John Levon wrote: > On Sun, Mar 23, 2003 at 09:28:21PM +0100, Alfredo Braunstein wrote: > >> It's the same thing as: >> >> vector<int> a(10); >> >> if(&a[11] == &*a.end()) >> cout << "yes" << endl; >> >> This does _not_ crash and prints yes (and in fact is perfectly valid and >> can even be useful).
I meant a[10], but you have surely understood anyway. > This does not look valid C++ to me. Maybe I am wrong, but despite "one > past the end" rules I don't think .end() is guaranteed to match here. Well it's maybe not guaranteed (as I've said, I have tried to but failed to find a proof on the stl documentation). But it will surely work on every vector or string implementation (on which iterators are wrappers to pointers). That was the argument on the post, the one with which Lars disagreed! The point is that end() is an iterator pointing one past the end, an invalid position. And rend is an iterator pointing one before start. They both point to invalid positions. What's the problem with that? What so terrible in returning an invalid paragraph position -1? (you even return the invalid par position 0) And if you are so against it, then we can make lastPos to return n (instead of max(0,n-1) on a paragraph with n chars (maybe changing its name). And we can eliminate all the special casing. Regards, Alfredo