title: Template class map insert VS Non template map insert
body: <p>I am trying to understand why the std::map.insert() function is behaving differently.</p>
  
  <p>Example of template class std::map insert function:</p>
  
  <pre><code>        #include &lt;iostream&gt;
          #include &lt;map&gt;
          #include &lt;limits&gt;
  
          template&lt;class K, class V&gt;
          class container
          {
          private:
          std::map&lt;K,V&gt; m_map;
          public:
          container(const V Val)
          {
          m_map.insert(m_map.begin(),std::make_pair(std::numeric_limits&lt;K&gt;::lowest(),Val));
          }
          const V operator[](const K key)
          {
          return (--m_map.lower_bound(key))-&gt;second;
          }
          };
  
          int main()
          {
          container&lt;unsigned int, char&gt; c('A');
          std::cout&lt;&lt;std::numeric_limits&lt;unsigned int&gt;::lowest()&lt;&lt;":"&lt;&lt;c[std::numeric_limits&lt;unsigned int&gt;::lowest()]&lt;&lt;"\n";
          std::cout&lt;&lt;"1:"&lt;&lt;c[1]&lt;&lt;"\n";
          std::cout&lt;&lt;"2:"&lt;&lt;c[2]&lt;&lt;"\n";
          std::cout&lt;&lt;"3:"&lt;&lt;c[3]&lt;&lt;"\n";
          std::cout&lt;&lt;"4:"&lt;&lt;c[4]&lt;&lt;"\n";
          std::cout&lt;&lt;"5:"&lt;&lt;c[5]&lt;&lt;"\n";
          std::cout&lt;&lt;std::numeric_limits&lt;unsigned int&gt;::max()&lt;&lt;":"&lt;&lt;c[std::numeric_limits&lt;unsigned int&gt;::max()]&lt;&lt;"\n";
          return 0;
          }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>0:A
  1:A
  2:A
  3:A
  4:A
  5:A
  4294967295:A
  </code></pre>
  
  <p>Example of Non-template std::map insert function:</p>
  
  <pre><code>            #include &lt;iostream&gt;
              #include &lt;map&gt;
              #include &lt;limits&gt;
              int main()
              {
              std::map&lt;unsigned int, char&gt; m_map;
              m_map.insert(m_map.begin(),std::make_pair(std::numeric_limits&lt;unsigned int&gt;::min(),'A'));
              std::cout&lt;&lt;std::numeric_limits&lt;unsigned int&gt;::min()&lt;&lt;":"&lt;&lt;m_map[std::numeric_limits&lt;unsigned int&gt;::min()]&lt;&lt;"\n";
              std::cout&lt;&lt;"1:"&lt;&lt;m_map[1]&lt;&lt;"\n";
              std::cout&lt;&lt;"2:"&lt;&lt;m_map[2]&lt;&lt;"\n";
              std::cout&lt;&lt;"3:"&lt;&lt;m_map[3]&lt;&lt;"\n";
              std::cout&lt;&lt;"4:"&lt;&lt;m_map[4]&lt;&lt;"\n";
              std::cout&lt;&lt;"5:"&lt;&lt;m_map[5]&lt;&lt;"\n";
              std::cout&lt;&lt;std::numeric_limits&lt;unsigned int&gt;::max()&lt;&lt;":"&lt;&lt;m_map[std::numeric_limits&lt;unsigned int&gt;::max()]&lt;&lt;"\n";
              return 0;
              }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>0:A
  1:
  2:
  3:
  4:
  5:
  4294967295:
  </code></pre>
  
  <p>The output of the first example shows that all index from 0 -> 4294967295 has been assigned the character 'A'. In the second example, only the index zero(0) has been assigned the character 'A'.</p>
  
  <p>Now my question is why the first example insert function assigned the same value to all keys in range even though I did only one insert and the second example insert function inserted exactly at one location I hinted.</p>