Boost logo

Boost Users :

Subject: Re: [Boost-users] [iterators ]bug?
From: David Abrahams (dave_at_[hidden])
Date: 2009-03-04 15:01:25


on Wed Mar 04 2009, bismuth-AT-list.ru wrote:

> There is probably a bug in boost::iterators library.
> boost::transform_iteartor degrade stl iterator_category.
> There is a code below, illustrating a problem(using VS2008 c++
> compiler):

I just answered the trac ticket. It's not a bug. ForwardIterator (and
thus Bidirectional and RandomAccessIterator) require their operator* to
return a true reference to the value_type.

> ---------------------
> #include <stdio.h>
> #include <tchar.h>
>
> #include <vector>
> #include <boost/iterator/transform_iterator.hpp>
> #include <boost/static_assert.hpp>
>
> struct Tr1:
> std::unary_function<unsigned, unsigned>
> {
> unsigned operator()(unsigned a)const
> {
> return a;
> }
> };
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> typedef std::vector<unsigned>::iterator some_ra_iterator_t;
> typedef boost::transform_iterator<Tr1, some_ra_iterator_t> tr_iter_t;
>
> BOOST_STATIC_ASSERT
> (( boost::is_convertible
> < std::iterator_traits<some_ra_iterator_t>::iterator_category,
> std::random_access_iterator_tag
> >::value
> ));
>
> BOOST_STATIC_ASSERT
> (( ! boost::is_convertible
> < std::iterator_traits<tr_iter_t>::iterator_category,
> std::random_access_iterator_tag
> >::value
> ));
>
> BOOST_STATIC_ASSERT
> (( boost::is_same
> < std::iterator_traits<tr_iter_t>::iterator_category,
> boost::detail::iterator_category_with_traversal
> < std::input_iterator_tag, //?!
> boost::random_access_traversal_tag
> >
> >::value
> ));
>
> return 0;
> }
> ---------------------
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net