Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2007-12-10 10:21:07


on Mon Dec 10 2007, shunsuke <pstade.mb-AT-gmail.com> wrote:

> Hi,
>
>
> Assume a base iterator is an InputIterator with RandomAccessTraversalTag.
> boost::make_zip_iterator often returns such iterators.
>
> boost::transform_iterator sometimes resurrects lvalue-ness of its base iterator.
> For example,
>
> char & to_lvalue(boost::tuple<char &, int &> const &t)
> {
> return boost::get<0>(t);
> }
>
> can return a lvalue from zip_iterator dereference.
>
> Therefore, if boost::transform_iterator extracts "pure" traversal tag from its base iterator,
> it can be not an InputIterator but a RandomAccessIterator.
> The patch will be something like this:
>
> template <class UnaryFunc, class Iterator, class Reference, class Value>
> struct transform_iterator_base
> {
> // ...
>
> typedef iterator_adaptor<
> transform_iterator<UnaryFunc, Iterator, Reference, Value>
> , Iterator
> , cv_value_type
> - , use_default // Leave the traversal category alone
> + , typename pure_traversal_tag<typename iterator_traversal<Iterator>::type>::type
> , reference
> > type;
> };
> }
>
>
> Is there any pitfalls?

Looks like a good idea. Did you check to see if it breaks any tests?

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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