title: Puzzling post and pre-increment behavior of reverse_iterators and base
body: <p>Consider the toy program (post.cpp):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  int main() {
          vector&lt;int &gt; a;
          int i;
          for(i=0;i&lt;10;i++)
                  a.push_back(i);
          auto it=a.rbegin();
          while(it!=a.rend()) {
                  if ((*it % 2)==0) {
                                  cout &lt;&lt; "about to erase "&lt;&lt;*it&lt;&lt;endl;
                                  a.erase((it++).base());
                  }
                  else {
                          ++it;
                  }
          }
          for(auto it2=a.begin(); it2 != a.end(); it2++) {
                  cout &lt;&lt; *it2 &lt;&lt; endl;
          }
          return 0;
  }
  </code></pre>
  
  <p>What I am trying to do is to test for evenness, and then delete the current number, since <code>(it++)</code> should return the current iterator and then advance the iterator. This is what I get as the output:</p>
  
  <pre><code>$ ./post 
  about to erase 8
  about to erase 6
  about to erase 4
  about to erase 2
  about to erase 0
  0
  2
  4
  6
  8
  </code></pre>
  
  <p>If, however, I change the line <code>a.erase((it++).base());</code> to <code>a.erase((++it).base());</code>, I get the correct behavior. Why is this?</p>
  
  <p>Useful clarification: I am using <code>base()</code> since reverse_iterators cannot be used in <code>erase()</code>. There is an application where I want to go reverse on the vector to erase stuff.</p>