title: speeding up std::map and boost:unordered_map [] operation
body: <p>I have a MAP which is optionally of type std::map and optionally of type unordered_map ( according to typdef MAP)  , and a function which adds a value to the given keyed value:</p>
  
  <pre><code>  func1(MAP&lt;string,  double&gt;  &amp;map, string  &amp;key, double &amp;val2add){
      try
  {
        map.at(key)  += val2add;
  }catch(out_of_range&amp; oor){
            map[key] = val2add; // in case map[key] didn't exist before. 
      }
    }
  </code></pre>
  
  <p>The problem is that this means double ( and possibly even more ) work than simply </p>
  
  <pre><code>  func2(MAP&lt;string,  double&gt;  &amp;map, string  &amp;key, double &amp;val2add){
         map[key] += val2add; // if map[key] doesn't exist - problem
    }
  </code></pre>
  
  <p>But the above would not work, since as i understand the [] operator initializes a new object in map with the defined key, and with the default double value. If i knew that the default double value is 0, then func2 would still achieve what i want it to - but i can't rely on that. </p>
  
  <p>So is there any way to use [] in a better way over func1?</p>