<h1 id="unifying-the-many-ways-to-compare">Unifying the many ways to compare</h1>
<pre>
Date: 2018-10-07
Author: David Stone (&#100;&#97;&#118;&#105;&#100;&#109;&#115;&#116;&#111;&#110;&#101;&#64;&#103;&#111;&#111;&#103;&#108;&#101;&#46;&#99;&#111;&#109;, &#100;&#97;&#118;&#105;&#100;&#64;&#100;&#111;&#117;&#98;&#108;&#101;&#119;&#105;&#115;&#101;&#46;&#110;&#101;&#116;)
Audience: Library Evolution Working Group (LEWG)
</pre>

<h2 id="dependencies">Dependencies</h2>
<ul>
<li><a href="http://wg21.link/P0790">P0790: Effect of <code>operator&lt;=&gt;</code> on the C++ Standard Library</a></li>
<li><a href="http://wg21.link/P1190">P1190: I did not order this</a></li>
</ul>
<h2 id="background">Background</h2>
<p>We currently have several facilities to compare things (mostly strings). We should unify on &quot;the one true way&quot;. For reference, the currently existing functionality relevant to this paper (other than existing comparison operators) is:</p>
<ul>
<li><code>char_traits::eq</code> (returns <code>bool</code>)</li>
<li><code>char_traits::eq_int_type</code> (returns <code>bool</code>)</li>
<li><code>char_traits::lt</code> (returns <code>bool</code>)</li>
<li><code>char_traits::compare</code> (returns <code>int</code>)</li>
<li><code>basic_string::compare</code> (returns <code>int</code>)</li>
<li><code>basic_string_view::compare</code> (returns <code>int</code>)</li>
<li><code>sub_match::compare</code> (returns <code>int</code>)</li>
<li><code>istreambuf_iterator::equal</code> (returns <code>bool</code>)</li>
<li><code>filesystem::path::compare</code> (returns <code>int</code>)</li>
<li><code>filesystem::equivalent</code> (returns <code>bool</code>, provides the weak equality of whether two paths resolve to the same file)</li>
</ul>
<p>Note that for <code>char_traits</code>, we also have a &quot;character traits&quot; &#39;concept&#39; with the same requirements as the concrete <code>char_traits</code> type.</p>
<h2 id="proposal">Proposal</h2>
<ul>
<li>Add <code>char_traits::cmp</code>, which returns <code>std::strong_ordering</code> for all built-in character types.</li>
<li>Require all character traits classes to<ul>
<li>have a static member function <code>cmp</code> that returns a comparison category or</li>
<li>have <code>lt</code> and <code>compare</code> (as they do now).</li>
</ul>
</li>
<li>Deprecate support for character traits classes that do not have static member <code>cmp</code>.</li>
<li>Remove the requirement that character traits classes provide <code>lt</code> and <code>compare</code>.</li>
<li>Deprecate <code>char_traits::lt</code> and <code>char_traits::compare</code>.<ul>
<li>Note: we may also deprecate <code>eq</code> and <code>eq_int_type</code>, depending on the outcome of <a href="http://wg21.link/P1190">P1190: I did not order this</a>.</li>
</ul>
</li>
<li>Deprecate <code>basic_string::compare</code> <code>basic_string_view::compare</code>, <code>sub_match::compare</code>, and <code>filesystem::path::compare</code> in favor of <code>operator&lt;=&gt;</code>.</li>
<li>Deprecate <code>istreambuf_iterator::equal</code> in favor of <code>operator==</code>.</li>
<li>Deprecate <code>filesystem::equivalent</code> (operating on <code>filesystem::path</code> objects) in favor of an overload of <code>std::weak_equality</code>?</li>
</ul>

