title: how are map iterators invalidated when erasing elements?
body: <p>when and how are iterators invalidated in a map when using the erase method ?</p>
  
  <p>for example :</p>
  
  <pre><code>std :: map &lt; int , int &gt; aMap ;
  
  aMap [ 33 ] = 1 ;
  aMap [ 42 ] = 10000 ;
  aMap [ 69 ] = 100 ;
  aMap [ 666 ] = -1 ;
  
  std :: map &lt; int , int &gt; :: iterator itEnd = aMap.lower_bound ( 50 ) ;
  
  for ( std :: map &lt; int , int &gt; :: iterator it = aMap.begin ( ) ;
        it != itEnd ;
        // no-op
      )
  {
     aMap.erase ( it ++ ) ;
  }
  </code></pre>
  
  <p>the erased iterator will surely become invalid (it's incremented while still valid)
  but what about the others?</p>
  
  <p>if I'm not wrong the standard says that a map has to be a balanced binary tree or a structure with equivalent key-search complexity</p>
  
  <p>in case the map is implemented with a tree, can I assume that not erased iterators remain valid ?</p>
  
  <p>what about other possible ways to implement a map ? </p>