title: destructor is called multiple number of times while inserting into map
body: <p>In below code , destructor is called multiple number of times :-</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;map&gt;
  using namespace std;
  
  
  class abc{
  
      public:
          abc()
          {
              cout&lt;&lt;"\nconstructor called\n";
          }
  
          ~abc()
          {
              cout&lt;&lt;"\ndestructor called\n";
          }
          void fun()
          {
              cout&lt;&lt;"\nfunction called\n";
          }
  };
  
  struct cmp_str
  {
     bool operator()(abc a,abc b)
     {
        return 1;
     }
  };
  
  
  
  
  int main()
  {
  
  map&lt;abc,int,cmp_str&gt; mymap;
  abc a;
  mymap[a]=5; // destructor is called twice
  //mymap.insert(pair&lt;abc,int&gt;(a,5)); // // destructor is called 3 times
  
  map&lt;abc,int,cmp_str&gt;::iterator it=mymap.begin();
  mymap.clear();
  while(1)
  {
  //infinite loop added to check number of times destrctor is called before objects goes out of scope
  }
  return 1;
  }
  </code></pre>
  
  <p>I am inserting values in the object using different ways.
  one by using insert() function  and other by simple [].
  when i insert using mymap[a]=5; then destructor is called twice whereas when i comment this line and use insert() function for insertion then destructor is called thrice.
  one destructor can be ignored because of mymap.clear() but why rest of the destructor are invoked.</p>
  
  <p>I have inserted infinite loop just above return , so that i can ignore the destructor called when object goes out of scope.
  please help me understanding this behaviours because multiple calls to the destructor is dangerous and could leads to core dump if not handled properly.</p>