Operator[] in std::map implementation
<p>I am trying to implement a container like <a href="http://en.cppreference.com/w/cpp/container/map" rel="nofollow">std::map</a> in C++. I have a small query while overloading operator []. I see that this operator works in two ways:</p>

<ol>
<li><code>mymap[2]</code> - For this case it looks for key 2 in map and return the value against this key.</li>
<li><code>mymap[2]=3</code> - For this case it looks for key 2 in map and if key is not found than 3 is inserted in map.</li>
</ol>

<p>I see that declaration for this operator looks like: <code>Mapped_T &amp;operator[](const Key_T &amp;);</code> but what I am not getting is that in case the key is not found I will have to insert a new element in Map but in declaration of operator[] function I don't see value being passed anywhere. So how would overloaded operator know what is value against key to be inserted?</p>