title: Find and erase element from STL container while iterating
body: <p>While iterating over a <code>multimap</code> I want to delete elements, but not only the element the iterator is pointing to.</p>
  
  <pre><code>for (vector&lt;int&gt; myVec : myVectors)
  {
      auto range = myMultiMap.equal_range(myVector);
      for (auto it = range.first; it != range.second; ++it)
      {
          // secondPair is another element of this multimap
          auto secondPair = getSecondPair(it, myMultiMap);
          if (condition)
          {
              it = myMultiMap.erase(it);
              auto finder = myMultiMap.find(secondPair);
              // how can I delete secondPair?
          }
      }
  }
  </code></pre>
  
  <p>Maybe it's the xy-problem here, so let me explain what I need  this for: What I'm trying to do is to shorten a set of <code>vector&lt;int&gt;</code>. There are associated elements of type <code>MyPair</code> for each element. Those associated elements are stored in an unordered multimap.</p>
  
  <pre><code>typedef unordered_multimap &lt; vector&lt;int&gt;, MyPair, SomeHash &gt; MyMultiMap;
  </code></pre>
  
  <p>An element of the <code>set&lt;vector &lt;int&gt; &gt;</code> can be removed if all associated pairs in the multimap have been processed successfully. It won't be successful for most of them, so most of them are expected to remain in the set. My idea was to delete the elements from the multimap and if there are no associated elements in the multimap anymore, it means the element can be removed from the set.
  Here again I have the problem to remove elements from a set while iterating. Again, not only the one the iterator is pointing to.</p>