<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3118: fpos equality comparison unspecified</title>
<meta property="og:title" content="Issue 3118: fpos equality comparison unspecified">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3118.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#C++23">C++23</a> status.</em></p>
<h3 id="3118"><a href="lwg-defects.html#3118">3118</a>. <code>fpos</code> equality comparison unspecified</h3>
<p><b>Section:</b> 31.5.3.3 <a href="https://wg21.link/fpos.operations">[fpos.operations]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2018-06-04 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>4
</p>
<p><b>View all other</b> <a href="lwg-index.html#fpos.operations">issues</a> in [fpos.operations].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++23">C++23</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The <code>fpos</code> requirements do not give any idea what is compared by <code>operator==</code> (even after Daniel's 
<a href="https://wg21.link/p0759r1">P0759R1</a> paper). I'd like something to make it clear that <code>return true;</code> 
is not a valid implementation of <code>operator==(const fpos&lt;T&gt;&amp;, const fpos&lt;T&gt;&amp;)</code>. Maybe in the 
<code>P(o)</code> row state that "<code>p == P(o)</code>" and "<code>p != P(o + 1)</code>", i.e. two <code>fpos</code> objects 
constructed from the same <code>streamoff</code> values are equal, and two <code>fpos</code> objects constructed from two 
different <code>streamoff</code> values are not equal.
</p>

<p><i>[2018-06-23 after reflector discussion]</i></p>

<p>Priority set to 4</p>

<p><i>[2022-05-01; Daniel comments and provides wording]</i></p>

<p>
The proposed wording does intentionally not use a form involving addition or subtraction to prevent the need
for extra wording that ensures that this computed value is well-defined. According to 31.2.2 <a href="https://wg21.link/stream.types">[stream.types]</a>,
<code>streamoff</code> is a signed basic integral type, so we know what equality means for such values.
</p>

<p><strong>Previous resolution [SUPERSEDED]:</strong></p>
<blockquote class="note">
<p>
This wording is relative to <a href="https://wg21.link/N4910" title=" Working Draft, Standard for Programming Language C++">N4910</a>.
</p>

<li><p>Modify in 31.5.3.3 <a href="https://wg21.link/fpos.operations">[fpos.operations]</a> as indicated:</p>

<blockquote class="note">
<p>
[<i>Drafting note:</i> The return type specification of <code>operator==</code> should be resolved in
sync with <a href="https://isocpp.org/files/papers/D2167R2.html">D2167R2</a>; see also LWG
<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>.]
</p>
</blockquote>

<blockquote>

<ol style="list-style-type:none">
<li><p>(1.1) &mdash; [&hellip;]</p></li>
<li><p>[&hellip;]</p></li>
<li><p>(1.5) &mdash; <code>o</code> <ins>and <code>o2</code></ins> refer<del>s</del> to <del>a</del> value<ins>s</ins> 
of type <code>streamoff</code> or <code>const streamoff</code>.</p></li>
</ol>
<table border="1">
<caption>Table 119: Position type requirements [tab:fpos.operations]</caption>

<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion/note<br/>pre-/post-condition</th>
</tr>

<tr>
<td colspan="4" style="text-align:center;">&hellip;</td> 
</tr>

<tr>
<td><code>P p(o);<br/>
P p = o;</code></td>
<td></td>
<td></td>
<td><i>Effects:</i> Value-initializes the<br/>
state object.<br/>
<i>Postconditions:</i> <code>p == P(o)</code> <ins>is <code>true</code>.</ins></td>
</tr>

<tr>
<td colspan="4" style="text-align:center;">&hellip;</td> 
</tr>

<tr>
<td><code>O(p)</code></td>
<td><code>streamoff</code></td>
<td>converts to <code>offset</code></td>
<td><code>P(O(p)) == p</code></td>
</tr>

<tr>
<td><ins><code>p == q</code></ins></td>
<td><ins>convertible to <code>bool</code></ins></td>
<td></td>
<td><ins><i>Remarks:</i> For any two values <code>o</code> and <code>o2</code>, if<br/> 
<code>p</code> is obtained from <code>o</code> converted to <code>P</code> or from a copy<br/> 
of such <code>P</code> value and if <code>q</code> is obtained from <code>o2</code><br/> 
converted to <code>P</code> or from a copy of such <code>P</code> value, then<br/> 
<code>bool(p == q)</code> is <code>true</code> only if <code>o == o2</code> is <code>true</code>.</ins></td>
</tr>

<tr>
<td><code>p != q</code></td>
<td>convertible to <code>bool</code></td>
<td><code>!(p == q)</code></td>
<td></td>
</tr>

<tr>
<td colspan="4" style="text-align:center;">&hellip;</td> 
</tr>

</table>
</blockquote>
</li>
</blockquote>

<p><i>[2022-11-02; Daniel  comments and improves wording]</i></p>

<p>
<a href="https://wiki.edg.com/bin/view/Wg21telecons2022/P2167-20220921">LWG discussion</a> of <a href="https://wg21.link/P2167R2" title=" Improved Proposed Wording for LWG 2114 (contextually convertible to bool)">P2167R2</a>
has shown preference to require that the equality operations of <code>fpos</code> should be specified to have type
<code>bool</code> instead of being specified as "convertible to <code>bool</code>". This has been reflected in the most recent
paper revision <a href="https://isocpp.org/files/papers/P2167R3.html">P2167R3</a>. The below wording changes
follow that direction to reduce the wording mismatch to a minimum.
</p>

<p><i>[2022-11-02; LWG telecon]</i></p>

<p>Moved to Ready. For: 6, Against: 0, Neutral: 0</p>

<p><i>[2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting &rarr; WP.]</i></p>



<p id="res-3118"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4917" title=" Working Draft, Standard for Programming Language C++">N4917</a>.
</p>

<li><p>Modify in 31.5.3.3 <a href="https://wg21.link/fpos.operations">[fpos.operations]</a> as indicated:</p>

<blockquote>

<ol style="list-style-type:none">
<li><p>(1.1) &mdash; [&hellip;]</p></li>
<li><p>[&hellip;]</p></li>
<li><p>(1.5) &mdash; <code>o</code> <ins>and <code>o2</code></ins> refer<del>s</del> to <del>a</del> value<ins>s</ins> 
of type <code>streamoff</code> or <code>const streamoff</code>.</p></li>
</ol>
<table border="1">
<caption>Table 124: Position type requirements [tab:fpos.operations]</caption>

<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational<br/>semantics</th>
<th>Assertion/note<br/>pre-/post-condition</th>
</tr>

<tr>
<td colspan="4" style="text-align:center;">&hellip;</td> 
</tr>

<tr>
<td><code>P p(o);<br/>
P p = o;</code></td>
<td></td>
<td></td>
<td><i>Effects:</i> Value-initializes the<br/>
state object.<br/>
<i>Postconditions:</i> <code>p == P(o)</code> <ins>is <code>true</code>.</ins></td>
</tr>

<tr>
<td colspan="4" style="text-align:center;">&hellip;</td> 
</tr>

<tr>
<td><code>O(p)</code></td>
<td><code>streamoff</code></td>
<td>converts to <code>offset</code></td>
<td><code>P(O(p)) == p</code></td>
</tr>

<tr>
<td><ins><code>p == q</code></ins></td>
<td><ins><code>bool</code></ins></td>
<td></td>
<td><ins><i>Remarks:</i> For any two values <code>o</code> and <code>o2</code>, if<br/> 
<code>p</code> is obtained from <code>o</code> converted to <code>P</code> or from a copy<br/> 
of such <code>P</code> value and if <code>q</code> is obtained from <code>o2</code><br/> 
converted to <code>P</code> or from a copy of such <code>P</code> value, then<br/> 
<code>p == q</code> is <code>true</code> only if <code>o == o2</code> is <code>true</code>.</ins></td>
</tr>

<tr>
<td><code>p != q</code></td>
<td><del>convertible to</del> <code>bool</code></td>
<td><code>!(p == q)</code></td>
<td></td>
</tr>

<tr>
<td colspan="4" style="text-align:center;">&hellip;</td> 
</tr>

</table>
</blockquote>
</li>





</body>
</html>
