Boost logo

Boost Users :

Subject: Re: [Boost-users] [iterator] [iterator_facade] Why is advance not defined for bidirectional iterators?
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2011-08-22 11:10:37


On Mon, Aug 22, 2011 at 4:53 PM, Sebastian Redl <
sebastian.redl_at_[hidden]> wrote:

> On 22.08.2011 13:09, Ovanes Markarian wrote:
>
[..]

> std::advance will switch implementations based on the standard iterator
> tags, i.e. std::input_iterator_tag, std::forward_iterator_tag,
> std::bidirectional_iterator_tag and std::random_access_iterator_tag.
> (Actually, forward isn't treated any different than input in std::advance.)
> These categories conflate traversal and access. The problem is that to be a
> forward iterator, the associated type 'reference' must be a true reference.
> So whenever that isn't the case, the iterator is an input_iterator, no
> matter how you can navigate it.
>
Ok, thanks. I was aware of iterator categories, but did not know that
advance really is going to make a decision dependent on reference type and
not the iterator category. If that is true what you have written, than
vector<bool> must be either a forward_iterator sequence or advance is also
specialized for vector<boost>::iterator and ...const_iterator respectively.

> Boost.Iterator separates the concepts, and so it has
> boost::one_pass_traversal_tag, boost::forward_traversal_tag,
> boost::bidirectional_traversal_tag, and boost::random_access_traversal_tag.
> However, you would need an advance algorithm that is aware of these tags. No
> std::advance I know is, so basically, you can't use it. (I'm not sure if
> you're allowed to specialize std::advance.)
>
AFAIK users are allowed to specialize the std templates but are disallowed
to overload them.

I was hoping to solve it more elegantly, but thanks for your help anyway.

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