title: In an STL Map of structs, why does the "[ ]" operator cause the struct's dtor to be invoked 2 extra times?
body: <p>I've created a simple test case exhibiting a strange behavior I've noticed in a larger code base I'm working on. This test case is below. I'm relying on the STL Map's "[ ]" operator to create a pointer to a struct in a map of such structs. In the test case below, the line...</p>
  
  <pre><code>TestStruct *thisTestStruct = &amp;testStructMap["test"];
  </code></pre>
  
  <p>...gets me the pointer (and creates a new entry in the map). The weird thing I've noticed is that this line not only causes a new entry in the map to be created (because of the "[ ]" operator), but for some reason it causes the struct's destructor to be called two extra times. I'm obviously missing something - any help is much appreciated! 
  Thanks!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;map&gt;
  
  using namespace std;
  struct TestStruct;
  
  int main (int argc, char * const argv[]) {
  
      map&lt;string, TestStruct&gt; testStructMap;
  
      std::cout &lt;&lt; "Marker One\n";
  
      //why does this line cause "~TestStruct()" to be invoked twice?
      TestStruct *thisTestStruct = &amp;testStructMap["test"];
  
      std::cout &lt;&lt; "Marker Two\n";
  
      return 0;
  }
  
  struct TestStruct{
      TestStruct(){
          std::cout &lt;&lt; "TestStruct Constructor!\n";
      }
  
      ~TestStruct(){
          std::cout &lt;&lt; "TestStruct Destructor!\n";
      }
  };
  </code></pre>
  
  <p>the code above outputs the following...</p>
  
  <pre><code>/*
  Marker One
  TestStruct Constructor!             //makes sense
  TestStruct Destructor!               //&lt;---why?
  TestStruct Destructor!               //&lt;---god why?
  Marker Two
  TestStruct Destructor!               //makes sense
  */
  </code></pre>
  
  <p>...but I don't understand what causes the first two invocations of TestStruct's destructor? 
  (I think the last destructor invocation makes sense because testStructMap is going out of scope.)</p>