Skip to content

Commit 28dae65

Browse files
committed
New issue: Algorithm requirements don't describe semantics of 's - i' well
1 parent 44001be commit 28dae65

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

xml/issue4462.xml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4462" status="New">
5+
<title>Algorithm requirements don't describe semantics of `s - i` well</title>
6+
<section><sref ref="[algorithms.requirements]"/></section>
7+
<submitter>Jonathan Wakely</submitter>
8+
<date>07 Nov 2025</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<b>Addresses <a href="https://github.com/cplusplus/nbballot/issues/827">US 154-252</a></b>
13+
<p>
14+
“the semantics of `s - i` has” is not grammatically correct.
15+
Additionally, “type, value, and value category” are properties of expressions,
16+
not “semantics”.
17+
</p>
18+
</discussion>
19+
20+
<resolution>
21+
<p>
22+
This wording is relative to <paper num="N5014"/>.
23+
</p>
24+
25+
<ol>
26+
<li><p>Modify <sref ref="[algorithms.requirements]"/>, as indicated:</p>
27+
28+
<blockquote>
29+
<p>-11-
30+
In the description of the algorithms, operator `+` is used for some of the
31+
iterator categories for which it does not have to be defined.
32+
In these cases the semantics of `a + n` are the same as those of
33+
<pre>
34+
auto tmp = a;
35+
for (; n &lt; 0; ++n) --tmp;
36+
for (; n &gt; 0; --n) ++tmp;
37+
return tmp;
38+
</pre>
39+
Similarly, operator `-` is used for some combinations of iterators
40+
and sentinel types for which it does not have to be defined.
41+
If [`a`, `b`) denotes a range, the semantics of `b - a` in these cases
42+
are the same as those of
43+
<pre>
44+
iter_difference_t&lt;decltype(a)&gt; n = 0;
45+
for (auto tmp = a; tmp != b; ++tmp) ++n;
46+
return n;
47+
</pre>
48+
and if [`b`, `a`) denotes a range, the same as those of
49+
<pre>
50+
iter_difference_t&lt;decltype(b)&gt; n = 0;
51+
for (auto tmp = b; tmp != a; ++tmp) --n;
52+
return n;
53+
</pre>
54+
</p>
55+
<p>
56+
For each iterator `i` and sentinel `s` produced from a range `r`,
57+
the semantics of `s - i`
58+
<ins>are the same as those of an expression that</ins>
59+
has the same type, value,
60+
and value category as `ranges::distance(i, s)`.
61+
</p>
62+
<p>
63+
[<i>Note 3</i>: The implementation can use `ranges::distance(r)`
64+
when that produces the same value as `ranges::distance(i, s)`.
65+
This can be more efficient for sized ranges. &mdash; <i>end note</i>]
66+
</p>
67+
</blockquote>
68+
</li>
69+
</ol>
70+
71+
</resolution>
72+
73+
</issue>

0 commit comments

Comments
 (0)