Boost logo

Boost :

From: shunsuke (pstade.mb_at_[hidden])
Date: 2007-12-10 00:34:11


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?

Regards,

-- 
Shunsuke Sogame

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