title: Using The [] Operator Efficiently With C++ unordered_map
body: <p>Firstly could someone clarify whether in C++ the use of the [] operator in conjunction with an unordered_map for lookups wraps a call to the find() method, or is using the [] operator quicker than find()?</p>
  
  <p>Secondly, in the following piece of code I suspect in cases where the key is not already in the unordered_map I am performing a second look up by way of the line <code>map[key] = value</code> in order to replace the default value created there by using the [] operator when a key is not present. </p>
  
  <p>Is that true, and if so is there a way (perhaps by use of pointers or something) that I might only perform one look up in any case (perhaps by storing the address of where to place a value/read a value from) and still achieve the same functionality? Obviously this would be a useful efficiency improvement if so.</p>
  
  <p>Here is the modified code excerpt:</p>
  
  <pre><code>    int stored_val = map[key]; // first look up. Does this wrap -&gt;find()??
  
      // return the corresponding value if we find the key in the map - ie != 0
      if (stored_val) return stored_val;
  
      // if not in map
      map[key] = value; 
         /* second (unnecessary?) look up here to find position for newly 
            added key entry */
  
     return value;
  </code></pre>