title: When using std::map should I overload operator== for the key type?
body: <p>The std::map should not have duplicated keys so how does it knows I have a duplicated key when I have a custom type, do I need do overload overload operator==? Or it will be implicitly created?</p>
  
  <p>According to the documentation I only need the operator&lt; but this is not enough to maintain the keys' unicity.</p>
  
  <p>Consider this example:</p>
  
  <pre><code>class MyType{
  public:
    MyType(int newId){
      id = new int;
      *id = newId;
    };
    ~MyType{
      delete id;
    }
  private:
    int* id;
  };
  
  int main(){
    std::map&lt;MyType,int&gt; myMap;
  
    std::pair&lt;std::map&lt;MyType,int&gt;::iterator,bool&gt; ret;
    ret = myMap.insert ( std::pair&lt;MyType,int&gt;(myType(2),100) );
  
    if (!ret.second) {//now how can he knows that?
      std::cout &lt;&lt; "element already existed" &lt;&lt; endl;
    }
  }
  </code></pre>