title: std::map Requirements for Keys (Design Decision)
body: <p>When I make a <code>std::map&lt;my_data_type, mapped_value&gt;</code>, what C++ expects from me is that <code>my_data_type</code> has its own <code>operator&lt;</code>.</p>
  
  <pre><code>struct my_data_type
  {
      my_data_type(int i) : my_i(i) { }
  
      bool operator&lt;(const my_data_type&amp; other) const { return my_i &lt; other.my_i; }
  
      int my_i;
  };
  </code></pre>
  
  <p>The reason is that you can derive <code>operator&gt;</code> and <code>operator==</code> from <code>operator&lt;</code>. <em>b &lt; a</em> implies <em>a > b</em>, so there's <code>operator&gt;</code>. <em>!(a &lt; b) &amp;&amp; !(b &lt; a)</em> means that <em>a</em> is neither less than <em>b</em> nor greater than it, so they must be equal.</p>
  
  <p>The question is: Why hasn't the C++ designer require <code>operator==</code> to be explicitly defined? Obviously, <code>operator==</code> is inevitable for <code>std::map::find()</code> and for removing duplicates from the <code>std::map</code>. Why implement 5 operations and call a method twice in order not to compel me to explicitly implement <code>operator==</code>?</p>