<html><head><meta charset="UTF-8">
<title>Do not add value_exists and value_or to C++23</title>
  <style type='text/css'>
  body {font-variant-ligatures: none;}
  p {text-align:justify}
  li {text-align:justify}
  blockquote.note, div.note
  {
          background-color:#E0E0E0;
          padding-left: 15px;
          padding-right: 15px;
          padding-top: 1px;
          padding-bottom: 1px;
  }
  p code {color:navy}
  ins p code {color:#00A000}
  p ins code {color:#00A000}
  p del code {color:#A00000}
  ins {color:#00A000}
  del {color:#A00000}
  table#boilerplate { border:0 }
  table#boilerplate td { padding-left: 2em }
  table.bordered, table.bordered th, table.bordered td {
    border: 1px solid;
    text-align: center;
  }
  ins.block {color:#00A000; text-decoration: none}
  del.block {color:#A00000; text-decoration: none}
  #hidedel:checked ~ * del, #hidedel:checked ~ * del * { display:none; visibility:hidden }
  </style>
</head><body>
<table id="boilerplate">
<tr><td>Document number</td><td>P2485R0</td></tr>
<tr><td>Date</td><td>2021-11-01</td></tr>
<tr><td>Audience</td><td>LEWG</td></tr>
<tr><td>Reply-to</td><td>Jonathan Wakely &lt;cxx&#x40;kayari.org&gt;</td></tr>
</table><hr>
<h1>Do not add value_exists and value_or to C++23</h1>
<ul>
 <li>
 <ul>
  <li><a href="#Abstract">Abstract</a></li>
  <li><a href="#Discussion">Discussion</a></li>
  <li><a href="#Background">Background</a></li>
  <li><a href="#Proposed-change">Proposed change</a></li>
 </ul>
 </li>
</ul>
<a name="Abstract"></a>
<h2>Abstract</h2>

<p>Drop the <code>value_exists</code> and <code>value_or</code> helpers from
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1841r1.pdf">P1841</a>
and only adopt the numeric traits that are the core of the proposal.</p>

<a name="Discussion"></a>
<h2>Discussion</h2>

<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1841r1.pdf">[P1841R1]</a>
(Wording for Individually Specializable Numeric Traits)
proposes to add:</p>

<pre><code>  template &lt;template&lt;class&gt; class Trait, class T&gt;
    constexpr bool value_exists = requires { Trait&lt;T&gt;::value; };
</code></pre>

<p>(The paper actually says <em>see below</em> and doesn't provide the definition,
but it probably should provide it as above.)</p>

<p>During review of P1841R1 LWG wanted to know why <code>value_exists</code> is used as
<code>value_exists&lt;foo, T&gt;</code> rather than <code>value_exists&lt;foo&lt;T&gt;&gt;</code>.
Why is the proposed design that the <code>value_exists</code> template "applies" the
non-type template argument to the second template argument?
The following seems simpler to understand for non-expert users:</p>

<pre><code>  template &lt;class T&gt;
    constexpr bool value_exists = requires { T::value };
</code></pre>

<p>With this alternative API you would say <code>value_exists&lt;signaling_NaN&lt;float&gt;&gt;</code>
not <code>value_exists&lt;signaling_NaN, float&gt;</code>.</p>

<p>LWG also noted that the proposed API for <code>value_or</code> uses the argument type as
the return type, so that <code>value_or&lt;finite_min, double&gt;(1)</code> is rounded to <code>int</code>.
This is surprising.</p>

<p>On the LEWG reflector I asked whether there is any rationale for
the proposed design of <code>value_exists</code>, and whether we need this utility at all.
There was support for dropping <code>value_exists</code> and <code>value_or</code> from the proposal.</p>

<a name="Background"></a>
<h2>Background</h2>

<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0437r1.pdf">[P0437R1]</a>
(Numeric Traits for the Standard Library)
introduced the <code>value_exists</code> utility, but didn't justify the API choice.
It also pointed out that the adoption of
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0266r1.pdf">[P0266R1]</a>
(Lifting Restrictions on <code>requires</code>-Expressions)
would make it unnecessary.
P0266R1 was adopted at the Issaquah 2016 meeting.</p>

<p>In San Diego the LEWG discussion of P0437R1 included:</p>

<blockquote>
<p>"value_exists belongs in compile-time programming support"</p>

<p>"has value_or &mdash; if not exists, use arg. usefully coupled, but separable."</p>

<p>Want value_exists? <br/> 0 5 6 0 1 </p>
</blockquote>


<p>That is quite weak support. There is no record in the minutes
(or that I recall from that session) about the proposed API.</p>

<a name="Proposed-change"></a>
<h2>Proposed change</h2>

<p>I propose that we drop the <code>value_exists</code> and <code>value_or</code> helpers from
P1841 and only adopt the actual numeric traits.
If we want the metaprogamming helpers,
they can be added separately at a later date.</p>
</body></html>
