[iterator] lvalue-ness resurrection in transform_iterator?

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

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

David Abrahams wrote:
Looks like a good idea.
I wanted to see if this strategy is theoretically right. I'm relieved to hear that. :-)
Did you check to see if it breaks any tests?
FWIW, gcc-3.4, gcc-4.1 (mingw), msvc-7.1, and msvc-8.0 pass. Regards, -- Shunsuke Sogame

on Mon Dec 10 2007, shunsuke <pstade.mb-AT-gmail.com> wrote:
David Abrahams wrote:
Looks like a good idea.
I wanted to see if this strategy is theoretically right. I'm relieved to hear that. :-)
Did you check to see if it breaks any tests?
FWIW, gcc-3.4, gcc-4.1 (mingw), msvc-7.1, and msvc-8.0 pass.
Great! Could you submit your patch attached to a ticket at http://svn.boost.org? Thanks, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

David Abrahams wrote:
Great! Could you submit your patch attached to a ticket at http://svn.boost.org?
Thanks,
Uploaded. http://svn.boost.org/trac/boost/ticket/1519 Regards, -- Shunsuke Sogame

on Mon Dec 10 2007, shunsuke <pstade.mb-AT-gmail.com> wrote:
David Abrahams wrote:
Great! Could you submit your patch attached to a ticket at http://svn.boost.org?
Thanks,
Thank you -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (2)
-
David Abrahams
-
shunsuke