|
Boost : |
Subject: Re: [boost] Boost range - Add variadic join/zip
From: Jonathan Wakely (jwakely.boost_at_[hidden])
Date: 2013-05-10 06:28:46
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 <class... T>
> 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.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk