Can I reverse traversal using iterator like below (is it correct?):
for (auto it=foo.end()-1; it != foo.begin()-1; it--)
DoSomethingHere(it);
I have been doing this OK on vectors. However, from Dr. Dobbs article, it seems that the iterator implementation may vary. I am afraid that it could fail on iterators of other classes.
If the above implementation is correct, is it preferred or is the following reverse-iterator is preferred:
for (auto it = foo.rbegin(); it != foo.rend(); it++)
DoSomethingHere(it);
Related articles/Q&A for this question of preference can be found in: