Skip to content

Commit d172594

Browse files
committed
Jonathan adds P/R to 4293
1 parent 15695bc commit d172594

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

xml/issue4293.xml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,131 @@ A proposed fix (thanks to Jonathan Wakely) could look like this following:
3333
for the affected paragraphs,
3434
which would explicitly specify the constructor used.
3535
</p>
36+
37+
<note>2025-07-11; Jonathan adds proposed resolution</note>
38+
<p>
39+
The meaning of those <i>Effects</i>: paragraphs was changed for C++26 by
40+
<paper num="P2447R6"/> which added the `span(initializer_list)` constructor.
41+
A simpler demo is:
42+
<blockquote><pre><code>
43+
bool a[5]{};
44+
std::span&lt;const bool&gt; s(a);
45+
std::span&lt;const bool&gt; s2 = s.first(5);
46+
assert(s2.size() == 5); // OK in C++23, fails in C++26
47+
assert(s2.data() == a); // OK in C++23, fails in C++26
48+
</code></pre></blockquote>
49+
The proposed resolution is to use `R(data(), count)` instead of
50+
`{data(), count}`. The former always (uniformly) means the same thing,
51+
but for the latter the meaning of list-initialization depends on the types.
52+
The list-initialization form will choose the initializer-list constructor
53+
when `data()` and `count` are both convertible to the element type.
54+
</p>
3655
</discussion>
3756

3857
<resolution>
3958
<p>
59+
This wording is relative to <paper num="N5008"/>.
60+
</p>
61+
62+
<ol>
63+
64+
<li><p>Modify <sref ref="[span.sub]"/> as indicated:</p>
65+
66+
<blockquote>
67+
68+
<pre><code>
69+
template&lt;size_t Count&gt; constexpr span&lt;element_type, Count&gt; first() const;
70+
</code></pre>
71+
<blockquote>
72+
<p>-1- <i>Mandates</i>: <code>Count &lt;= Extent</code> is `true`.</p>
73+
<p>-2- <i>Hardened preconditions</i>: <code>Count &lt;= size()</code> is `true`.</p>
74+
<p>-3- <i>Effects</i>: Equivalent to:
75+
<code>return R<ins>(</ins><del>{</del>data(), Count<del>}</del><ins>)</ins>;</code>
76+
where `R` is the return type.
77+
</p>
78+
</blockquote>
79+
80+
<pre><code>
81+
template&lt;size_t Count&gt; constexpr span&lt;element_type, Count&gt; last() const;
82+
</code></pre>
83+
<blockquote>
84+
<p>-4- <i>Mandates</i>: <code>Count &lt;= Extent</code> is `true`.</p>
85+
<p>-5- <i>Hardened preconditions</i>: <code>Count &lt;= size()</code> is `true`.</p>
86+
<p>-6- <i>Effects</i>: Equivalent to:
87+
<code>return R<ins>(</ins><del>{</del>data() + (size() - Count), Count<del>}</del><ins>)</ins>;</code>
88+
where `R` is the return type.
89+
</p>
90+
</blockquote>
91+
92+
<pre><code>
93+
template&lt;size_t Offset, size_t Count = dynamic_extent&gt;
94+
constexpr span&lt;element_type, <i>see below</i>&gt; subspan() const;
95+
</code></pre>
96+
<blockquote>
97+
<p>-7- <i>Mandates</i>:
98+
<pre><code> Offset &lt;= Extent &amp;&amp; (Count == dynamic_extent || Count &lt;= Extent - Offset)
99+
</code></pre>
100+
is `true`.</p>
101+
<p>-8- <i>Hardened preconditions</i>:
102+
<pre><code> Offset &lt;= size() &amp;&amp; (Count == dynamic_extent || Count &lt;= size() - Offset)
103+
</code></pre>
104+
is `true`.</p>
105+
<p>-9- <i>Effects</i>: Equivalent to:
106+
<pre><code> return span&lt;ElementType, <i>see below</i>&gt;(
107+
data() + Offset, Count != dynamic_extent ? Count : size() - Offset);
108+
</code></pre>
40109
</p>
110+
<p>-10- <i>Remarks</i>:
111+
The second template argument of the returned `span` type is:
112+
<pre><code> Count != dynamic_extent ? Count
113+
: (Extent != dynamic_extent ? Extent - Offset
114+
: dynamic_extent)
115+
</code></pre>
116+
</p>
117+
</blockquote>
118+
119+
<pre><code>
120+
constexpr span&lt;element_type, dynamic_extent&gt; first(size_type count) const;
121+
</code></pre>
122+
<blockquote>
123+
<p>-11- <i>Hardened preconditions</i>: <code>count &lt;= size()</code> is `true`.</p>
124+
<p>-12- <i>Effects</i>: Equivalent to:
125+
<code>return <ins>R(</ins><del>{</del>data(), count<del>}</del><ins>)</ins>;</code>
126+
<ins>where `R` is the return type</ins>.
127+
</p>
128+
</blockquote>
129+
130+
<pre><code>
131+
constexpr span&lt;element_type, dynamic_extent&gt; last(size_type count) const;
132+
</code></pre>
133+
<blockquote>
134+
<p>-13- <i>Hardened preconditions</i>: <code>count &lt;= size()</code> is `true`.</p>
135+
<p>-14- <i>Effects</i>: Equivalent to:
136+
<code>return <ins>R(</ins><del>{</del>data() + (size() - count), count<del>}</del><ins>)</ins>;</code>
137+
<ins>where `R` is the return type</ins>.
138+
</p>
139+
</blockquote>
140+
141+
<pre><code>
142+
constexpr span&lt;element_type, dynamic_extent&gt; subspan(
143+
size_type offset, size_type count = dynamic_extent) const;
144+
</code></pre>
145+
<blockquote>
146+
<p>-15- <i>Hardened preconditions</i>:
147+
<pre><code> offset &lt;= size() &amp;&amp; (count == dynamic_extent || count &lt;= size() - offset
148+
</code></pre>
149+
is `true`.</p>
150+
<p>-16- <i>Effects</i>: Equivalent to:
151+
<pre><code> return <ins>R(</ins><del>{</del>data() + offset, count == dynamic_extent ? size() - offset : count<del>}</del><ins>)</ins>;
152+
</code></pre>
153+
<ins>where `R` is the return type</ins>.
154+
</p>
155+
</blockquote>
156+
157+
</blockquote>
158+
</li>
159+
</ol>
160+
41161
</resolution>
42162

43163
</issue>

0 commit comments

Comments
 (0)