iterator: use iota for izip
Using `indices` introduced problematic dangling references. We should almost always want integral indices anyway, so we drop the fancy iterator. A user can always call zip with an indices object anyway.
This commit is contained in:
parent
4d91db760c
commit
1f1f6ddbaf
16
iterator.hpp
16
iterator.hpp
@ -515,7 +515,7 @@ namespace cruft {
|
|||||||
///
|
///
|
||||||
/// eg, cruft::zip ({1,2,3}, {4,5,6}) ~= {{1,4},{2,5},{3,6}}
|
/// eg, cruft::zip ({1,2,3}, {4,5,6}) ~= {{1,4},{2,5},{3,6}}
|
||||||
template <typename ...ContainerT>
|
template <typename ...ContainerT>
|
||||||
auto
|
decltype(auto)
|
||||||
zip (ContainerT&&... data)
|
zip (ContainerT&&... data)
|
||||||
{
|
{
|
||||||
CHECK (((std::size (data) == std::size (variadic::get<0> (data...))) && ...));
|
CHECK (((std::size (data) == std::size (variadic::get<0> (data...))) && ...));
|
||||||
@ -531,15 +531,21 @@ namespace cruft {
|
|||||||
/// object where the first of the iterator's value_types is the index of
|
/// object where the first of the iterator's value_types is the index of
|
||||||
/// that iterator. ie, It combines container offsets with value_types.
|
/// that iterator. ie, It combines container offsets with value_types.
|
||||||
///
|
///
|
||||||
|
/// The supplied containers _must_ not change size while the izip object
|
||||||
|
/// is live. The size of the containers may be cached for efficiency.
|
||||||
|
///
|
||||||
/// eg, cruft::izip ("abc") ~= {{0,'a'},{1,'b'},{2,'c'}}
|
/// eg, cruft::izip ("abc") ~= {{0,'a'},{1,'b'},{2,'c'}}
|
||||||
template <typename ...ContainerT>
|
template <typename ...ContainerT>
|
||||||
auto
|
decltype(auto)
|
||||||
izip (ContainerT&&... data)
|
izip (ContainerT&&... data)
|
||||||
{
|
{
|
||||||
indices idx (::cruft::variadic::get<0> (data...));
|
// Assume that all containers are the same size and create a range
|
||||||
|
// that will supply integral indices over the first container.
|
||||||
|
//
|
||||||
|
// The call to `zip` will peform more rigorous tests on the sizes
|
||||||
|
// of the container collection.
|
||||||
return zip (
|
return zip (
|
||||||
std::move (idx),
|
iota (::cruft::variadic::get<0> (data...).size ()),
|
||||||
std::forward<ContainerT> (data)...
|
std::forward<ContainerT> (data)...
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user