
On 9 May 2013 16:01, Gonzalo BG wrote:
A variadic zip is more complicated. If we want write access we cannot use boost zip_iterator. Still one can use Anthony Williams' TupleIterator:
template
auto zip(T&&... c) -> boost::iterator_range< decltype(iterators::makeTupleIterator(std::begin(std::forward<T>(c))...))> { return boost::make_iterator_range (iterators::makeTupleIterator(std::begin(std::forward<T>(c))...), iterators::makeTupleIterator(std::end(std::forward<T>(c))...)); }
For read-only access one could use boost::zip_iterator, but I think write-access is _really_ important (e.g. sort wouldn't work).
It looks as though it's undefined behaviour to zip ranges of different lengths, because you'll walk off the end of the shorter ranges. My variadic zip stops at the end of the shortest range, which seems to be consistent with zip functions in most other languages I've looked at. Your adaptors also get dangling references if used with rvalue ranges, although this is a problem with the existing boost range adaptors too.