title: Is there any way to check if an iterator is valid?
body: <p>For two threads manipulating a container map for example, what the correct way to test whether an iterator still valid (for performance reason) ?<br/>
  Or would be of only indirect way that this can be done.
  The sample code for this :<br></p>
  
  <pre><code>#define _SECURE_SCL 1
  //http://msdn2.microsoft.com/en-us/library/aa985973.aspx
  #define _SECURE_SCL_THROWS 1
  
  #include "map"
  #include "string"
  #include "exception"
  #include "iostream"
  
  using namespace std;
  
  void main(void)
  {
      map&lt;string, string&gt; map_test;
      map&lt;string, string&gt;::iterator iter_map_test;
  
      map_test [ "AAAAA" ] = "11111";
      map_test [ "BBBBB" ] = "22222";
      map_test [ "CCCCC" ] = "33333";
  
      iter_map_test = map_test.find ("BBBBB");
  
      map_test.erase ("BBBBB");
  
      try
      {
          string value = (*iter_map_test).second;
      }
      catch ( exception &amp; e )
      {
              cout &lt;&lt; e.what() &lt;&lt; endl;
      }
      catch ( ... )
      {
              cout &lt;&lt; "generic exception." &lt;&lt; endl;
      }
  }
  </code></pre>