Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-06-03 14:14:17


christopher diggins <cdiggins_at_[hidden]> writes:

>> That would be useful, however your sample code has a problem with the end
>> iterator. To iterate over every second element of a container that has an
>> even length, the one-past-the-end stride-2 iterator is actually TWO past
>> the end of the original container. Unless you have a special container
>> where incrementing beyond the one-past-the-end is allowed, you need
>> another
>> solution (indexing?).
>
> Would indexing not lead to a similar problem? I would have thought the only
> way out is to pass a size parameter to the iterator. Do any iterators exist
> which do not allow incrementing past one past the end?

When the step size is 3 you go 2 past the end.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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