From Jason Turner

[views.span]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp41sf74h6/{from.md → to.md} +66 -35
tmp/tmp41sf74h6/{from.md → to.md} RENAMED
@@ -39,16 +39,15 @@ namespace std {
39
  constexpr span(array<T, N>& arr) noexcept;
40
  template<class T, size_t N>
41
  constexpr span(const array<T, N>& arr) noexcept;
42
  template<class R>
43
  constexpr explicit(extent != dynamic_extent) span(R&& r);
 
44
  constexpr span(const span& other) noexcept = default;
45
  template<class OtherElementType, size_t OtherExtent>
46
  constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
47
 
48
- ~span() noexcept = default;
49
-
50
  constexpr span& operator=(const span& other) noexcept = default;
51
 
52
  // [span.sub], subviews
53
  template<size_t Count>
54
  constexpr span<element_type, Count> first() const;
@@ -63,14 +62,15 @@ namespace std {
63
  size_type offset, size_type count = dynamic_extent) const;
64
 
65
  // [span.obs], observers
66
  constexpr size_type size() const noexcept;
67
  constexpr size_type size_bytes() const noexcept;
68
- [[nodiscard]] constexpr bool empty() const noexcept;
69
 
70
  // [span.elem], element access
71
  constexpr reference operator[](size_type idx) const;
 
72
  constexpr reference front() const;
73
  constexpr reference back() const;
74
  constexpr pointer data() const noexcept;
75
 
76
  // [span.iterators], iterator support
@@ -87,11 +87,12 @@ namespace std {
87
  pointer data_; // exposition only
88
  size_type size_; // exposition only
89
  };
90
 
91
  template<class It, class EndOrSize>
92
- span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
 
93
  template<class T, size_t N>
94
  span(T (&)[N]) -> span<T, N>;
95
  template<class T, size_t N>
96
  span(array<T, N>&) -> span<T, N>;
97
  template<class T, size_t N>
@@ -105,10 +106,14 @@ namespace std {
105
  [[term.trivially.copyable.type]].
106
 
107
  `ElementType` is required to be a complete object type that is not an
108
  abstract class type.
109
 
 
 
 
 
110
  ##### Constructors, copy, and assignment <a id="span.cons">[[span.cons]]</a>
111
 
112
  ``` cpp
113
  constexpr span() noexcept;
114
  ```
@@ -131,14 +136,15 @@ template<class It>
131
 
132
  *Preconditions:*
133
 
134
  - \[`first`, `first + count`) is a valid range.
135
  - `It` models `contiguous_iterator`.
136
- - If `extent` is not equal to `dynamic_extent`, then `count` is equal to
137
- `extent`.
138
 
139
- *Effects:* Initializes *`data_`* with `to_address(first)` and *`size_`*
 
 
 
140
  with `count`.
141
 
142
  *Throws:* Nothing.
143
 
144
  ``` cpp
@@ -155,28 +161,29 @@ template<class It, class End>
155
  - `End` satisfies `sized_sentinel_for<It>`.
156
  - `is_convertible_v<End, size_t>` is `false`.
157
 
158
  *Preconditions:*
159
 
160
- - If `extent` is not equal to `dynamic_extent`, then `last - first` is
161
- equal to `extent`.
162
  - \[`first`, `last`) is a valid range.
163
  - `It` models `contiguous_iterator`.
164
  - `End` models `sized_sentinel_for<It>`.
165
 
166
- *Effects:* Initializes *`data_`* with `to_address(first)` and *`size_`*
 
 
 
167
  with `last - first`.
168
 
169
  *Throws:* When and what `last - first` throws.
170
 
171
  ``` cpp
172
  template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
173
  template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept;
174
  template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
175
  ```
176
 
177
- *Constraints:* Let `U` be `remove_pointer_t<decltype(data(arr))>`.
178
 
179
  - `extent == dynamic_extent || N == extent` is `true`, and
180
  - `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
181
  \[*Note 3*: The intent is to allow only qualification conversions of
182
  the array element type to `element_type`. — *end note*]
@@ -184,11 +191,11 @@ template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
184
  *Effects:* Constructs a `span` that is a view over the supplied array.
185
 
186
  [*Note 1*: `type_identity_t` affects class template argument
187
  deduction. — *end note*]
188
 
189
- *Ensures:* `size() == N && data() == data(arr)` is `true`.
190
 
191
  ``` cpp
192
  template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
193
  ```
194
 
@@ -205,21 +212,34 @@ template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
205
  \[*Note 4*: The intent is to allow only qualification conversions of
206
  the range reference type to `element_type`. — *end note*]
207
 
208
  *Preconditions:*
209
 
210
- - If `extent` is not equal to `dynamic_extent`, then `ranges::size(r)`
211
- is equal to `extent`.
212
  - `R` models `ranges::contiguous_range` and `ranges::sized_range`.
213
  - If `is_const_v<element_type>` is `false`, `R` models
214
  `ranges::borrowed_range`.
215
 
216
- *Effects:* Initializes *`data_`* with `ranges::data(r)` and *`size_`*
217
- with `ranges::size(r)`.
 
 
 
218
 
219
  *Throws:* What and when `ranges::data(r)` and `ranges::size(r)` throw.
220
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  ``` cpp
222
  constexpr span(const span& other) noexcept = default;
223
  ```
224
 
225
  *Ensures:* `other.size() == size() && other.data() == data()`.
@@ -236,12 +256,12 @@ template<class OtherElementType, size_t OtherExtent>
236
  - `is_convertible_v<OtherElementType(*)[], element_type(*)[]>` is
237
  `true`. \[*Note 5*: The intent is to allow only qualification
238
  conversions of the `OtherElementType` to
239
  `element_type`. — *end note*]
240
 
241
- *Preconditions:* If `extent` is not equal to `dynamic_extent`, then
242
- `s.size()` is equal to `extent`.
243
 
244
  *Effects:* Constructs a `span` that is a view over the range
245
  \[`s.data()`, `s.data() + s.size()`).
246
 
247
  *Ensures:* `size() == s.size() && data() == s.data()`.
@@ -260,11 +280,12 @@ constexpr span& operator=(const span& other) noexcept = default;
260
 
261
  ##### Deduction guides <a id="span.deduct">[[span.deduct]]</a>
262
 
263
  ``` cpp
264
  template<class It, class EndOrSize>
265
- span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
 
266
  ```
267
 
268
  *Constraints:* `It` satisfies `contiguous_iterator`.
269
 
270
  ``` cpp
@@ -280,22 +301,22 @@ template<class R>
280
  template<size_t Count> constexpr span<element_type, Count> first() const;
281
  ```
282
 
283
  *Mandates:* `Count <= Extent` is `true`.
284
 
285
- *Preconditions:* `Count <= size()` is `true`.
286
 
287
  *Effects:* Equivalent to: `return R{data(), Count};` where `R` is the
288
  return type.
289
 
290
  ``` cpp
291
  template<size_t Count> constexpr span<element_type, Count> last() const;
292
  ```
293
 
294
  *Mandates:* `Count <= Extent` is `true`.
295
 
296
- *Preconditions:* `Count <= size()` is `true`.
297
 
298
  *Effects:* Equivalent to: `return R{data() + (size() - Count), Count};`
299
  where `R` is the return type.
300
 
301
  ``` cpp
@@ -309,12 +330,10 @@ template<size_t Offset, size_t Count = dynamic_extent>
309
  Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset)
310
  ```
311
 
312
  is `true`.
313
 
314
- *Preconditions:*
315
-
316
  ``` cpp
317
  Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
318
  ```
319
 
320
  is `true`.
@@ -336,29 +355,27 @@ Count != dynamic_extent ? Count
336
 
337
  ``` cpp
338
  constexpr span<element_type, dynamic_extent> first(size_type count) const;
339
  ```
340
 
341
- *Preconditions:* `count <= size()` is `true`.
342
 
343
  *Effects:* Equivalent to: `return {data(), count};`
344
 
345
  ``` cpp
346
  constexpr span<element_type, dynamic_extent> last(size_type count) const;
347
  ```
348
 
349
- *Preconditions:* `count <= size()` is `true`.
350
 
351
  *Effects:* Equivalent to: `return {data() + (size() - count), count};`
352
 
353
  ``` cpp
354
  constexpr span<element_type, dynamic_extent> subspan(
355
  size_type offset, size_type count = dynamic_extent) const;
356
  ```
357
 
358
- *Preconditions:*
359
-
360
  ``` cpp
361
  offset <= size() && (count == dynamic_extent || count <= size() - offset)
362
  ```
363
 
364
  is `true`.
@@ -382,46 +399,60 @@ constexpr size_type size_bytes() const noexcept;
382
  ```
383
 
384
  *Effects:* Equivalent to: `return size() * sizeof(element_type);`
385
 
386
  ``` cpp
387
- [[nodiscard]] constexpr bool empty() const noexcept;
388
  ```
389
 
390
  *Effects:* Equivalent to: `return size() == 0;`
391
 
392
  ##### Element access <a id="span.elem">[[span.elem]]</a>
393
 
394
  ``` cpp
395
  constexpr reference operator[](size_type idx) const;
396
  ```
397
 
398
- *Preconditions:* `idx < size()` is `true`.
399
 
400
- *Effects:* Equivalent to: `return *(data() + idx);`
 
 
 
 
 
 
 
 
 
 
401
 
402
  ``` cpp
403
  constexpr reference front() const;
404
  ```
405
 
406
- *Preconditions:* `empty()` is `false`.
407
 
408
- *Effects:* Equivalent to: `return *data();`
 
 
409
 
410
  ``` cpp
411
  constexpr reference back() const;
412
  ```
413
 
414
- *Preconditions:* `empty()` is `false`.
415
 
416
- *Effects:* Equivalent to: `return *(data() + (size() - 1));`
 
 
417
 
418
  ``` cpp
419
  constexpr pointer data() const noexcept;
420
  ```
421
 
422
- *Effects:* Equivalent to: `return `*`data_`*`;`
423
 
424
  ##### Iterator support <a id="span.iterators">[[span.iterators]]</a>
425
 
426
  ``` cpp
427
  using iterator = implementation-defined // type of span::iterator;
 
39
  constexpr span(array<T, N>& arr) noexcept;
40
  template<class T, size_t N>
41
  constexpr span(const array<T, N>& arr) noexcept;
42
  template<class R>
43
  constexpr explicit(extent != dynamic_extent) span(R&& r);
44
+ constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
45
  constexpr span(const span& other) noexcept = default;
46
  template<class OtherElementType, size_t OtherExtent>
47
  constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
48
 
 
 
49
  constexpr span& operator=(const span& other) noexcept = default;
50
 
51
  // [span.sub], subviews
52
  template<size_t Count>
53
  constexpr span<element_type, Count> first() const;
 
62
  size_type offset, size_type count = dynamic_extent) const;
63
 
64
  // [span.obs], observers
65
  constexpr size_type size() const noexcept;
66
  constexpr size_type size_bytes() const noexcept;
67
+ constexpr bool empty() const noexcept;
68
 
69
  // [span.elem], element access
70
  constexpr reference operator[](size_type idx) const;
71
+ constexpr reference at(size_type idx) const; // freestanding-deleted
72
  constexpr reference front() const;
73
  constexpr reference back() const;
74
  constexpr pointer data() const noexcept;
75
 
76
  // [span.iterators], iterator support
 
87
  pointer data_; // exposition only
88
  size_type size_; // exposition only
89
  };
90
 
91
  template<class It, class EndOrSize>
92
+ span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>,
93
+ maybe-static-ext<EndOrSize>>;
94
  template<class T, size_t N>
95
  span(T (&)[N]) -> span<T, N>;
96
  template<class T, size_t N>
97
  span(array<T, N>&) -> span<T, N>;
98
  template<class T, size_t N>
 
106
  [[term.trivially.copyable.type]].
107
 
108
  `ElementType` is required to be a complete object type that is not an
109
  abstract class type.
110
 
111
+ For a `span` `s`, any operation that invalidates a pointer in the range
112
+ \[`s.data()`, `s.data() + s.size()`) invalidates pointers, iterators,
113
+ and references to elements of `s`.
114
+
115
  ##### Constructors, copy, and assignment <a id="span.cons">[[span.cons]]</a>
116
 
117
  ``` cpp
118
  constexpr span() noexcept;
119
  ```
 
136
 
137
  *Preconditions:*
138
 
139
  - \[`first`, `first + count`) is a valid range.
140
  - `It` models `contiguous_iterator`.
 
 
141
 
142
+ If `extent` is not equal to `dynamic_extent`, then `count == extent` is
143
+ `true`.
144
+
145
+ *Effects:* Initializes *data\_* with `to_address(first)` and *size\_*
146
  with `count`.
147
 
148
  *Throws:* Nothing.
149
 
150
  ``` cpp
 
161
  - `End` satisfies `sized_sentinel_for<It>`.
162
  - `is_convertible_v<End, size_t>` is `false`.
163
 
164
  *Preconditions:*
165
 
 
 
166
  - \[`first`, `last`) is a valid range.
167
  - `It` models `contiguous_iterator`.
168
  - `End` models `sized_sentinel_for<It>`.
169
 
170
+ If `extent` is not equal to `dynamic_extent`, then
171
+ `(last - first) == extent` is `true`.
172
+
173
+ *Effects:* Initializes *data\_* with `to_address(first)` and *size\_*
174
  with `last - first`.
175
 
176
  *Throws:* When and what `last - first` throws.
177
 
178
  ``` cpp
179
  template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
180
  template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept;
181
  template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
182
  ```
183
 
184
+ *Constraints:* Let `U` be `remove_pointer_t<decltype(std::data(arr))>`.
185
 
186
  - `extent == dynamic_extent || N == extent` is `true`, and
187
  - `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
188
  \[*Note 3*: The intent is to allow only qualification conversions of
189
  the array element type to `element_type`. — *end note*]
 
191
  *Effects:* Constructs a `span` that is a view over the supplied array.
192
 
193
  [*Note 1*: `type_identity_t` affects class template argument
194
  deduction. — *end note*]
195
 
196
+ *Ensures:* `size() == N && data() == std::data(arr)` is `true`.
197
 
198
  ``` cpp
199
  template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
200
  ```
201
 
 
212
  \[*Note 4*: The intent is to allow only qualification conversions of
213
  the range reference type to `element_type`. — *end note*]
214
 
215
  *Preconditions:*
216
 
 
 
217
  - `R` models `ranges::contiguous_range` and `ranges::sized_range`.
218
  - If `is_const_v<element_type>` is `false`, `R` models
219
  `ranges::borrowed_range`.
220
 
221
+ If `extent` is not equal to `dynamic_extent`, then
222
+ `ranges::size(r) == extent` is `true`.
223
+
224
+ *Effects:* Initializes *data\_* with `ranges::data(r)` and *size\_* with
225
+ `ranges::size(r)`.
226
 
227
  *Throws:* What and when `ranges::data(r)` and `ranges::size(r)` throw.
228
 
229
+ ``` cpp
230
+ constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
231
+ ```
232
+
233
+ *Constraints:* `is_const_v<element_type>` is `true`.
234
+
235
+ If `extent` is not equal to `dynamic_extent`, then `il.size() == extent`
236
+ is `true`.
237
+
238
+ *Effects:* Initializes *data\_* with `il.begin()` and *size\_* with
239
+ `il.size()`.
240
+
241
  ``` cpp
242
  constexpr span(const span& other) noexcept = default;
243
  ```
244
 
245
  *Ensures:* `other.size() == size() && other.data() == data()`.
 
256
  - `is_convertible_v<OtherElementType(*)[], element_type(*)[]>` is
257
  `true`. \[*Note 5*: The intent is to allow only qualification
258
  conversions of the `OtherElementType` to
259
  `element_type`. — *end note*]
260
 
261
+ If `extent` is not equal to `dynamic_extent`, then `s.size() == extent`
262
+ is `true`.
263
 
264
  *Effects:* Constructs a `span` that is a view over the range
265
  \[`s.data()`, `s.data() + s.size()`).
266
 
267
  *Ensures:* `size() == s.size() && data() == s.data()`.
 
280
 
281
  ##### Deduction guides <a id="span.deduct">[[span.deduct]]</a>
282
 
283
  ``` cpp
284
  template<class It, class EndOrSize>
285
+ span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>,
286
+ maybe-static-ext<EndOrSize>>;
287
  ```
288
 
289
  *Constraints:* `It` satisfies `contiguous_iterator`.
290
 
291
  ``` cpp
 
301
  template<size_t Count> constexpr span<element_type, Count> first() const;
302
  ```
303
 
304
  *Mandates:* `Count <= Extent` is `true`.
305
 
306
+ `Count <= size()` is `true`.
307
 
308
  *Effects:* Equivalent to: `return R{data(), Count};` where `R` is the
309
  return type.
310
 
311
  ``` cpp
312
  template<size_t Count> constexpr span<element_type, Count> last() const;
313
  ```
314
 
315
  *Mandates:* `Count <= Extent` is `true`.
316
 
317
+ `Count <= size()` is `true`.
318
 
319
  *Effects:* Equivalent to: `return R{data() + (size() - Count), Count};`
320
  where `R` is the return type.
321
 
322
  ``` cpp
 
330
  Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset)
331
  ```
332
 
333
  is `true`.
334
 
 
 
335
  ``` cpp
336
  Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
337
  ```
338
 
339
  is `true`.
 
355
 
356
  ``` cpp
357
  constexpr span<element_type, dynamic_extent> first(size_type count) const;
358
  ```
359
 
360
+ `count <= size()` is `true`.
361
 
362
  *Effects:* Equivalent to: `return {data(), count};`
363
 
364
  ``` cpp
365
  constexpr span<element_type, dynamic_extent> last(size_type count) const;
366
  ```
367
 
368
+ `count <= size()` is `true`.
369
 
370
  *Effects:* Equivalent to: `return {data() + (size() - count), count};`
371
 
372
  ``` cpp
373
  constexpr span<element_type, dynamic_extent> subspan(
374
  size_type offset, size_type count = dynamic_extent) const;
375
  ```
376
 
 
 
377
  ``` cpp
378
  offset <= size() && (count == dynamic_extent || count <= size() - offset)
379
  ```
380
 
381
  is `true`.
 
399
  ```
400
 
401
  *Effects:* Equivalent to: `return size() * sizeof(element_type);`
402
 
403
  ``` cpp
404
+ constexpr bool empty() const noexcept;
405
  ```
406
 
407
  *Effects:* Equivalent to: `return size() == 0;`
408
 
409
  ##### Element access <a id="span.elem">[[span.elem]]</a>
410
 
411
  ``` cpp
412
  constexpr reference operator[](size_type idx) const;
413
  ```
414
 
415
+ `idx < size()` is `true`.
416
 
417
+ *Returns:* `*(data() + idx)`.
418
+
419
+ *Throws:* Nothing.
420
+
421
+ ``` cpp
422
+ constexpr reference at(size_type idx) const;
423
+ ```
424
+
425
+ *Returns:* `*(data() + idx)`.
426
+
427
+ *Throws:* `out_of_range` if `idx >= size()` is `true`.
428
 
429
  ``` cpp
430
  constexpr reference front() const;
431
  ```
432
 
433
+ `empty()` is `false`.
434
 
435
+ *Returns:* `*data()`.
436
+
437
+ *Throws:* Nothing.
438
 
439
  ``` cpp
440
  constexpr reference back() const;
441
  ```
442
 
443
+ `empty()` is `false`.
444
 
445
+ *Returns:* `*(data() + (size() - 1))`.
446
+
447
+ *Throws:* Nothing.
448
 
449
  ``` cpp
450
  constexpr pointer data() const noexcept;
451
  ```
452
 
453
+ *Returns:* *data\_*.
454
 
455
  ##### Iterator support <a id="span.iterators">[[span.iterators]]</a>
456
 
457
  ``` cpp
458
  using iterator = implementation-defined // type of span::iterator;