title: how to get stl map to construct/destruct inserted object only once
body: <p>I have found a very prejudicial fact about stl maps. For some reason I cant get objects being inserted in the map to get constructed/destructed only once.</p>
  
  <p>Example:</p>
  
  <pre><code>struct MyObject{
      MyObject(){
          cout &lt;&lt; "constructor" &lt;&lt; endl;
      }
      ~MyObject(){
          cout &lt;&lt; "destructor" &lt;&lt; endl;
      }
  };
  int main() {
      std::map&lt;int, MyObject&gt; myObjectsMap;
      myObjectsMap[0] = MyObject();
      return 0;
  }
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>constructor
  destructor
  destructor
  constructor
  destructor
  </code></pre>
  
  <p>If I do:</p>
  
  <pre><code>typedef std::pair&lt;int, MyObject&gt; MyObjectPair;
  myObjectsMap.insert( MyObjectPair(0,MyObject()));
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>constructor
  destructor
  destructor
  destructor
  </code></pre>
  
  <p>I'm inserting Objects responsible for their own memory allocation, so when destructed they'll clean themselves up, being destructed several times is causing me some trouble.</p>