title: why does the equivalent condition necessary?
body: <p>I have a question on the code piece from <a href="https://rads.stackoverflow.com/amzn/click/com/B000K1YANC" rel="nofollow noreferrer" rel="nofollow noreferrer" title="link to Amazon">C++ standard library</a>. My question is that <code>!(p2.lastname() &lt; p1.lastname())</code> seems not to be necessary because I think the condition represents the last names are in p1 and p2 equivalent. If I removed the condition, the code seems to work properly. I saw this <em>strict weak ordering</em>. I read the relevant article but I did not fully understand the concept. Would you please explain why the condition is required?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>class Person {
  public:
    string firstname() const;
    string lastname() const;
  };
  
  class PersonSortCriterion {
  public:
    bool operator() (const Person&amp; p1, const Person&amp; p2) const {
      // 1) Compare the lastnames.
      // 2) If the lastnames are equivalent, compare the firstnames.
      return p1.lastname() &lt; p2.lastname() ||
         (!(p2.lastname() &lt; p1.lastname()) &amp;&amp;
            p1.firstname() &lt; p2.firstname());
    }
  };
  </code></pre>