Boost logo

Boost :

Subject: Re: [boost] [iterators] Proof-of-concept for a sentinel iterator adapter
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-05-13 11:34:22


Peter Dimov skrev:
>> Attached is proof-of-concept code for a sentinel iterator adapter. It
>> turns a pointer to sentinel terminated sequence, such as a C-style
>> string, into a forward iterator with a conforming end iterator.
>>
>> This is more efficient than doing a separate sequence traversal just to
>> find the end.
>
> No, it is not. :-)

In Boost.StringAlgo the end iterator is usually computed by
a call to strlen().

I suspect for algorithms that do not need

a. random access iterators

b. to discover the whole range before terminating

then a sentinel range could be more efficient.

Of course, a random access range might be subject to other optimizations
that are lost when the iterator cetagory is made more general.

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk