title: std::sort with custom comparator
body: <p>In the following code, why do all three <code>IntComparator()</code>, <code>IntComparator2</code> and <code>IntComparator3</code> work as the 3rd parameter of the <code>sort()</code> function? Wouldn't they have different l-value function types? Based on <a href="https://en.cppreference.com/w/cpp/algorithm/sort" rel="noreferrer">https://en.cppreference.com/w/cpp/algorithm/sort</a> it says</p>
  
  <blockquote>
    <p>The signature of the comparison function should be equivalent to the
    following:</p>
    
    <p>bool cmp(const Type1 &amp;a, const Type2 &amp;b);</p>
  </blockquote>
  
  <p>which seems to match <code>IntComparator2</code> better?</p>
  
  <p>Also which one would be preferable? Third option seems much simpler and more intuitive.</p>
  
  <pre><code>
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;functional&gt;
  
  struct IntComparator
  {
    bool operator()(const int &amp;a, const int &amp;b) const
    {
      return a &lt; b;
    }
  };
  
  bool IntComparator2 (const int &amp;a, const int &amp;b)
  {
      return a &lt; b;
  }
  
  bool IntComparator3 (int a, int b)
  {
      return a &lt; b;
  }
  
  int main()
  {
      int items[] = { 4, 3, 1, 2 };
      std::sort(items, items+4, IntComparator());
  
      for (int n=0; n&lt;4; n++) {
          std::cout &lt;&lt; items[n] &lt;&lt; ", ";
      }
  
      std::cout &lt;&lt; "\n";
  
      int items2[] = { 4, 3, 1, 2 };
      std::sort(items2, items2+4, IntComparator2);
  
      for (int n=0; n&lt;4; n++) {
          std::cout &lt;&lt; items2[n] &lt;&lt; ", ";
      }
  
      std::cout &lt;&lt; "\n";
  
      int items3[] = { 4, 3, 1, 2 };
      std::sort(items3, items3+4, IntComparator3);
  
      for (int n=0; n&lt;4; n++) {
          std::cout &lt;&lt; items3[n] &lt;&lt; ", ";
      }
  
      std::cout &lt;&lt; "\n";
  
      return 0;
  }
  </code></pre>