title: What's the cleanest way to walk and unwalk a std::vector using iterators?
body: <p>I have a situation where I'm marching through a vector, doing things:</p>
  <pre><code>std::vector&lt;T&gt;::iterator iter = my_list.begin();
  
  for ( ; iter != my_list.end(); ++iter )
  {
    if ( iter-&gt;doStuff() )   // returns true if successful, false o/w
    {
      // Keep going...
    }
    else
    {
      for ( ; iter != m_list.begin(); --iter )  // ...This won't work...
      {
        iter-&gt;undoStuff();
      }
    }
  }
  </code></pre>
  <p>Under normal conditions - assuming everything goes well - I march all the way to <code>my_list.end()</code> and end the loop successfully.</p>
  <p>However, if something goes wrong while I'm doing stuff, I want to be able to undo everything - basically retrace my steps back to the very beginning of the vector, undoing everything one at a time in reverse order.</p>
  <p>My problem is that when I get to <code>my_list.begin()</code> - as shown in the nested for loop - I'm really not done yet because I still need to call <code>undoStuff()</code> on my first element in the list.   Now, I could just make the final call outside of the loop, but this seems a little unclean.</p>
  <p>The way I see it, I'm only done when I get to <code>my_list.rend()</code>.  However, I can't compare a <code>std::vector::iterator</code> to a <code>std::vector::reverse_iterator</code>.</p>
  <p>Given what I'm trying to do, what's the best choice of iterator-type / loop combination?</p>