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

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top