title: How do I erase a reverse_iterator from an stl data structure?
body: <p>For some reason the following code fails. You can't simply erase a reverse_iterator by using its base() method. </p>
  
  <pre><code>#include &lt;set&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      std::set&lt;int&gt; setOfInts;
      setOfInts.insert(1);
      setOfInts.insert(2);
      setOfInts.insert(3);
  
      std::set&lt;int&gt;::reverse_iterator rev_iter = setOfInts.rbegin();
      std::set&lt;int&gt;::reverse_iterator nextRevIter = setOfInts.rbegin();
      ++nextIter;
  
      while ( rev_iter != setOfInts.rend())
      {
          // Find 3 and try to erase
          if (*rev_iter == 3)
          {
              // SEGFAULT HERE
              setOfInts.erase( rev_iter.base());
          }
          rev_iter = nextRevIter;
          ++nextRevIter;
      }
  
  }
  </code></pre>
  
  <p>How does one go about correctly doing the above? Given a reverse_iterator that corresponds to something you want to erase, how do you erase it?</p>
  
  <p><strong>Note, erase won't take reverse_iterators unfortunately. It wants the real thing.</strong></p>