title: Implementing operator< in C++
body: <p>I have a class with a few numeric fields such as:</p>
  
  <pre><code>class Class1 {
      int a;
      int b;
      int c;
  public:
      // constructor and so on...
      bool operator&lt;(const Class1&amp; other) const;
  };
  </code></pre>
  
  <p>I need to use objects of this class as a key in an <code>std::map</code>. I therefore implement <code>operator&lt;</code>. What is the simplest implementation of <code>operator&lt;</code> to use here?</p>
  
  <p><strong>EDIT:</strong>
  The meaning of <code>&lt;</code> can be assumed so as to guarantee uniqueness as long as any of the fields are unequal.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>A simplistic implementation:</p>
  
  <pre><code>bool Class1::operator&lt;(const Class1&amp; other) const {
      if(a &lt; other.a) return true;
      if(a &gt; other.a) return false;
  
      if(b &lt; other.b) return true;
      if(b &gt; other.b) return false;
  
      if(c &lt; other.c) return true;
      if(c &gt; other.c) return false;
  
      return false;
  }
  </code></pre>
  
  <p>The whole reason behind this post is just that I found the above implementation too verbose. There ought to be something simpler.</p>