|
|
 |
 |
 |
 |
doubt on erasing the first element of a vector with reverse_iterator
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
On 30 Maj, 09:12, wolverine <kiran.ha@gmail.com> wrote: > 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(). -- Erik Wikstrm
|
 |
 |
 |
 |
|