Boost logo

Boost :

Subject: Re: [boost] Boost range - Add variadic join/zip
From: Neil Groves (neil_at_[hidden])
Date: 2013-05-10 04:37:53


>
> However, boost's zip_iterators are not writable. I don't really think it
> would be possible to make them writable, but that would allow code like
> this:

<snip>
</snip>

>
> template<class C, class D, class... Args>
> auto join(C&& c, D&& d, Args&&... args)
> ->
>
> decltype(boost::join(boost::join(boost::make_iterator_range(std::forward<C>(c)),
>
> boost::make_iterator_range(std::forward<D>(d))),
> join(std::forward<Args>(args)...))) {
> return
> boost::join(boost::join(boost::make_iterator_range(std::forward<C>(c)),
>
> boost::make_iterator_range(std::forward<D>(d))),
> join(std::forward<Args>(args)...));
> }
>
> 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).
>
> Would it be possible to add similar functionality to boost range?
>
>
Yes and I shall do so when I find time. If you find time to create a patch
it would be even quicker of course, but I understand if this is not
possible. It seems we are all running with less and less time to work on
these extra-curricula projects!

> This code wouldn't work without the help of everyone who participated in
> the following SO discussions:
> -
>
> http://stackoverflow.com/questions/14366576/boostrangejoin-for-multiple-ranges
> -
>
> http://stackoverflow.com/questions/13840998/sorting-zipped-locked-containers-in-c-using-boost-or-the-stl
> and without Anthony Williams's tupleIterator. See also
> http://www.justsoftwaresolutions.co.uk/articles/pair_iterators.pdf
>
>
I'll have to see if I can persuade Anthony to be charitable enough to allow
us to include his tuple iterator. Ideally this would be made a public
feature of Boost.Iterator I think.

> Bests,
> Gonzalo BG
>

Thank you for your feedback. It's great to have positive suggestions that
are actionable like this.

Regards,
Neil Groves


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk