Boost logo

Boost Users :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-11-16 04:34:58


Markus Werle wrote:
> Hi!
>
> This was detected by profiling. I expected the code below
> to have a rather cheap std::distance call because my iterator
> was tagged as random_access.
>
std::distance doesn't understand the new iterator categories, only the
old, which merge the traversal and access traits into one.
This means that even if your iterator has random_access_traversal,
std::distance will not see it as a random_access iterator unless it also
has lvalue semantics (forgot what that trait is called). Since your
reference type is ValueT, not ValueT&, this is not the case.

You could write a new-style distance() function that only cares about
the traversal category. Or perhaps someone has already written it.

(Dave: that might be a worthy addition to the iterator library:
distance() and advance() for the new-style iterators. Like boost::TR1,
the functions could just forward to implementations that are already
updated.)

Sebastian Redl


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