title: operator< comparing multiple fields
body: <p>I have the following operator&lt; that is supposed to sort first by a value, then by another value:</p>
  
  <pre><code>    inline bool operator &lt; (const obj&amp; a, const obj&amp; b) 
      {
          if(a.field1&lt; b.field1)
              return true;
          else
              return a.field2 &lt; b.field2;
      }
  </code></pre>
  
  <p>I have the feeling this is incorrect and that you can't do that without another third comparaison test on the members variables, but I can't find any example where this doesn't work.
  So whould this really sort as expected?
  thanks</p>
  
  <p>edit :
  I would have coded it as :</p>
  
  <pre><code>    inline bool operator &lt; (const obj&amp; a, const obj&amp; b) 
      {
          if(a.field1&lt; b.field1)
              return true;
                      else if(a.field1&gt; b.field1)
              return false;
          else
              return a.field2 &lt; b.field2;
      }
  </code></pre>
  
  <p>are there any differences? I'm asking because I know mine is correct from experience but also longer than the first one</p>