iterator/zip: use the iterable concept for zip construction

This commit is contained in:
Danny Robson 2020-02-24 14:39:58 +11:00
parent 3791c8b8ee
commit ebd88b25e7

View File

@ -9,6 +9,7 @@
#pragma once
#include "iota.hpp"
#include "../concepts.hpp"
#include "../tuple/value.hpp"
#include "../variadic.hpp"
#include "../functor.hpp"
@ -81,6 +82,21 @@ namespace cruft::iterator {
}
decltype (auto)
operator* (void) const
{
// We deliberately construct a tuple manually here to reduce
// the risk of dangling references. `forward_as_tuple` and
// `make_tuple` have resulted in references to locals in the
// past.
return std::tuple<
decltype(*std::get<Indices> (m_iterators))...
> (
*std::get<Indices> (m_iterators)...
);
}
bool
operator== (const zipped_iterator &rhs) const
{
@ -178,6 +194,7 @@ namespace cruft::iterator {
///
/// eg, cruft::zip ({1,2,3}, {4,5,6}) ~= {{1,4},{2,5},{3,6}}
template <typename ...ContainerT>
requires (cruft::concepts::iterable<ContainerT> && ...)
decltype(auto)
zip (ContainerT&&... data)
{
@ -199,6 +216,7 @@ namespace cruft::iterator {
///
/// eg, cruft::izip ("abc") ~= {{0,'a'},{1,'b'},{2,'c'}}
template <typename ...ContainerT>
requires (cruft::concepts::iterable<ContainerT> && ...)
decltype(auto)
izip (ContainerT&&... data)
{