|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2006-11-17 10:15:10
Markus Werle <numerical.simulation_at_[hidden]> writes:
> Sebastian Redl <sebastian.redl <at> getdesigned.at> writes:
>
>>
>> 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,
>
> Ouch! The tutorial is definitely too short!
Patches welcomed.
> So I can use std::random_access_iterator_tag instead?
Not with your iterator definition; you'd be lying to the standard
library. A standard random access iterator has a reference type of
value_type&. Without that, your iterator is just an input iterator
from the STL point-of-view.
> I simply want an iterator that works with current STL as random
> iterator.
Then use a real reference type. Sorry, the STL iterator design took a
limited worldview and you have to conform to it if you want to get all
the expected optimizations.
> Class Demo uses a std::size_t as index type.
> How do I build my iterator with iterator_facade?
Use a signed distance type; that's a requirement of STL (and
new-style) iterators.
-- Dave Abrahams Boost Consulting www.boost-consulting.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