title: Iterator invalidation in boost::unordered_map
body: <p>I am using <code>boost::unordered_map</code> as follows </p>
  
  <pre><code>typedef boost::shared_ptr&lt;WriterExeciter&gt; PtrWriter;
  typedef std::list&lt;PtrWriter&gt; PtrList; 
  boost::unordered_map&lt;std::pair&lt;unsigned int, unsigned long long&gt;, PtrList&gt;  Map
  Map instrMap;
  </code></pre>
  
  <p>Now I am making some changes to the list of type <code>PtrList</code> in a loop</p>
  
  <pre><code>for(auto it = instrMap.begin(); it != instrMap.end(); ++it)
  {
       auto key = it-&gt;first();
       auto list&amp; = it-&gt;second();    
       //Make some change to an element in list 
  
        if(list.empty())
        {
              instMap.erase(key); 
        }
  
  
  
  }
  </code></pre>
  
  <ol>
  <li><p>Does making changes to the list invalidate the iterator to instrMap? </p></li>
  <li><p>Erasing the element will invalidate the iterator pointing to the erased element. How do I modify my code so that the this does not cause any problem? Does using <code>it++</code> instead of <code>++it</code> help?</p></li>
  </ol>
  
  <p>Thanks</p>