<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 3236: Random access iterator requirements lack limiting relational operators domain to comparing 
those from the same range</title>
<meta property="og:title" content="Issue 3236: Random access iterator requirements lack limiting relational operators domain to comparing 
those from the same range">
<meta property="og:description" content="C++ library issue. Status: C++23">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue3236.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="3236"><a href="lwg-defects.html#3236">3236</a>. Random access iterator requirements lack limiting relational operators domain to comparing 
those from the same range</h3>
<p><b>Section:</b> 24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a> <b>Status:</b> <a href="lwg-active.html#C++23">C++23</a>
 <b>Submitter:</b> Peter Sommerlad <b>Opened:</b> 2019-07-15 <b>Last modified:</b> 2023-11-22</p>
<p><b>Priority: </b>3
</p>
<p><b>View all other</b> <a href="lwg-index.html#random.access.iterators">issues</a> in [random.access.iterators].</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>
For forward iterators we have very clear wording regarding the restricted domain of <code>operator==</code>
in 24.3.5.5 <a href="https://wg21.link/forward.iterators">[forward.iterators]</a> p2:
</p>
<blockquote><p>
The domain of <code>==</code> for forward iterators is that of iterators over the same underlying sequence. 
However, value-initialized iterators may be compared and shall compare equal to other value-initialized 
iterators of the same type. [<i>Note:</i> Value-initialized iterators behave as if they refer past the 
end of the same empty sequence. &mdash; <i>end note</i>]
</p></blockquote>
<p>
But for the relational operators of random access iterators specified in 
24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a>, Table  [tab:randomaccessiterator],
no such domain constraints are clearly defined, except that we can infer that they are
similarly constrained as the difference of the compared iterators by means of the
operational semantics of <code>operator&lt;</code>.
</p>

<p><i>[2019-07-29; Casey comments and provides wording]</i></p>

<p>
Change the "Operational Semantics" column of the "<code>a &lt; b</code>" row of [tab:randomaccessiterator] to 
"<ins><i>Effects:</i> Equivalent to: <code>return</code></ins> <code>b - a &gt; 0</code><ins>;</ins>
<p/>
It then follows that <code>a &lt; b</code> is required to be well-defined over the domain for which 
<code>b - a</code> is required to be well-defined, which is the set of pairs <code>(x, y)</code> such that 
there exists a value <code>n</code> of type difference_type such that <code>x + n == b</code>.
</p>

<p><i>[2020-02-13, Prague]</i></p>

<p>
P3, but some hesitation to make it Immediate, therefore moving to Ready.
</p>
<p><i>[2020-11-09 Approved In November virtual meeting. Status changed: Ready &rarr; WP.]</i></p>



<p id="res-3236"><b>Proposed resolution:</b></p>
<p>This wording is relative to <a href="https://wg21.link/n4849">N4849</a>.</p>

<ol>
<li><p>Modify 24.3.5.7 <a href="https://wg21.link/random.access.iterators">[random.access.iterators]</a> as indicated:</p>

<blockquote>
<table border="1">
<caption>Table 87: <i>Cpp17RandomAccessIterator</i> requirements (in addition to 
<i>Cpp17BidirectionalIterator</i>) [tab:randomaccessiterator]</caption>
<tr align="center">
<th>Expression</th>
<th>Return type</th>
<th>Operational semantics</th>
<th>Assertion&#47;note<br/>pre-&#47;post-condition</th>
</tr> 

<tr>
<td colspan="4" align="center">
<code>[&hellip;]</code>
</td>
</tr>

<tr>
<td>
<code>a &lt; b</code>
</td>
<td>
contextually convertible to <code>bool</code>
</td>
<td>
<ins><i>Effects:</i> Equivalent to: <code>return</code></ins> <code>b - a &gt; 0<ins>;</ins></code>
</td>
<td>
<code>&lt;</code> is a total ordering relation
</td>
</tr>

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




</body>
</html>
