@@ -33,11 +33,131 @@ A proposed fix (thanks to Jonathan Wakely) could look like this following:
33
33
for the affected paragraphs,
34
34
which would explicitly specify the constructor used.
35
35
</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< const bool> s(a);
45
+ std::span< const bool> 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 >
36
55
</discussion >
37
56
38
57
<resolution >
39
58
<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< size_t Count> constexpr span< element_type, Count> first() const;
70
+ </code ></pre >
71
+ <blockquote >
72
+ <p >-1- <i >Mandates</i >: <code >Count < = Extent</code > is `true`.</p >
73
+ <p >-2- <i >Hardened preconditions</i >: <code >Count < = 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< size_t Count> constexpr span< element_type, Count> last() const;
82
+ </code ></pre >
83
+ <blockquote >
84
+ <p >-4- <i >Mandates</i >: <code >Count < = Extent</code > is `true`.</p >
85
+ <p >-5- <i >Hardened preconditions</i >: <code >Count < = 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< size_t Offset, size_t Count = dynamic_extent>
94
+ constexpr span< element_type, <i >see below</i >> subspan() const;
95
+ </code ></pre >
96
+ <blockquote >
97
+ <p >-7- <i >Mandates</i >:
98
+ <pre ><code > Offset < = Extent && (Count == dynamic_extent || Count < = Extent - Offset)
99
+ </code ></pre >
100
+ is `true`.</p >
101
+ <p >-8- <i >Hardened preconditions</i >:
102
+ <pre ><code > Offset < = size() && (Count == dynamic_extent || Count < = size() - Offset)
103
+ </code ></pre >
104
+ is `true`.</p >
105
+ <p >-9- <i >Effects</i >: Equivalent to:
106
+ <pre ><code > return span< ElementType, <i >see below</i >> (
107
+ data() + Offset, Count != dynamic_extent ? Count : size() - Offset);
108
+ </code ></pre >
40
109
</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< element_type, dynamic_extent> first(size_type count) const;
121
+ </code ></pre >
122
+ <blockquote >
123
+ <p >-11- <i >Hardened preconditions</i >: <code >count < = 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< element_type, dynamic_extent> last(size_type count) const;
132
+ </code ></pre >
133
+ <blockquote >
134
+ <p >-13- <i >Hardened preconditions</i >: <code >count < = 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< element_type, dynamic_extent> 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 < = size() && (count == dynamic_extent || count < = 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
+
41
161
</resolution >
42
162
43
163
</issue >
0 commit comments