title: reverse traversal: iterator or reverse iterator: correctness and preference?
body: <p>Can I reverse traversal using iterator like below (is it correct?):</p>
  
  <pre><code>for (auto it=foo.end()-1; it != foo.begin()-1; it--)
      DoSomethingHere(it);
  </code></pre>
  
  <p>I have been doing this OK on vectors.  However, from <a href="http://www.drdobbs.com/cpp/three-guidelines-for-effective-iterator/184401406" rel="nofollow noreferrer">Dr. Dobbs article</a>, it seems that the iterator implementation may vary.  I am afraid that it could fail on iterators of other classes.</p>
  
  <p>If the above implementation is correct, is it preferred or is the following reverse-iterator is preferred:</p>
  
  <pre><code>for (auto it = foo.rbegin(); it != foo.rend(); it++)
          DoSomethingHere(it);
  </code></pre>
  
  <p>Related articles/Q&amp;A for this question of preference can be found in:</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/8621426/how-do-you-erase-and-continue-using-a-stdreverse-iterator">How do you erase <em>AND CONTINUE</em> using a std::reverse_iterator?</a></li>
  <li><a href="http://www.drdobbs.com/cpp/three-guidelines-for-effective-iterator/184401406" rel="nofollow noreferrer">Dr. Dobbs article</a></li>
  <li><a href="https://stackoverflow.com/questions/3207679/what-are-the-shortcomings-of-stdreverse-iterator">"What are the shortcomings of std::reverse_iterator?"</a></li>
  </ol>