Yes, it is undefined.
If you want to iterate over elements in reverse, just use rbegin
and rend
. They're reverse iterators, designed explicitly for this purpose. If you need to get a standard iterator from the reverse iterator, you can use the base
member function on the iterator.