I am using a reverse iterator on a std::vector
and according to the following link:
http://www.cplusplus.com/reference/stl/vector/rbegin/
myVector.rbegin()
is the last element of the vector. In my case, I am actually getting the past the end
iterator on rbegin()
and the fist element from rend()
. I would have expected rend()
to give me past the end
iterator and rbegin()
to give me the last element in the container. Did I understand the whole thing wrong?
The following is my code, nothing special. I put a break point just after the assignments, and the above is the result I am getting in the debugger (VecDebugCubes
is a type define for a std::vector<myStructure>
)
VecDebugCubes::reverse_iterator itr = pActiveDebugCubes.rbegin();
VecDebugCubes::reverse_iterator itrEnd = pActiveDebugCubes.rend();
while (itr != itrEnd)
{
(*itr)->printDebugValues();
++itr;
}
See http://www.cplusplus.com/reference/std/iterator/reverse_iterator/base/.
Dereferencing a reverse iterator will return a different value than the one that you see it pointing to in your debugger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With