Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-12-11 00:21:05

Bob Bell wrote:

> Now consider a typical reverse loop, where we decrement backwards through
> [b, e):
> while (b != e) {
> --e;
> // use *e;
> }
> No "begin sentinel" is required to make this loop behave as expected. When b is
> created, it will point to the first element of the filtered pseudo-sequence;
> this means that eventually, e will become equal to b, and the loop will
> terminate.

Not if the filter predicate returns false for *b.

> In fact, it seems that without a begin sentinel, uses of b and e are just as
> well-defined (or undefined) as equivalent ordinary iterators. For example, for
> an ordinary sequence [b, e), --b is well-defined only if there is something
> dereferencable there. For a filter iterator lacking a begin sentinel, the same
> thing is true.
> What do you think?

I think you overlooked something important.

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at