title: C++: std::map throws an out_of_range exception
body: <p>I have a code which looks as follows</p>
  
  <pre><code>template &lt;typename KeyType, typename ValueType&gt;
  KeyType IDSystem&lt;KeyType,ValueType&gt;::registerParameter(const ValueType&amp; value)
  {
      KeyType key = __IDCounter++;
      _Map[key] = value; //crashes here
      return key;
  }
  </code></pre>
  
  <p>where _Map is</p>
  
  <pre><code>std::map&lt;KeyType, ValueType&gt; _Map;
  </code></pre>
  
  <p>The program used to crash where indicated, and then I replaced that line with</p>
  
  <pre><code>_Map.at(key) = value; //out_of_range thrown here
  </code></pre>
  
  <p>And now the program throws an std::out_of_range exception at that same line...</p>
  
  <p>KeyType is int64_t from the standard library, and ValueType is a pointer to some class (like MyClass*).</p>
  
  <p>The surprising part is that I used std::map just like that before... and no problem occured.</p>
  
  <p>Am I using std::map incorrectly? Please advise.</p>