
David Abrahams wrote:
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.
Well, let me think about this again. Maybe you're right. The issue would be that you can't predict where the beginning of the filtered sequence lies... but that's not true. Imagine you have a std::list<int> l and you build filter iterators b and e over [l.begin(), l.end()). Since b and e form a valid range, I see no reason you can't iterate backwards from e to b. Okay, I buy it. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com