title: STL map insertion efficiency: [] vs. insert
body: <p>There are two ways of map insertion:</p>
  
  <pre><code>m[key] = val;
  </code></pre>
  
  <p>Or</p>
  
  <pre><code>m.insert(make_pair(key, val));
  </code></pre>
  
  <p>My question is, which operation is faster?
  People usually say the first one is slower, because the STL Standard at first 'insert' a default element if 'key' is not existing in map and then assign 'val' to the default element.</p>
  
  <p>But I don't see the second way is better because of 'make_pair'. make_pair actually is a convenient way to make 'pair' compared to <code>pair&lt;T1, T2&gt;(key, val)</code>. Anyway, both of them do two assignments, one is assigning 'key' to 'pair.first' and two is assigning 'val' to 'pair.second'. After pair is made, map inserts the element initialized by 'pair.second'.</p>
  
  <p>So the first way is 1. '<code>default construct of typeof(val)</code>' 2. assignment
  the second way is 1. assignment 2. '<code>copy construct of typeof(val)</code>'</p>