<!DOCTYPE html>
<html>

<title>P1855R0: Make &lt;compare&gt; freestanding</title>
<style type="text/css">
  p {text-align:justify}
  li {text-align:justify}
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table {border-collapse: collapse;}
</style>
<body>
<h1>Make &lt;compare&gt; freestanding</h1>
Document number: P1855R0<br/>
Date: 2019-10-05<br/>
Reply-to:<br/>
&nbsp;&nbsp;Ben Craig (National Instruments) &lt;ben dot craig at gmail dot com&gt;<br/>
&nbsp;&nbsp;Bryce Adelstein Lelbach (NVIDIA) &lt;brycelelbach at gmail dot com&gt;<br/>
Audience: Library Evolution Working Group

<h1>The problem</h1>
<p>
In Cologne, <a href="https://wg21.link/p1614r2">the mothership landed</a> and <code>&lt;coroutine&gt;</code> got updated to use op&lt=&gt;.  <code>&lt;coroutine&gt;</code> is a <a href="https://wg21.link/compliance">freestanding header</a>.  <code>&lt;compare&gt;</code> isn’t listed as freestanding.
</p><p>
Pedantically, <code>&lt;coroutine&gt;</code> is part of the implementation, so it can do whatever it wants.  However, if the user wants to compare <code>coroutine_handle</code>s, then I think they need to include <code>&lt;compare&gt;</code> <a href="https://wg21.link/expr.spaceship#10">[expr.spaceship]</a>.
</p><p>
So we should add <code>&lt;compare&gt;</code> to freestanding to resolve the issue.  This follows the C++98 - C++20 design precedent of having core language support in the freestanding library.
</p>

<h1>Proposed resolution:</h1>
<p>
Make <code>&lt;compare&gt;</code> freestanding.  <code>&lt;compare&gt;</code> was identified as a potential addition to freestanding in the February 2018, Pre-Jacksonville mailing in the omnibus <a href="https://wg21.link/P0829R1">Freestanding Proposal R1</a> paper.  At the time, adding it to freestanding wasn't as urgent, as no other freestanding facilities depended on it.
</p><p>
The header <code>&lt;compare&gt;</code> specifies types, objects, and functions for use primarily in connection with the three-way comparison operator.  This largely involves types with <code>constexpr</code>, <code>noexcept</code> comparison operator members.  There are also some concepts, a type_trait-like struct, and a "Niebloid" for the <code>compare_three_way</code> algorithm.
</p><p>
None of the facilities in <code>&lt;compare&gt;</code> require exceptions, RTTI, heap storage, virtual functions, function pointers, recursion, thread local storage, floating point, dynamic global initialization, dynamic global destructors, process exit functionality, atomics, or thread-safe statics.
</p><p>
None of the facilities in <code>&lt;compare&gt;</code> require facilities in non-freestanding headers.
</p><p>
<code>&lt;compare&gt;</code> can be implemented entirely in a header, without requiring a built library that needs to be linked against.
</p><p>
Making <code>&lt;compare&gt;</code> freestanding this late in the standards process isn't ideal, but it is still very low risk.
</p>

<h1>Consequences of delaying or rejecting:</h1>
<p>
Suppose we decide not to put this in C++20, or decide not to do this at all.  What are the ramifications for the standard?  What are the ramifications to users?
</p><p>
In the abstract, the standard will be falsely advertising that <code>coroutine_handle</code> can be compared or used with the three-way comparison operator in freestanding.  There will also be a core language feature that isn't readily usable in freestanding.
</p><p>
In practice, there aren't many users of strictly minimal freestanding implementations.  Implementers are allowed to provide additional facilities beyond the bare minimum, and would likely provide a <code>&lt;compare&gt;</code> header.  Even if the implementer didn't provide <code>&lt;compare&gt;</code>, it would only affect the ability of the user to do three-way comparisons and ordered comparisons on <code>coroutine_handle</code>.
</p><p>
Adding the header to the freestanding subset later wouldn't break binary or source compatibility.
</p>
<h1>Wording:</h1>
<p>This wording is relative to <a href="https://wg21.link/n4830">N4830</a>.</p>

<ol>
<li><p>In 16.5.1.3 <a href="https://wg21.link/compliance">[compliance]</a>, add a new row to
<a href="https://wg21.link/compliance#tab:headers.cpp.fs">Table 22</a>:</p>

<blockquote>
<table style="border: 1px solid black">
<caption>Table 22 &mdash; C++ headers for freestanding implementations</caption>
<thead>
<tr style="border: 1px solid black">
<th colspan="2" style="text-align: center">Subclause</th><th style="text-align: center">Header(s)</th>
</tr>
</thead>
<tbody>
<tr style="border: 1px solid black">
<td style="padding: 0ex 1ex 0ex 1ex">[&hellip;]</td>
<td style="padding: 0ex 1ex 0ex 1ex">[&hellip;]</td>
<td style="padding: 0ex 1ex 0ex 1ex">[&hellip;]</td>
</tr>
<tr style="border: 1px solid black">
<td style="padding: 0ex 1ex 0ex 1ex">17.10 <a href="https://wg21.link/support.initlist">[support.initlist]</a></td>
<td style="padding: 0ex 1ex 0ex 1ex">Initializer lists</td>
<td style="padding: 0ex 1ex 0ex 1ex"><tt>&lt;initializer_list&gt;</tt></td>
</tr>
<tr style="border: 1px solid black">
<td style="padding: 0ex 1ex 0ex 1ex"><ins>17.11 <a href="https://wg21.link/cmp">[cmp]</a></ins></td>
<td style="padding: 0ex 1ex 0ex 1ex"><ins>Comparisons</ins></td>
<td style="padding: 0ex 1ex 0ex 1ex"><ins><tt>&lt;compare&gt;</tt></ins></td>
</tr>
<tr style="border: 1px solid black">
<td style="padding: 0ex 1ex 0ex 1ex">17.12 <a href="https://wg21.link/support.coroutine">[support.cooutine]</a></td>
<td style="padding: 0ex 1ex 0ex 1ex">Coroutines support</td>
<td style="padding: 0ex 1ex 0ex 1ex"><tt>&lt;coroutine&gt;</tt></td>
</tr>
<tr style="border: 1px solid black">
<td style="padding: 0ex 1ex 0ex 1ex">[&hellip;]</td>
<td style="padding: 0ex 1ex 0ex 1ex">[&hellip;]</td>
<td style="padding: 0ex 1ex 0ex 1ex">[&hellip;]</td>
</tr>
</tbody>
</table>

</blockquote>
</li>
</ol>

</body>
