Re: vector: erase() and rbegin()

From: Buster (buster_at_zzy.co.uk)
Date: 10/24/04


Date: Sun, 24 Oct 2004 10:38:29 +0100

Alex Vinokur wrote:
> "John Harrison" <john_andronicus@hotmail.com> wrote in message news:2u11vbF253sffU1@uni-berlin.de...
>
> I have got
>
> assertion "assert ((*v.rbegin()) == (*v.rbegin().base()))" failed

That's undefined. Try "assert (v.rbegin ().base () == v.end ())". For a
reverse iterator pointing to an element of a collection, the base
iterator points to the following element (in the forward sequence). If j
is a reverse iterator that points to an element of a collection then
"j.base () - 1" gives a forward iterator pointing to the same element
(actually, you can only do arithmetic like this if the base iterator is
a random access iterator, but that's beside the point). Be careful
though, because if j is a reverse iterator that points one-past-the-end
(of the reverse sequence), i.e. if (j == v.rend ()), then j.base ()
points to the first element of the forward sequence, so "j.base () - 1"
is undefined.