doubt on erasing the first element of a vector with reverse_iterator

W

wolverine

Hi,
I have read that to erase an element from a vector with
reverse_iterator we have to use
-- vector.erase( (++reverseItr).base()) -- But assuming i have to
delete the first element of the vector ( zeroth index), would this
result in undefined behavior. My thinking is like, since the
reverseItr is already pointing to the first element of the vector,
when we increment it and try to get the base, will this work ?

Thanks in advance
Kiran
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

Hi,
I have read that to erase an element from a vector with
reverse_iterator we have to use
-- vector.erase( (++reverseItr).base()) -- But assuming i have to
delete the first element of the vector ( zeroth index), would this
result in undefined behavior. My thinking is like, since the
reverseItr is already pointing to the first element of the vector,
when we increment it and try to get the base, will this work ?

Yes, since v.rend().base() == v.begin().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top