From Jason Turner

[views.span]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpeppxrge3/{from.md → to.md} +29 -235
tmp/tmpeppxrge3/{from.md → to.md} RENAMED
@@ -1,8 +1,8 @@
1
- ### Class template `span` <a id="views.span">[[views.span]]</a>
2
 
3
- #### Overview <a id="span.overview">[[span.overview]]</a>
4
 
5
  A `span` is a view over a contiguous sequence of objects, the storage of
6
  which is owned by some other object.
7
 
8
  All member functions of `span` have constant time complexity.
@@ -20,11 +20,13 @@ namespace std {
20
  using pointer = element_type*;
21
  using const_pointer = const element_type*;
22
  using reference = element_type&;
23
  using const_reference = const element_type&;
24
  using iterator = implementation-defined // type of span::iterator; // see [span.iterators]
 
25
  using reverse_iterator = std::reverse_iterator<iterator>;
 
26
  static constexpr size_type extent = Extent;
27
 
28
  // [span.cons], constructors, copy, and assignment
29
  constexpr span() noexcept;
30
  template<class It>
@@ -72,12 +74,16 @@ namespace std {
72
  constexpr pointer data() const noexcept;
73
 
74
  // [span.iterators], iterator support
75
  constexpr iterator begin() const noexcept;
76
  constexpr iterator end() const noexcept;
 
 
77
  constexpr reverse_iterator rbegin() const noexcept;
78
  constexpr reverse_iterator rend() const noexcept;
 
 
79
 
80
  private:
81
  pointer data_; // exposition only
82
  size_type size_; // exposition only
83
  };
@@ -93,14 +99,17 @@ namespace std {
93
  template<class R>
94
  span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
95
  }
96
  ```
97
 
 
 
 
98
  `ElementType` is required to be a complete object type that is not an
99
  abstract class type.
100
 
101
- #### Constructors, copy, and assignment <a id="span.cons">[[span.cons]]</a>
102
 
103
  ``` cpp
104
  constexpr span() noexcept;
105
  ```
106
 
@@ -125,12 +134,12 @@ template<class It>
125
  - \[`first`, `first + count`) is a valid range.
126
  - `It` models `contiguous_iterator`.
127
  - If `extent` is not equal to `dynamic_extent`, then `count` is equal to
128
  `extent`.
129
 
130
- *Effects:* Initializes `data_` with `to_address(first)` and `size_` with
131
- `count`.
132
 
133
  *Throws:* Nothing.
134
 
135
  ``` cpp
136
  template<class It, class End>
@@ -152,12 +161,12 @@ template<class It, class End>
152
  equal to `extent`.
153
  - \[`first`, `last`) is a valid range.
154
  - `It` models `contiguous_iterator`.
155
  - `End` models `sized_sentinel_for<It>`.
156
 
157
- *Effects:* Initializes `data_` with `to_address(first)` and `size_` with
158
- `last - first`.
159
 
160
  *Throws:* When and what `last - first` throws.
161
 
162
  ``` cpp
163
  template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept;
@@ -202,12 +211,12 @@ template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
202
  is equal to `extent`.
203
  - `R` models `ranges::contiguous_range` and `ranges::sized_range`.
204
  - If `is_const_v<element_type>` is `false`, `R` models
205
  `ranges::borrowed_range`.
206
 
207
- *Effects:* Initializes `data_` with `ranges::data(r)` and `size_` with
208
- `ranges::size(r)`.
209
 
210
  *Throws:* What and when `ranges::data(r)` and `ranges::size(r)` throw.
211
 
212
  ``` cpp
213
  constexpr span(const span& other) noexcept = default;
@@ -247,11 +256,11 @@ extent != dynamic_extent && OtherExtent == dynamic_extent
247
  constexpr span& operator=(const span& other) noexcept = default;
248
  ```
249
 
250
  *Ensures:* `size() == other.size() && data() == other.data()`.
251
 
252
- #### Deduction guides <a id="span.deduct">[[span.deduct]]</a>
253
 
254
  ``` cpp
255
  template<class It, class EndOrSize>
256
  span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>>;
257
  ```
@@ -263,11 +272,11 @@ template<class R>
263
  span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
264
  ```
265
 
266
  *Constraints:* `R` satisfies `ranges::contiguous_range`.
267
 
268
- #### Subviews <a id="span.sub">[[span.sub]]</a>
269
 
270
  ``` cpp
271
  template<size_t Count> constexpr span<element_type, Count> first() const;
272
  ```
273
 
@@ -358,17 +367,17 @@ is `true`.
358
 
359
  ``` cpp
360
  return {data() + offset, count == dynamic_extent ? size() - offset : count};
361
  ```
362
 
363
- #### Observers <a id="span.obs">[[span.obs]]</a>
364
 
365
  ``` cpp
366
  constexpr size_type size() const noexcept;
367
  ```
368
 
369
- *Effects:* Equivalent to: `return size_;`
370
 
371
  ``` cpp
372
  constexpr size_type size_bytes() const noexcept;
373
  ```
374
 
@@ -378,11 +387,11 @@ constexpr size_type size_bytes() const noexcept;
378
  [[nodiscard]] constexpr bool empty() const noexcept;
379
  ```
380
 
381
  *Effects:* Equivalent to: `return size() == 0;`
382
 
383
- #### Element access <a id="span.elem">[[span.elem]]</a>
384
 
385
  ``` cpp
386
  constexpr reference operator[](size_type idx) const;
387
  ```
388
 
@@ -408,23 +417,25 @@ constexpr reference back() const;
408
 
409
  ``` cpp
410
  constexpr pointer data() const noexcept;
411
  ```
412
 
413
- *Effects:* Equivalent to: `return data_;`
414
 
415
- #### Iterator support <a id="span.iterators">[[span.iterators]]</a>
416
 
417
  ``` cpp
418
  using iterator = implementation-defined // type of span::iterator;
419
  ```
420
 
421
  The type models `contiguous_iterator` [[iterator.concept.contiguous]],
422
  meets the *Cpp17RandomAccessIterator*
423
  requirements [[random.access.iterators]], and meets the requirements for
424
- constexpr iterators [[iterator.requirements.general]]. All requirements
425
- on container iterators [[container.requirements]] apply to
 
 
426
  `span::iterator` as well.
427
 
428
  ``` cpp
429
  constexpr iterator begin() const noexcept;
430
  ```
@@ -448,222 +459,5 @@ constexpr reverse_iterator rbegin() const noexcept;
448
  constexpr reverse_iterator rend() const noexcept;
449
  ```
450
 
451
  *Effects:* Equivalent to: `return reverse_iterator(begin());`
452
 
453
- #### Views of object representation <a id="span.objectrep">[[span.objectrep]]</a>
454
-
455
- ``` cpp
456
- template<class ElementType, size_t Extent>
457
- span<const byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
458
- as_bytes(span<ElementType, Extent> s) noexcept;
459
- ```
460
-
461
- *Effects:* Equivalent to:
462
- `return R{reinterpret_cast<const byte*>(s.data()), s.size_bytes()};`
463
- where `R` is the return type.
464
-
465
- ``` cpp
466
- template<class ElementType, size_t Extent>
467
- span<byte, Extent == dynamic_extent ? dynamic_extent : sizeof(ElementType) * Extent>
468
- as_writable_bytes(span<ElementType, Extent> s) noexcept;
469
- ```
470
-
471
- *Constraints:* `is_const_v<ElementType>` is `false`.
472
-
473
- *Effects:* Equivalent to:
474
- `return R{reinterpret_cast<byte*>(s.data()), s.size_bytes()};` where `R`
475
- is the return type.
476
-
477
- <!-- Link reference definitions -->
478
- [alg.sorting]: algorithms.md#alg.sorting
479
- [algorithm.stable]: library.md#algorithm.stable
480
- [algorithms]: algorithms.md#algorithms
481
- [algorithms.requirements]: algorithms.md#algorithms.requirements
482
- [allocator.requirements]: library.md#allocator.requirements
483
- [allocator.requirements.completeness]: library.md#allocator.requirements.completeness
484
- [allocator.traits.members]: utilities.md#allocator.traits.members
485
- [array]: #array
486
- [array.cons]: #array.cons
487
- [array.creation]: #array.creation
488
- [array.members]: #array.members
489
- [array.overview]: #array.overview
490
- [array.special]: #array.special
491
- [array.syn]: #array.syn
492
- [array.tuple]: #array.tuple
493
- [array.zero]: #array.zero
494
- [associative]: #associative
495
- [associative.general]: #associative.general
496
- [associative.map.syn]: #associative.map.syn
497
- [associative.reqmts]: #associative.reqmts
498
- [associative.reqmts.except]: #associative.reqmts.except
499
- [associative.set.syn]: #associative.set.syn
500
- [basic.string]: strings.md#basic.string
501
- [class.copy.ctor]: class.md#class.copy.ctor
502
- [class.default.ctor]: class.md#class.default.ctor
503
- [class.dtor]: class.md#class.dtor
504
- [container.adaptors]: #container.adaptors
505
- [container.adaptors.general]: #container.adaptors.general
506
- [container.alloc.req]: #container.alloc.req
507
- [container.assoc.req]: #container.assoc.req
508
- [container.hash.req]: #container.hash.req
509
- [container.insert.return]: #container.insert.return
510
- [container.node]: #container.node
511
- [container.node.compat]: #container.node.compat
512
- [container.node.cons]: #container.node.cons
513
- [container.node.dtor]: #container.node.dtor
514
- [container.node.modifiers]: #container.node.modifiers
515
- [container.node.observers]: #container.node.observers
516
- [container.node.overview]: #container.node.overview
517
- [container.opt]: #container.opt
518
- [container.req]: #container.req
519
- [container.requirements]: #container.requirements
520
- [container.requirements.dataraces]: #container.requirements.dataraces
521
- [container.requirements.general]: #container.requirements.general
522
- [container.rev.req]: #container.rev.req
523
- [container.seq.opt]: #container.seq.opt
524
- [container.seq.req]: #container.seq.req
525
- [containers]: #containers
526
- [containers.general]: #containers.general
527
- [containers.summary]: #containers.summary
528
- [dcl.init.aggr]: dcl.md#dcl.init.aggr
529
- [deque]: #deque
530
- [deque.capacity]: #deque.capacity
531
- [deque.cons]: #deque.cons
532
- [deque.erasure]: #deque.erasure
533
- [deque.modifiers]: #deque.modifiers
534
- [deque.overview]: #deque.overview
535
- [deque.syn]: #deque.syn
536
- [forward.list.erasure]: #forward.list.erasure
537
- [forward.list.syn]: #forward.list.syn
538
- [forwardlist]: #forwardlist
539
- [forwardlist.access]: #forwardlist.access
540
- [forwardlist.cons]: #forwardlist.cons
541
- [forwardlist.iter]: #forwardlist.iter
542
- [forwardlist.modifiers]: #forwardlist.modifiers
543
- [forwardlist.ops]: #forwardlist.ops
544
- [forwardlist.overview]: #forwardlist.overview
545
- [hash.requirements]: library.md#hash.requirements
546
- [iterator.concept.contiguous]: iterators.md#iterator.concept.contiguous
547
- [iterator.requirements]: iterators.md#iterator.requirements
548
- [iterator.requirements.general]: iterators.md#iterator.requirements.general
549
- [list]: #list
550
- [list.capacity]: #list.capacity
551
- [list.cons]: #list.cons
552
- [list.erasure]: #list.erasure
553
- [list.modifiers]: #list.modifiers
554
- [list.ops]: #list.ops
555
- [list.overview]: #list.overview
556
- [list.syn]: #list.syn
557
- [map]: #map
558
- [map.access]: #map.access
559
- [map.cons]: #map.cons
560
- [map.erasure]: #map.erasure
561
- [map.modifiers]: #map.modifiers
562
- [map.overview]: #map.overview
563
- [multimap]: #multimap
564
- [multimap.cons]: #multimap.cons
565
- [multimap.erasure]: #multimap.erasure
566
- [multimap.modifiers]: #multimap.modifiers
567
- [multimap.overview]: #multimap.overview
568
- [multiset]: #multiset
569
- [multiset.cons]: #multiset.cons
570
- [multiset.erasure]: #multiset.erasure
571
- [multiset.overview]: #multiset.overview
572
- [priority.queue]: #priority.queue
573
- [priqueue.cons]: #priqueue.cons
574
- [priqueue.cons.alloc]: #priqueue.cons.alloc
575
- [priqueue.members]: #priqueue.members
576
- [priqueue.overview]: #priqueue.overview
577
- [priqueue.special]: #priqueue.special
578
- [queue]: #queue
579
- [queue.cons]: #queue.cons
580
- [queue.cons.alloc]: #queue.cons.alloc
581
- [queue.defn]: #queue.defn
582
- [queue.ops]: #queue.ops
583
- [queue.special]: #queue.special
584
- [queue.syn]: #queue.syn
585
- [random.access.iterators]: iterators.md#random.access.iterators
586
- [res.on.data.races]: library.md#res.on.data.races
587
- [sequence.reqmts]: #sequence.reqmts
588
- [sequences]: #sequences
589
- [sequences.general]: #sequences.general
590
- [set]: #set
591
- [set.cons]: #set.cons
592
- [set.erasure]: #set.erasure
593
- [set.overview]: #set.overview
594
- [span.cons]: #span.cons
595
- [span.deduct]: #span.deduct
596
- [span.elem]: #span.elem
597
- [span.iterators]: #span.iterators
598
- [span.objectrep]: #span.objectrep
599
- [span.obs]: #span.obs
600
- [span.overview]: #span.overview
601
- [span.sub]: #span.sub
602
- [span.syn]: #span.syn
603
- [stack]: #stack
604
- [stack.cons]: #stack.cons
605
- [stack.cons.alloc]: #stack.cons.alloc
606
- [stack.defn]: #stack.defn
607
- [stack.ops]: #stack.ops
608
- [stack.special]: #stack.special
609
- [stack.syn]: #stack.syn
610
- [strings]: strings.md#strings
611
- [swappable.requirements]: library.md#swappable.requirements
612
- [tab:container.opt]: #tab:container.opt
613
- [tab:container.req]: #tab:container.req
614
- [tab:container.rev.req]: #tab:container.rev.req
615
- [tab:container.seq.opt]: #tab:container.seq.opt
616
- [tab:container.seq.req]: #tab:container.seq.req
617
- [temp.deduct]: temp.md#temp.deduct
618
- [temp.param]: temp.md#temp.param
619
- [temp.type]: temp.md#temp.type
620
- [unord]: #unord
621
- [unord.general]: #unord.general
622
- [unord.hash]: utilities.md#unord.hash
623
- [unord.map]: #unord.map
624
- [unord.map.cnstr]: #unord.map.cnstr
625
- [unord.map.elem]: #unord.map.elem
626
- [unord.map.erasure]: #unord.map.erasure
627
- [unord.map.modifiers]: #unord.map.modifiers
628
- [unord.map.overview]: #unord.map.overview
629
- [unord.map.syn]: #unord.map.syn
630
- [unord.multimap]: #unord.multimap
631
- [unord.multimap.cnstr]: #unord.multimap.cnstr
632
- [unord.multimap.erasure]: #unord.multimap.erasure
633
- [unord.multimap.modifiers]: #unord.multimap.modifiers
634
- [unord.multimap.overview]: #unord.multimap.overview
635
- [unord.multiset]: #unord.multiset
636
- [unord.multiset.cnstr]: #unord.multiset.cnstr
637
- [unord.multiset.erasure]: #unord.multiset.erasure
638
- [unord.multiset.overview]: #unord.multiset.overview
639
- [unord.req]: #unord.req
640
- [unord.req.except]: #unord.req.except
641
- [unord.set]: #unord.set
642
- [unord.set.cnstr]: #unord.set.cnstr
643
- [unord.set.erasure]: #unord.set.erasure
644
- [unord.set.overview]: #unord.set.overview
645
- [unord.set.syn]: #unord.set.syn
646
- [vector]: #vector
647
- [vector.bool]: #vector.bool
648
- [vector.capacity]: #vector.capacity
649
- [vector.cons]: #vector.cons
650
- [vector.data]: #vector.data
651
- [vector.erasure]: #vector.erasure
652
- [vector.modifiers]: #vector.modifiers
653
- [vector.overview]: #vector.overview
654
- [vector.syn]: #vector.syn
655
- [views]: #views
656
- [views.general]: #views.general
657
- [views.span]: #views.span
658
-
659
- [^1]: Equality comparison is a refinement of partitioning if no two
660
- objects that compare equal fall into different partitions.
661
-
662
- [^2]: These member functions are only provided by containers whose
663
- iterators are random access iterators.
664
-
665
- [^3]: As specified in  [[allocator.requirements]], the requirements in
666
- this Clause apply only to lists whose allocators compare equal.
667
-
668
- [^4]: `reserve()` uses `Allocator::allocate()` which may throw an
669
- appropriate exception.
 
1
+ #### Class template `span` <a id="views.span">[[views.span]]</a>
2
 
3
+ ##### Overview <a id="span.overview">[[span.overview]]</a>
4
 
5
  A `span` is a view over a contiguous sequence of objects, the storage of
6
  which is owned by some other object.
7
 
8
  All member functions of `span` have constant time complexity.
 
20
  using pointer = element_type*;
21
  using const_pointer = const element_type*;
22
  using reference = element_type&;
23
  using const_reference = const element_type&;
24
  using iterator = implementation-defined // type of span::iterator; // see [span.iterators]
25
+ using const_iterator = std::const_iterator<iterator>;
26
  using reverse_iterator = std::reverse_iterator<iterator>;
27
+ using const_reverse_iterator = std::const_iterator<reverse_iterator>;
28
  static constexpr size_type extent = Extent;
29
 
30
  // [span.cons], constructors, copy, and assignment
31
  constexpr span() noexcept;
32
  template<class It>
 
74
  constexpr pointer data() const noexcept;
75
 
76
  // [span.iterators], iterator support
77
  constexpr iterator begin() const noexcept;
78
  constexpr iterator end() const noexcept;
79
+ constexpr const_iterator cbegin() const noexcept { return begin(); }
80
+ constexpr const_iterator cend() const noexcept { return end(); }
81
  constexpr reverse_iterator rbegin() const noexcept;
82
  constexpr reverse_iterator rend() const noexcept;
83
+ constexpr const_reverse_iterator crbegin() const noexcept { return rbegin(); }
84
+ constexpr const_reverse_iterator crend() const noexcept { return rend(); }
85
 
86
  private:
87
  pointer data_; // exposition only
88
  size_type size_; // exposition only
89
  };
 
99
  template<class R>
100
  span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
101
  }
102
  ```
103
 
104
+ `span<ElementType, Extent>` is a trivially copyable type
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
  ```
115
 
 
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
145
  template<class It, class End>
 
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;
 
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;
 
256
  constexpr span& operator=(const span& other) noexcept = default;
257
  ```
258
 
259
  *Ensures:* `size() == other.size() && data() == other.data()`.
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
  ```
 
272
  span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;
273
  ```
274
 
275
  *Constraints:* `R` satisfies `ranges::contiguous_range`.
276
 
277
+ ##### Subviews <a id="span.sub">[[span.sub]]</a>
278
 
279
  ``` cpp
280
  template<size_t Count> constexpr span<element_type, Count> first() const;
281
  ```
282
 
 
367
 
368
  ``` cpp
369
  return {data() + offset, count == dynamic_extent ? size() - offset : count};
370
  ```
371
 
372
+ ##### Observers <a id="span.obs">[[span.obs]]</a>
373
 
374
  ``` cpp
375
  constexpr size_type size() const noexcept;
376
  ```
377
 
378
+ *Effects:* Equivalent to: `return `*`size_`*`;`
379
 
380
  ``` cpp
381
  constexpr size_type size_bytes() const noexcept;
382
  ```
383
 
 
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
 
 
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;
428
  ```
429
 
430
  The type models `contiguous_iterator` [[iterator.concept.contiguous]],
431
  meets the *Cpp17RandomAccessIterator*
432
  requirements [[random.access.iterators]], and meets the requirements for
433
+ constexpr iterators [[iterator.requirements.general]], whose value type
434
+ is `value_type` and whose reference type is `reference`.
435
+
436
+ All requirements on container iterators [[container.reqmts]] apply to
437
  `span::iterator` as well.
438
 
439
  ``` cpp
440
  constexpr iterator begin() const noexcept;
441
  ```
 
459
  constexpr reverse_iterator rend() const noexcept;
460
  ```
461
 
462
  *Effects:* Equivalent to: `return reverse_iterator(begin());`
463