<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2417: [fund.ts.v2] std::experimental::optional::operator&lt; and LessThanComparable requirement</title>
<meta property="og:title" content="Issue 2417: [fund.ts.v2] std::experimental::optional::operator&lt; and LessThanComparable requirement">
<meta property="og:description" content="C++ library issue. Status: NAD">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2417.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  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.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#NAD">NAD</a> status.</em></p>
<h3 id="2417"><a href="lwg-closed.html#2417">2417</a>. [fund.ts.v2] <code>std::experimental::optional::operator&lt;</code> and <code>LessThanComparable</code> requirement</h3>
<p><b>Section:</b> 5.7 <a href="https://cplusplus.github.io/fundamentals-ts/v2.html#optional.relops">[fund.ts.v2::optional.relops]</a>, 5.9 <a href="https://cplusplus.github.io/fundamentals-ts/v2.html#optional.comp_with_t">[fund.ts.v2::optional.comp_with_t]</a> <b>Status:</b> <a href="lwg-active.html#NAD">NAD</a>
 <b>Submitter:</b> Daniel Kr&uuml;gler <b>Opened:</b> 2014-06-20 <b>Last modified:</b> 2025-03-13</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
<p><b>Discussion:</b></p>
<p><b>Addresses: fund.ts.v2</b></p>
<p>
Currently, <code>std::experimental::optional::operator==</code> imposes the <code>EqualityComparable</code> requirement which provides
two guarantees: It ensures that <code>operator!=</code> can rely on the equivalence-relation property and more importantly, that
the <code>BooleanTestable</code> requirements suggested by issue <a href="lwg-defects.html#2114" title="Incorrect &quot;contextually convertible to bool&quot; requirements (Status: Resolved)">2114</a><sup><a href="https://cplusplus.github.io/LWG/issue2114" title="Latest snapshot">(i)</a></sup> are automatically implied.
<p/>
<code>std::experimental::optional::operator&lt;</code> doesn't provide a <code>LessThanComparable</code> requirement, but there was quite
an historic set of changes involved with that family of types: As of <a href="https://wg21.link/N3527" title=" A proposal to add a utility class to represent optional objects (Revision 2)">N3527</a>
this operator was defined in terms of <code>operator&lt;</code> of the contained type <code>T</code> and imposed the <code>LessThanComparable</code>
requirement. In the final acceptance step of <code>optional</code> by the committee, the definition was expressed in terms of <code>std::less</code>
and the <code>LessThanComparable</code> requirement had been removed.
<p/>
The inconsistency between <code>operator==</code> and <code>operator&lt;</code> should be removed. One possible course of action would be
to add the <code>LessThanComparable</code> to <code>std::experimental::optional::operator&lt;</code>. The <code>EqualityComparable</code> requirement
of <code>operator==</code> could also be removed, but in that case both operators would at least need to require the <code>BooleanTestable</code>
requirements (see <a href="lwg-defects.html#2114" title="Incorrect &quot;contextually convertible to bool&quot; requirements (Status: Resolved)">2114</a><sup><a href="https://cplusplus.github.io/LWG/issue2114" title="Latest snapshot">(i)</a></sup>) for the result type of <code>T</code>'s <code>operator==</code> and <code>operator&lt;</code>.
<p/>
Arguably, corresponding operators for <code>pair</code> and <code>tuple</code> do not impose <code>LessThanComparable</code> (nor
<code>EqualityComparable</code>), albeit the definition of the "derived" relation functions depend on properties ensured by
<code>LessThanComparable</code>. According to the <a href="https://www.boost.org/sgi/stl/pair.html">SGI definition</a>, the intention was
to imposed both <code>EqualityComparable</code> and <code>LessThanComparable</code>. If this is not intended, the standard should clarify
this position.
</p>

<p><i>[2015-02 Cologne]</i></p>

<p>
VV, DK, JY discuss why and when <code>LessThanComparable</code> was removed. AM: Move to LEWG. Please tell LWG when you look at it.
</p>

<p><i>[2016-11-08, Issaquah]</i></p>

<p>Not adopted during NB comment resolution</p>

<p><i>[LEWG Kona 2017]</i></p>

<p>Recommend NAD: We've done a lot of work getting the C++17 semantics we want in this area; we're not going to change
them 3 days from DIS or change the TSv2 behavior to be different from '17.</p>


<p id="res-2417"><b>Proposed resolution:</b></p>





</body>
</html>
