|
Boost Users : |
Subject: [Boost-users] [iterator] [iterator_facade] Why is advance not defined for bidirectional iterators?
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2011-08-17 08:58:36
Hello *!
I defined a custom bidi-iterator and assumed it was going to support
std::advance(iterator, Difference n), where n can be negative for random
access and bidirectional iterators.
The definition of my iterator's facade base looks like:
struct my_iter
: boost::iterator_facade
< my_iter
, const byte
, boost::bidirectional_traversal_tag
, const byte
>
{
// some impl stuff follows...
};
My tests show that calling:
advance(instance_of_my_iter, N) works fine (increment implementation is
called)
advance(instance_of_my_iter, -N) does not work, because increment (instead
of decrement) is called as well
While reading through the docs for iterator facade at
http://www.boost.org/doc/libs/1_46_0/libs/iterator/doc/iterator_facade.html I
found the section iterator_facade Core Operations.
For the advance implementation is stated there that it is only gets called
for Random Access Iterators. C++ Standard clearly defines that N-Parameter
to std::advance can be negative to random access and bidi iterators.
Implementing void advance member in my_iter still results in the call to
increment member. Can someone give me any suggestions or is it a bug in the
iterator lib?
My compiler is gcc 4.3 under Debian Linux with Kernal 2.6.26. and Boost
1.42.
With Kind Regards,
Ovanes
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