From Jason Turner

[views.contiguous]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzhv4nd60/{from.md → to.md} +86 -38
tmp/tmpzhv4nd60/{from.md → to.md} RENAMED
@@ -1,22 +1,39 @@
1
  ### Contiguous access <a id="views.contiguous">[[views.contiguous]]</a>
2
 
3
  #### Header `<span>` synopsis <a id="span.syn">[[span.syn]]</a>
4
 
5
  ``` cpp
 
 
 
6
  namespace std {
7
  // constants
8
  inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  // [views.span], class template span
11
  template<class ElementType, size_t Extent = dynamic_extent>
12
- class span;
13
 
14
  template<class ElementType, size_t Extent>
15
- constexpr bool ranges::enable_view<span<ElementType, Extent>> = true;
16
  template<class ElementType, size_t Extent>
17
- constexpr bool ranges::enable_borrowed_range<span<ElementType, Extent>> = true;
18
 
19
  // [span.objectrep], views of object representation
20
  template<class ElementType, size_t Extent>
21
  span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
22
  as_bytes(span<ElementType, Extent> s) noexcept;
@@ -68,16 +85,15 @@ namespace std {
68
  constexpr span(array<T, N>& arr) noexcept;
69
  template<class T, size_t N>
70
  constexpr span(const array<T, N>& arr) noexcept;
71
  template<class R>
72
  constexpr explicit(extent != dynamic_extent) span(R&& r);
 
73
  constexpr span(const span& other) noexcept = default;
74
  template<class OtherElementType, size_t OtherExtent>
75
  constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
76
 
77
- ~span() noexcept = default;
78
-
79
  constexpr span& operator=(const span& other) noexcept = default;
80
 
81
  // [span.sub], subviews
82
  template<size_t Count>
83
  constexpr span<element_type, Count> first() const;
@@ -92,14 +108,15 @@ namespace std {
92
  size_type offset, size_type count = dynamic_extent) const;
93
 
94
  // [span.obs], observers
95
  constexpr size_type size() const noexcept;
96
  constexpr size_type size_bytes() const noexcept;
97
- [[nodiscard]] constexpr bool empty() const noexcept;
98
 
99
  // [span.elem], element access
100
  constexpr reference operator[](size_type idx) const;
 
101
  constexpr reference front() const;
102
  constexpr reference back() const;
103
  constexpr pointer data() const noexcept;
104
 
105
  // [span.iterators], iterator support
@@ -116,11 +133,12 @@ namespace std {
116
  pointer data_; // exposition only
117
  size_type size_; // exposition only
118
  };
119
 
120
  template<class It, class EndOrSize>
121
- span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
 
122
  template<class T, size_t N>
123
  span(T (&)[N]) -> span<T, N>;
124
  template<class T, size_t N>
125
  span(array<T, N>&) -> span<T, N>;
126
  template<class T, size_t N>
@@ -134,10 +152,14 @@ namespace std {
134
  [[term.trivially.copyable.type]].
135
 
136
  `ElementType` is required to be a complete object type that is not an
137
  abstract class type.
138
 
 
 
 
 
139
  ##### Constructors, copy, and assignment <a id="span.cons">[[span.cons]]</a>
140
 
141
  ``` cpp
142
  constexpr span() noexcept;
143
  ```
@@ -160,14 +182,15 @@ template<class It>
160
 
161
  *Preconditions:*
162
 
163
  - \[`first`, `first + count`) is a valid range.
164
  - `It` models `contiguous_iterator`.
165
- - If `extent` is not equal to `dynamic_extent`, then `count` is equal to
166
- `extent`.
167
 
168
- *Effects:* Initializes *`data_`* with `to_address(first)` and *`size_`*
 
 
 
169
  with `count`.
170
 
171
  *Throws:* Nothing.
172
 
173
  ``` cpp
@@ -184,28 +207,29 @@ template<class It, class End>
184
  - `End` satisfies `sized_sentinel_for<It>`.
185
  - `is_convertible_v<End, size_t>` is `false`.
186
 
187
  *Preconditions:*
188
 
189
- - If `extent` is not equal to `dynamic_extent`, then `last - first` is
190
- equal to `extent`.
191
  - \[`first`, `last`) is a valid range.
192
  - `It` models `contiguous_iterator`.
193
  - `End` models `sized_sentinel_for<It>`.
194
 
195
- *Effects:* Initializes *`data_`* with `to_address(first)` and *`size_`*
 
 
 
196
  with `last - first`.
197
 
198
  *Throws:* When and what `last - first` throws.
199
 
200
  ``` cpp
201
  template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
202
  template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept;
203
  template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
204
  ```
205
 
206
- *Constraints:* Let `U` be `remove_pointer_t<decltype(data(arr))>`.
207
 
208
  - `extent == dynamic_extent || N == extent` is `true`, and
209
  - `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
210
  \[*Note 3*: The intent is to allow only qualification conversions of
211
  the array element type to `element_type`. — *end note*]
@@ -213,11 +237,11 @@ template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
213
  *Effects:* Constructs a `span` that is a view over the supplied array.
214
 
215
  [*Note 1*: `type_identity_t` affects class template argument
216
  deduction. — *end note*]
217
 
218
- *Ensures:* `size() == N && data() == data(arr)` is `true`.
219
 
220
  ``` cpp
221
  template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
222
  ```
223
 
@@ -234,21 +258,34 @@ template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
234
  \[*Note 4*: The intent is to allow only qualification conversions of
235
  the range reference type to `element_type`. — *end note*]
236
 
237
  *Preconditions:*
238
 
239
- - If `extent` is not equal to `dynamic_extent`, then `ranges::size(r)`
240
- is equal to `extent`.
241
  - `R` models `ranges::contiguous_range` and `ranges::sized_range`.
242
  - If `is_const_v<element_type>` is `false`, `R` models
243
  `ranges::borrowed_range`.
244
 
245
- *Effects:* Initializes *`data_`* with `ranges::data(r)` and *`size_`*
246
- with `ranges::size(r)`.
 
 
 
247
 
248
  *Throws:* What and when `ranges::data(r)` and `ranges::size(r)` throw.
249
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  ``` cpp
251
  constexpr span(const span& other) noexcept = default;
252
  ```
253
 
254
  *Ensures:* `other.size() == size() && other.data() == data()`.
@@ -265,12 +302,12 @@ template<class OtherElementType, size_t OtherExtent>
265
  - `is_convertible_v<OtherElementType(*)[], element_type(*)[]>` is
266
  `true`. \[*Note 5*: The intent is to allow only qualification
267
  conversions of the `OtherElementType` to
268
  `element_type`. — *end note*]
269
 
270
- *Preconditions:* If `extent` is not equal to `dynamic_extent`, then
271
- `s.size()` is equal to `extent`.
272
 
273
  *Effects:* Constructs a `span` that is a view over the range
274
  \[`s.data()`, `s.data() + s.size()`).
275
 
276
  *Ensures:* `size() == s.size() && data() == s.data()`.
@@ -289,11 +326,12 @@ constexpr span& operator=(const span& other) noexcept = default;
289
 
290
  ##### Deduction guides <a id="span.deduct">[[span.deduct]]</a>
291
 
292
  ``` cpp
293
  template<class It, class EndOrSize>
294
- span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
 
295
  ```
296
 
297
  *Constraints:* `It` satisfies `contiguous_iterator`.
298
 
299
  ``` cpp
@@ -309,22 +347,22 @@ template<class R>
309
  template<size_t Count> constexpr span<element_type, Count> first() const;
310
  ```
311
 
312
  *Mandates:* `Count <= Extent` is `true`.
313
 
314
- *Preconditions:* `Count <= size()` is `true`.
315
 
316
  *Effects:* Equivalent to: `return R{data(), Count};` where `R` is the
317
  return type.
318
 
319
  ``` cpp
320
  template<size_t Count> constexpr span<element_type, Count> last() const;
321
  ```
322
 
323
  *Mandates:* `Count <= Extent` is `true`.
324
 
325
- *Preconditions:* `Count <= size()` is `true`.
326
 
327
  *Effects:* Equivalent to: `return R{data() + (size() - Count), Count};`
328
  where `R` is the return type.
329
 
330
  ``` cpp
@@ -338,12 +376,10 @@ template<size_t Offset, size_t Count = dynamic_extent>
338
  Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset)
339
  ```
340
 
341
  is `true`.
342
 
343
- *Preconditions:*
344
-
345
  ``` cpp
346
  Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
347
  ```
348
 
349
  is `true`.
@@ -365,29 +401,27 @@ Count != dynamic_extent ? Count
365
 
366
  ``` cpp
367
  constexpr span<element_type, dynamic_extent> first(size_type count) const;
368
  ```
369
 
370
- *Preconditions:* `count <= size()` is `true`.
371
 
372
  *Effects:* Equivalent to: `return {data(), count};`
373
 
374
  ``` cpp
375
  constexpr span<element_type, dynamic_extent> last(size_type count) const;
376
  ```
377
 
378
- *Preconditions:* `count <= size()` is `true`.
379
 
380
  *Effects:* Equivalent to: `return {data() + (size() - count), count};`
381
 
382
  ``` cpp
383
  constexpr span<element_type, dynamic_extent> subspan(
384
  size_type offset, size_type count = dynamic_extent) const;
385
  ```
386
 
387
- *Preconditions:*
388
-
389
  ``` cpp
390
  offset <= size() && (count == dynamic_extent || count <= size() - offset)
391
  ```
392
 
393
  is `true`.
@@ -411,46 +445,60 @@ constexpr size_type size_bytes() const noexcept;
411
  ```
412
 
413
  *Effects:* Equivalent to: `return size() * sizeof(element_type);`
414
 
415
  ``` cpp
416
- [[nodiscard]] constexpr bool empty() const noexcept;
417
  ```
418
 
419
  *Effects:* Equivalent to: `return size() == 0;`
420
 
421
  ##### Element access <a id="span.elem">[[span.elem]]</a>
422
 
423
  ``` cpp
424
  constexpr reference operator[](size_type idx) const;
425
  ```
426
 
427
- *Preconditions:* `idx < size()` is `true`.
428
 
429
- *Effects:* Equivalent to: `return *(data() + idx);`
 
 
 
 
 
 
 
 
 
 
430
 
431
  ``` cpp
432
  constexpr reference front() const;
433
  ```
434
 
435
- *Preconditions:* `empty()` is `false`.
436
 
437
- *Effects:* Equivalent to: `return *data();`
 
 
438
 
439
  ``` cpp
440
  constexpr reference back() const;
441
  ```
442
 
443
- *Preconditions:* `empty()` is `false`.
444
 
445
- *Effects:* Equivalent to: `return *(data() + (size() - 1));`
 
 
446
 
447
  ``` cpp
448
  constexpr pointer data() const noexcept;
449
  ```
450
 
451
- *Effects:* Equivalent to: `return `*`data_`*`;`
452
 
453
  ##### Iterator support <a id="span.iterators">[[span.iterators]]</a>
454
 
455
  ``` cpp
456
  using iterator = implementation-defined // type of span::iterator;
 
1
  ### Contiguous access <a id="views.contiguous">[[views.contiguous]]</a>
2
 
3
  #### Header `<span>` synopsis <a id="span.syn">[[span.syn]]</a>
4
 
5
  ``` cpp
6
+ #include <initializer_list> // see [initializer.list.syn]
7
+
8
+ // mostly freestanding
9
  namespace std {
10
  // constants
11
  inline constexpr size_t dynamic_extent = numeric_limits<size_t>::max();
12
 
13
+ template<class T>
14
+ concept integral-constant-like = // exposition only
15
+ is_integral_v<remove_cvref_t<decltype(T::value)>> &&
16
+ !is_same_v<bool, remove_const_t<decltype(T::value)>> &&
17
+ convertible_to<T, decltype(T::value)> &&
18
+ equality_comparable_with<T, decltype(T::value)> &&
19
+ bool_constant<T() == T::value>::value &&
20
+ bool_constant<static_cast<decltype(T::value)>(T()) == T::value>::value;
21
+
22
+ template<class T>
23
+ constexpr size_t maybe-static-ext = dynamic_extent; // exposition only
24
+ template<integral-constant-like T>
25
+ constexpr size_t maybe-static-ext<T> = {T::value};
26
+
27
  // [views.span], class template span
28
  template<class ElementType, size_t Extent = dynamic_extent>
29
+ class span; // partially freestanding
30
 
31
  template<class ElementType, size_t Extent>
32
+ constexpr bool ranges::\libspec{enable_view}{span}<span<ElementType, Extent>> = true;
33
  template<class ElementType, size_t Extent>
34
+ constexpr bool ranges::\libspec{enable_borrowed_range}{span}<span<ElementType, Extent>> = true;
35
 
36
  // [span.objectrep], views of object representation
37
  template<class ElementType, size_t Extent>
38
  span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
39
  as_bytes(span<ElementType, Extent> s) noexcept;
 
85
  constexpr span(array<T, N>& arr) noexcept;
86
  template<class T, size_t N>
87
  constexpr span(const array<T, N>& arr) noexcept;
88
  template<class R>
89
  constexpr explicit(extent != dynamic_extent) span(R&& r);
90
+ constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
91
  constexpr span(const span& other) noexcept = default;
92
  template<class OtherElementType, size_t OtherExtent>
93
  constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
94
 
 
 
95
  constexpr span& operator=(const span& other) noexcept = default;
96
 
97
  // [span.sub], subviews
98
  template<size_t Count>
99
  constexpr span<element_type, Count> first() const;
 
108
  size_type offset, size_type count = dynamic_extent) const;
109
 
110
  // [span.obs], observers
111
  constexpr size_type size() const noexcept;
112
  constexpr size_type size_bytes() const noexcept;
113
+ constexpr bool empty() const noexcept;
114
 
115
  // [span.elem], element access
116
  constexpr reference operator[](size_type idx) const;
117
+ constexpr reference at(size_type idx) const; // freestanding-deleted
118
  constexpr reference front() const;
119
  constexpr reference back() const;
120
  constexpr pointer data() const noexcept;
121
 
122
  // [span.iterators], iterator support
 
133
  pointer data_; // exposition only
134
  size_type size_; // exposition only
135
  };
136
 
137
  template<class It, class EndOrSize>
138
+ span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>,
139
+ maybe-static-ext<EndOrSize>>;
140
  template<class T, size_t N>
141
  span(T (&)[N]) -> span<T, N>;
142
  template<class T, size_t N>
143
  span(array<T, N>&) -> span<T, N>;
144
  template<class T, size_t N>
 
152
  [[term.trivially.copyable.type]].
153
 
154
  `ElementType` is required to be a complete object type that is not an
155
  abstract class type.
156
 
157
+ For a `span` `s`, any operation that invalidates a pointer in the range
158
+ \[`s.data()`, `s.data() + s.size()`) invalidates pointers, iterators,
159
+ and references to elements of `s`.
160
+
161
  ##### Constructors, copy, and assignment <a id="span.cons">[[span.cons]]</a>
162
 
163
  ``` cpp
164
  constexpr span() noexcept;
165
  ```
 
182
 
183
  *Preconditions:*
184
 
185
  - \[`first`, `first + count`) is a valid range.
186
  - `It` models `contiguous_iterator`.
 
 
187
 
188
+ If `extent` is not equal to `dynamic_extent`, then `count == extent` is
189
+ `true`.
190
+
191
+ *Effects:* Initializes *data\_* with `to_address(first)` and *size\_*
192
  with `count`.
193
 
194
  *Throws:* Nothing.
195
 
196
  ``` cpp
 
207
  - `End` satisfies `sized_sentinel_for<It>`.
208
  - `is_convertible_v<End, size_t>` is `false`.
209
 
210
  *Preconditions:*
211
 
 
 
212
  - \[`first`, `last`) is a valid range.
213
  - `It` models `contiguous_iterator`.
214
  - `End` models `sized_sentinel_for<It>`.
215
 
216
+ If `extent` is not equal to `dynamic_extent`, then
217
+ `(last - first) == extent` is `true`.
218
+
219
+ *Effects:* Initializes *data\_* with `to_address(first)` and *size\_*
220
  with `last - first`.
221
 
222
  *Throws:* When and what `last - first` throws.
223
 
224
  ``` cpp
225
  template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
226
  template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept;
227
  template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
228
  ```
229
 
230
+ *Constraints:* Let `U` be `remove_pointer_t<decltype(std::data(arr))>`.
231
 
232
  - `extent == dynamic_extent || N == extent` is `true`, and
233
  - `is_convertible_v<U(*)[], element_type(*)[]>` is `true`.
234
  \[*Note 3*: The intent is to allow only qualification conversions of
235
  the array element type to `element_type`. — *end note*]
 
237
  *Effects:* Constructs a `span` that is a view over the supplied array.
238
 
239
  [*Note 1*: `type_identity_t` affects class template argument
240
  deduction. — *end note*]
241
 
242
+ *Ensures:* `size() == N && data() == std::data(arr)` is `true`.
243
 
244
  ``` cpp
245
  template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
246
  ```
247
 
 
258
  \[*Note 4*: The intent is to allow only qualification conversions of
259
  the range reference type to `element_type`. — *end note*]
260
 
261
  *Preconditions:*
262
 
 
 
263
  - `R` models `ranges::contiguous_range` and `ranges::sized_range`.
264
  - If `is_const_v<element_type>` is `false`, `R` models
265
  `ranges::borrowed_range`.
266
 
267
+ If `extent` is not equal to `dynamic_extent`, then
268
+ `ranges::size(r) == extent` is `true`.
269
+
270
+ *Effects:* Initializes *data\_* with `ranges::data(r)` and *size\_* with
271
+ `ranges::size(r)`.
272
 
273
  *Throws:* What and when `ranges::data(r)` and `ranges::size(r)` throw.
274
 
275
+ ``` cpp
276
+ constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
277
+ ```
278
+
279
+ *Constraints:* `is_const_v<element_type>` is `true`.
280
+
281
+ If `extent` is not equal to `dynamic_extent`, then `il.size() == extent`
282
+ is `true`.
283
+
284
+ *Effects:* Initializes *data\_* with `il.begin()` and *size\_* with
285
+ `il.size()`.
286
+
287
  ``` cpp
288
  constexpr span(const span& other) noexcept = default;
289
  ```
290
 
291
  *Ensures:* `other.size() == size() && other.data() == data()`.
 
302
  - `is_convertible_v<OtherElementType(*)[], element_type(*)[]>` is
303
  `true`. \[*Note 5*: The intent is to allow only qualification
304
  conversions of the `OtherElementType` to
305
  `element_type`. — *end note*]
306
 
307
+ If `extent` is not equal to `dynamic_extent`, then `s.size() == extent`
308
+ is `true`.
309
 
310
  *Effects:* Constructs a `span` that is a view over the range
311
  \[`s.data()`, `s.data() + s.size()`).
312
 
313
  *Ensures:* `size() == s.size() && data() == s.data()`.
 
326
 
327
  ##### Deduction guides <a id="span.deduct">[[span.deduct]]</a>
328
 
329
  ``` cpp
330
  template<class It, class EndOrSize>
331
+ span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>,
332
+ maybe-static-ext<EndOrSize>>;
333
  ```
334
 
335
  *Constraints:* `It` satisfies `contiguous_iterator`.
336
 
337
  ``` cpp
 
347
  template<size_t Count> constexpr span<element_type, Count> first() const;
348
  ```
349
 
350
  *Mandates:* `Count <= Extent` is `true`.
351
 
352
+ `Count <= size()` is `true`.
353
 
354
  *Effects:* Equivalent to: `return R{data(), Count};` where `R` is the
355
  return type.
356
 
357
  ``` cpp
358
  template<size_t Count> constexpr span<element_type, Count> last() const;
359
  ```
360
 
361
  *Mandates:* `Count <= Extent` is `true`.
362
 
363
+ `Count <= size()` is `true`.
364
 
365
  *Effects:* Equivalent to: `return R{data() + (size() - Count), Count};`
366
  where `R` is the return type.
367
 
368
  ``` cpp
 
376
  Offset <= Extent && (Count == dynamic_extent || Count <= Extent - Offset)
377
  ```
378
 
379
  is `true`.
380
 
 
 
381
  ``` cpp
382
  Offset <= size() && (Count == dynamic_extent || Count <= size() - Offset)
383
  ```
384
 
385
  is `true`.
 
401
 
402
  ``` cpp
403
  constexpr span<element_type, dynamic_extent> first(size_type count) const;
404
  ```
405
 
406
+ `count <= size()` is `true`.
407
 
408
  *Effects:* Equivalent to: `return {data(), count};`
409
 
410
  ``` cpp
411
  constexpr span<element_type, dynamic_extent> last(size_type count) const;
412
  ```
413
 
414
+ `count <= size()` is `true`.
415
 
416
  *Effects:* Equivalent to: `return {data() + (size() - count), count};`
417
 
418
  ``` cpp
419
  constexpr span<element_type, dynamic_extent> subspan(
420
  size_type offset, size_type count = dynamic_extent) const;
421
  ```
422
 
 
 
423
  ``` cpp
424
  offset <= size() && (count == dynamic_extent || count <= size() - offset)
425
  ```
426
 
427
  is `true`.
 
445
  ```
446
 
447
  *Effects:* Equivalent to: `return size() * sizeof(element_type);`
448
 
449
  ``` cpp
450
+ constexpr bool empty() const noexcept;
451
  ```
452
 
453
  *Effects:* Equivalent to: `return size() == 0;`
454
 
455
  ##### Element access <a id="span.elem">[[span.elem]]</a>
456
 
457
  ``` cpp
458
  constexpr reference operator[](size_type idx) const;
459
  ```
460
 
461
+ `idx < size()` is `true`.
462
 
463
+ *Returns:* `*(data() + idx)`.
464
+
465
+ *Throws:* Nothing.
466
+
467
+ ``` cpp
468
+ constexpr reference at(size_type idx) const;
469
+ ```
470
+
471
+ *Returns:* `*(data() + idx)`.
472
+
473
+ *Throws:* `out_of_range` if `idx >= size()` is `true`.
474
 
475
  ``` cpp
476
  constexpr reference front() const;
477
  ```
478
 
479
+ `empty()` is `false`.
480
 
481
+ *Returns:* `*data()`.
482
+
483
+ *Throws:* Nothing.
484
 
485
  ``` cpp
486
  constexpr reference back() const;
487
  ```
488
 
489
+ `empty()` is `false`.
490
 
491
+ *Returns:* `*(data() + (size() - 1))`.
492
+
493
+ *Throws:* Nothing.
494
 
495
  ``` cpp
496
  constexpr pointer data() const noexcept;
497
  ```
498
 
499
+ *Returns:* *data\_*.
500
 
501
  ##### Iterator support <a id="span.iterators">[[span.iterators]]</a>
502
 
503
  ``` cpp
504
  using iterator = implementation-defined // type of span::iterator;