From Jason Turner

[sequences]

Large diff (103.8 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbj3pzuhg/{from.md → to.md} +684 -608
tmp/tmpbj3pzuhg/{from.md → to.md} RENAMED
@@ -4,35 +4,47 @@
4
 
5
  The headers `<array>`, `<deque>`, `<forward_list>`, `<list>`, and
6
  `<vector>` define class templates that meet the requirements for
7
  sequence containers.
8
 
 
 
 
 
 
 
 
 
9
  ### Header `<array>` synopsis <a id="array.syn">[[array.syn]]</a>
10
 
11
  ``` cpp
12
- #include <initializer_list>
 
13
 
14
  namespace std {
15
  // [array], class template array
16
  template<class T, size_t N> struct array;
 
17
  template<class T, size_t N>
18
- bool operator==(const array<T, N>& x, const array<T, N>& y);
19
- template <class T, size_t N>
20
- bool operator!=(const array<T, N>& x, const array<T, N>& y);
21
- template <class T, size_t N>
22
- bool operator< (const array<T, N>& x, const array<T, N>& y);
23
  template<class T, size_t N>
24
- bool operator> (const array<T, N>& x, const array<T, N>& y);
 
 
 
25
  template<class T, size_t N>
26
- bool operator<=(const array<T, N>& x, const array<T, N>& y);
 
 
27
  template<class T, size_t N>
28
- bool operator>=(const array<T, N>& x, const array<T, N>& y);
29
  template<class T, size_t N>
30
- void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
31
 
32
- template <class T> class tuple_size;
33
- template <size_t I, class T> class tuple_element;
 
34
  template<class T, size_t N>
35
  struct tuple_size<array<T, N>>;
36
  template<size_t I, class T, size_t N>
37
  struct tuple_element<I, array<T, N>>;
38
  template<size_t I, class T, size_t N>
@@ -47,124 +59,136 @@ namespace std {
47
  ```
48
 
49
  ### Header `<deque>` synopsis <a id="deque.syn">[[deque.syn]]</a>
50
 
51
  ``` cpp
52
- #include <initializer_list>
 
53
 
54
  namespace std {
55
  // [deque], class template deque
56
  template<class T, class Allocator = allocator<T>> class deque;
 
57
  template<class T, class Allocator>
58
  bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
59
  template<class T, class Allocator>
60
- bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
61
- template <class T, class Allocator>
62
- bool operator!=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
63
- template <class T, class Allocator>
64
- bool operator> (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
65
- template <class T, class Allocator>
66
- bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
67
- template <class T, class Allocator>
68
- bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
69
  template<class T, class Allocator>
70
  void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
71
  noexcept(noexcept(x.swap(y)));
72
 
 
 
 
 
 
 
 
73
  namespace pmr {
74
  template<class T>
75
  using deque = std::deque<T, polymorphic_allocator<T>>;
76
  }
77
  }
78
  ```
79
 
80
- ### Header `<forward_list>` synopsis <a id="forward_list.syn">[[forward_list.syn]]</a>
81
 
82
  ``` cpp
83
- #include <initializer_list>
 
84
 
85
  namespace std {
86
  // [forwardlist], class template forward_list
87
  template<class T, class Allocator = allocator<T>> class forward_list;
 
88
  template<class T, class Allocator>
89
  bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
90
  template<class T, class Allocator>
91
- bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
92
- template <class T, class Allocator>
93
- bool operator!=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
94
- template <class T, class Allocator>
95
- bool operator> (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
96
- template <class T, class Allocator>
97
- bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
98
- template <class T, class Allocator>
99
- bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
100
  template<class T, class Allocator>
101
  void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
102
  noexcept(noexcept(x.swap(y)));
103
 
 
 
 
 
 
 
 
104
  namespace pmr {
105
  template<class T>
106
  using forward_list = std::forward_list<T, polymorphic_allocator<T>>;
107
  }
108
  }
109
  ```
110
 
111
  ### Header `<list>` synopsis <a id="list.syn">[[list.syn]]</a>
112
 
113
  ``` cpp
114
- #include <initializer_list>
 
115
 
116
  namespace std {
117
  // [list], class template list
118
  template<class T, class Allocator = allocator<T>> class list;
 
119
  template<class T, class Allocator>
120
  bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
121
  template<class T, class Allocator>
122
- bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
123
- template <class T, class Allocator>
124
- bool operator!=(const list<T, Allocator>& x, const list<T, Allocator>& y);
125
- template <class T, class Allocator>
126
- bool operator> (const list<T, Allocator>& x, const list<T, Allocator>& y);
127
- template <class T, class Allocator>
128
- bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
129
- template <class T, class Allocator>
130
- bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
131
  template<class T, class Allocator>
132
  void swap(list<T, Allocator>& x, list<T, Allocator>& y)
133
  noexcept(noexcept(x.swap(y)));
134
 
 
 
 
 
 
 
 
135
  namespace pmr {
136
  template<class T>
137
  using list = std::list<T, polymorphic_allocator<T>>;
138
  }
139
  }
140
  ```
141
 
142
  ### Header `<vector>` synopsis <a id="vector.syn">[[vector.syn]]</a>
143
 
144
  ``` cpp
145
- #include <initializer_list>
 
146
 
147
  namespace std {
148
  // [vector], class template vector
149
  template<class T, class Allocator = allocator<T>> class vector;
 
150
  template<class T, class Allocator>
151
- bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
152
  template<class T, class Allocator>
153
- bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
 
 
154
  template<class T, class Allocator>
155
- bool operator!=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
156
- template <class T, class Allocator>
157
- bool operator> (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
158
- template <class T, class Allocator>
159
- bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
160
- template <class T, class Allocator>
161
- bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
162
- template <class T, class Allocator>
163
- void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
164
  noexcept(noexcept(x.swap(y)));
165
 
 
 
 
 
 
 
 
166
  // [vector.bool], class vector<bool>
167
  template<class Allocator> class vector<bool, Allocator>;
168
 
169
  // hash support
170
  template<class T> struct hash;
@@ -177,35 +201,44 @@ namespace std {
177
  }
178
  ```
179
 
180
  ### Class template `array` <a id="array">[[array]]</a>
181
 
182
- #### Class template `array` overview <a id="array.overview">[[array.overview]]</a>
183
 
184
  The header `<array>` defines a class template for storing fixed-size
185
- sequences of objects. An `array` is a contiguous container (
186
- [[container.requirements.general]]). An instance of `array<T, N>` stores
187
  `N` elements of type `T`, so that `size() == N` is an invariant.
188
 
189
- An `array` is an aggregate ([[dcl.init.aggr]]) that can be
190
  list-initialized with up to `N` elements whose types are convertible to
191
  `T`.
192
 
193
- An `array` satisfies all of the requirements of a container and of a
194
- reversible container ([[container.requirements]]), except that a
195
- default constructed `array` object is not empty and that `swap` does not
196
- have constant complexity. An `array` satisfies some of the requirements
197
- of a sequence container ([[sequence.reqmts]]). Descriptions are
198
- provided here only for operations on `array` that are not described in
199
- one of these tables and for operations where there is additional
200
- semantic information.
 
 
 
 
 
 
 
 
 
201
 
202
  ``` cpp
203
  namespace std {
204
  template<class T, size_t N>
205
  struct array {
206
- // types:
207
  using value_type = T;
208
  using pointer = T*;
209
  using const_pointer = const T*;
210
  using reference = T&;
211
  using const_reference = const T&;
@@ -216,14 +249,14 @@ namespace std {
216
  using reverse_iterator = std::reverse_iterator<iterator>;
217
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
218
 
219
  // no explicit construct/copy/destroy for aggregate type
220
 
221
- void fill(const T& u);
222
- void swap(array&) noexcept(is_nothrow_swappable_v<T>);
223
 
224
- // iterators:
225
  constexpr iterator begin() noexcept;
226
  constexpr const_iterator begin() const noexcept;
227
  constexpr iterator end() noexcept;
228
  constexpr const_iterator end() const noexcept;
229
 
@@ -235,16 +268,16 @@ namespace std {
235
  constexpr const_iterator cbegin() const noexcept;
236
  constexpr const_iterator cend() const noexcept;
237
  constexpr const_reverse_iterator crbegin() const noexcept;
238
  constexpr const_reverse_iterator crend() const noexcept;
239
 
240
- // capacity:
241
- constexpr bool empty() const noexcept;
242
  constexpr size_type size() const noexcept;
243
  constexpr size_type max_size() const noexcept;
244
 
245
- // element access:
246
  constexpr reference operator[](size_type n);
247
  constexpr const_reference operator[](size_type n) const;
248
  constexpr reference at(size_type n);
249
  constexpr const_reference at(size_type n) const;
250
  constexpr reference front();
@@ -259,83 +292,75 @@ namespace std {
259
  template<class T, class... U>
260
  array(T, U...) -> array<T, 1 + sizeof...(U)>;
261
  }
262
  ```
263
 
264
- #### `array` constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
265
 
266
- The conditions for an aggregate ([[dcl.init.aggr]]) shall be met. Class
267
  `array` relies on the implicitly-declared special member functions (
268
- [[class.ctor]], [[class.dtor]], and [[class.copy]]) to conform to the
269
- container requirements table in  [[container.requirements]]. In addition
270
- to the requirements specified in the container requirements table, the
271
- implicit move constructor and move assignment operator for `array`
272
- require that `T` be `MoveConstructible` or `MoveAssignable`,
273
- respectively.
274
 
275
  ``` cpp
276
  template<class T, class... U>
277
  array(T, U...) -> array<T, 1 + sizeof...(U)>;
278
  ```
279
 
280
- *Requires:* `(is_same_v<T, U> && ...)` is `true`. Otherwise the program
281
- is ill-formed.
282
 
283
- #### `array` specialized algorithms <a id="array.special">[[array.special]]</a>
284
 
285
  ``` cpp
286
- template <class T, size_t N>
287
- void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
288
- ```
289
-
290
- *Remarks:* This function shall not participate in overload resolution
291
- unless `N == 0` or `is_swappable_v<T>` is `true`.
292
-
293
- *Effects:* As if by `x.swap(y)`.
294
-
295
- *Complexity:* Linear in `N`.
296
-
297
- #### `array::size` <a id="array.size">[[array.size]]</a>
298
-
299
- ``` cpp
300
- template <class T, size_t N> constexpr size_type array<T, N>::size() const noexcept;
301
  ```
302
 
303
  *Returns:* `N`.
304
 
305
- #### `array::data` <a id="array.data">[[array.data]]</a>
306
-
307
  ``` cpp
308
  constexpr T* data() noexcept;
309
  constexpr const T* data() const noexcept;
310
  ```
311
 
312
- *Returns:* A pointer such that `data() == addressof(front())`, and
313
- \[`data()`, `data() + size()`) is a valid range.
314
-
315
- #### `array::fill` <a id="array.fill">[[array.fill]]</a>
316
 
317
  ``` cpp
318
- void fill(const T& u);
319
  ```
320
 
321
  *Effects:* As if by `fill_n(begin(), N, u)`.
322
 
323
- #### `array::swap` <a id="array.swap">[[array.swap]]</a>
324
-
325
  ``` cpp
326
- void swap(array& y) noexcept(is_nothrow_swappable_v<T>);
327
  ```
328
 
329
  *Effects:* Equivalent to `swap_ranges(begin(), end(), y.begin())`.
330
 
331
  [*Note 1*: Unlike the `swap` function for other containers,
332
  `array::swap` takes linear time, may exit via an exception, and does not
333
  cause iterators to become associated with the other
334
  container. — *end note*]
335
 
336
- #### Zero sized arrays <a id="array.zero">[[array.zero]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
337
 
338
  `array` shall provide support for the special case `N == 0`.
339
 
340
  In the case that `N == 0`, `begin() == end() ==` unique value. The
341
  return value of `data()` is unspecified.
@@ -344,24 +369,51 @@ The effect of calling `front()` or `back()` for a zero-sized array is
344
  undefined.
345
 
346
  Member function `swap()` shall have a non-throwing exception
347
  specification.
348
 
349
- #### Tuple interface to class template `array` <a id="array.tuple">[[array.tuple]]</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  ``` cpp
352
  template<class T, size_t N>
353
  struct tuple_size<array<T, N>> : integral_constant<size_t, N> { };
354
  ```
355
 
356
  ``` cpp
357
- tuple_element<I, array<T, N>>::type
 
 
 
358
  ```
359
 
360
- *Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
361
-
362
- *Value:* The type T.
363
 
364
  ``` cpp
365
  template<size_t I, class T, size_t N>
366
  constexpr T& get(array<T, N>& a) noexcept;
367
  template<size_t I, class T, size_t N>
@@ -370,41 +422,40 @@ template <size_t I, class T, size_t N>
370
  constexpr const T& get(const array<T, N>& a) noexcept;
371
  template<size_t I, class T, size_t N>
372
  constexpr const T&& get(const array<T, N>&& a) noexcept;
373
  ```
374
 
375
- *Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
376
 
377
- *Returns:* A reference to the `I`th element of `a`, where indexing is
378
  zero-based.
379
 
380
  ### Class template `deque` <a id="deque">[[deque]]</a>
381
 
382
- #### Class template `deque` overview <a id="deque.overview">[[deque.overview]]</a>
383
 
384
  A `deque` is a sequence container that supports random access iterators
385
- ([[random.access.iterators]]). In addition, it supports constant time
386
  insert and erase operations at the beginning or the end; insert and
387
  erase in the middle take linear time. That is, a deque is especially
388
  optimized for pushing and popping elements at the beginning and end.
389
  Storage management is handled automatically.
390
 
391
- A `deque` satisfies all of the requirements of a container, of a
392
- reversible container (given in tables in  [[container.requirements]]),
393
- of a sequence container, including the optional sequence container
394
- requirements ([[sequence.reqmts]]), and of an allocator-aware container
395
- (Table  [[tab:containers.allocatoraware]]). Descriptions are provided
396
- here only for operations on `deque` that are not described in one of
397
- these tables or for operations where there is additional semantic
398
- information.
399
 
400
  ``` cpp
401
  namespace std {
402
  template<class T, class Allocator = allocator<T>>
403
  class deque {
404
  public:
405
- // types:
406
  using value_type = T;
407
  using allocator_type = Allocator;
408
  using pointer = typename allocator_traits<Allocator>::pointer;
409
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
410
  using reference = value_type&;
@@ -438,11 +489,11 @@ namespace std {
438
  void assign(InputIterator first, InputIterator last);
439
  void assign(size_type n, const T& t);
440
  void assign(initializer_list<T>);
441
  allocator_type get_allocator() const noexcept;
442
 
443
- // iterators:
444
  iterator begin() noexcept;
445
  const_iterator begin() const noexcept;
446
  iterator end() noexcept;
447
  const_iterator end() const noexcept;
448
  reverse_iterator rbegin() noexcept;
@@ -454,18 +505,18 @@ namespace std {
454
  const_iterator cend() const noexcept;
455
  const_reverse_iterator crbegin() const noexcept;
456
  const_reverse_iterator crend() const noexcept;
457
 
458
  // [deque.capacity], capacity
459
- bool empty() const noexcept;
460
  size_type size() const noexcept;
461
  size_type max_size() const noexcept;
462
  void resize(size_type sz);
463
  void resize(size_type sz, const T& c);
464
  void shrink_to_fit();
465
 
466
- // element access:
467
  reference operator[](size_type n);
468
  const_reference operator[](size_type n) const;
469
  reference at(size_type n);
470
  const_reference at(size_type n) const;
471
  reference front();
@@ -498,36 +549,22 @@ namespace std {
498
  void swap(deque&)
499
  noexcept(allocator_traits<Allocator>::is_always_equal::value);
500
  void clear() noexcept;
501
  };
502
 
503
- template<class InputIterator,
504
- class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
505
  deque(InputIterator, InputIterator, Allocator = Allocator())
506
- -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
507
 
508
- template <class T, class Allocator>
509
- bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
510
- template <class T, class Allocator>
511
- bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
512
- template <class T, class Allocator>
513
- bool operator!=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
514
- template <class T, class Allocator>
515
- bool operator> (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
516
- template <class T, class Allocator>
517
- bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
518
- template <class T, class Allocator>
519
- bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
520
-
521
- // [deque.special], specialized algorithms
522
  template<class T, class Allocator>
523
  void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
524
  noexcept(noexcept(x.swap(y)));
525
  }
526
  ```
527
 
528
- #### `deque` constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
529
 
530
  ``` cpp
531
  explicit deque(const Allocator&);
532
  ```
533
 
@@ -540,22 +577,22 @@ explicit deque(size_type n, const Allocator& = Allocator());
540
  ```
541
 
542
  *Effects:* Constructs a `deque` with `n` default-inserted elements using
543
  the specified allocator.
544
 
545
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
546
 
547
  *Complexity:* Linear in `n`.
548
 
549
  ``` cpp
550
  deque(size_type n, const T& value, const Allocator& = Allocator());
551
  ```
552
 
553
  *Effects:* Constructs a `deque` with `n` copies of `value`, using the
554
  specified allocator.
555
 
556
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
557
 
558
  *Complexity:* Linear in `n`.
559
 
560
  ``` cpp
561
  template<class InputIterator>
@@ -565,55 +602,57 @@ template <class InputIterator>
565
  *Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
566
  using the specified allocator.
567
 
568
  *Complexity:* Linear in `distance(first, last)`.
569
 
570
- #### `deque` capacity <a id="deque.capacity">[[deque.capacity]]</a>
571
 
572
  ``` cpp
573
  void resize(size_type sz);
574
  ```
575
 
 
 
 
576
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
577
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
578
  to the sequence.
579
 
580
- *Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
581
- `*this`.
582
-
583
  ``` cpp
584
  void resize(size_type sz, const T& c);
585
  ```
586
 
 
 
587
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
588
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
589
  sequence.
590
 
591
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
592
-
593
  ``` cpp
594
  void shrink_to_fit();
595
  ```
596
 
597
- *Requires:* `T` shall be `MoveInsertable` into `*this`.
598
 
599
  *Effects:* `shrink_to_fit` is a non-binding request to reduce memory use
600
  but does not change the size of the sequence.
601
 
602
  [*Note 1*: The request is non-binding to allow latitude for
603
  implementation-specific optimizations. — *end note*]
604
 
605
- If an exception is thrown other than by the move constructor of a
606
- non-`CopyInsertable` `T` there are no effects.
 
607
 
608
- *Complexity:* Linear in the size of the sequence.
 
609
 
610
- *Remarks:* `shrink_to_fit` invalidates all the references, pointers, and
611
- iterators referring to the elements in the sequence as well as the
612
- past-the-end iterator.
613
 
614
- #### `deque` modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
615
 
616
  ``` cpp
617
  iterator insert(const_iterator position, const T& x);
618
  iterator insert(const_iterator position, T&& x);
619
  iterator insert(const_iterator position, size_type n, const T& x);
@@ -638,16 +677,16 @@ has no effect on the validity of references to elements of the deque.
638
 
639
  *Remarks:* If an exception is thrown other than by the copy constructor,
640
  move constructor, assignment operator, or move assignment operator of
641
  `T` there are no effects. If an exception is thrown while inserting a
642
  single element at either end, there are no effects. Otherwise, if an
643
- exception is thrown by the move constructor of a non-`CopyInsertable`
644
- `T`, the effects are unspecified.
645
 
646
  *Complexity:* The complexity is linear in the number of elements
647
  inserted plus the lesser of the distances to the beginning and end of
648
- the deque. Inserting a single element either at the beginning or end of
649
  a deque always takes constant time and causes a single call to a
650
  constructor of `T`.
651
 
652
  ``` cpp
653
  iterator erase(const_iterator position);
@@ -672,48 +711,68 @@ operations. — *end note*]
672
  as the number of elements erased, but the number of calls to the
673
  assignment operator of `T` is no more than the lesser of the number of
674
  elements before the erased elements and the number of elements after the
675
  erased elements.
676
 
677
- *Throws:* Nothing unless an exception is thrown by the copy constructor,
678
- move constructor, assignment operator, or move assignment operator of
679
- `T`.
680
 
681
- #### `deque` specialized algorithms <a id="deque.special">[[deque.special]]</a>
682
 
683
  ``` cpp
684
- template <class T, class Allocator>
685
- void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
686
- noexcept(noexcept(x.swap(y)));
687
  ```
688
 
689
- *Effects:* As if by `x.swap(y)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
690
 
691
  ### Class template `forward_list` <a id="forwardlist">[[forwardlist]]</a>
692
 
693
- #### Class template `forward_list` overview <a id="forwardlist.overview">[[forwardlist.overview]]</a>
694
 
695
  A `forward_list` is a container that supports forward iterators and
696
  allows constant time insert and erase operations anywhere within the
697
  sequence, with storage management handled automatically. Fast random
698
  access to list elements is not supported.
699
 
700
  [*Note 1*: It is intended that `forward_list` have zero space or time
701
  overhead relative to a hand-written C-style singly linked list. Features
702
  that would conflict with that goal have been omitted. — *end note*]
703
 
704
- A `forward_list` satisfies all of the requirements of a container
705
- (Table  [[tab:containers.container.requirements]]), except that the
706
- `size()` member function is not provided and `operator==` has linear
707
- complexity. A `forward_list` also satisfies all of the requirements for
708
- an allocator-aware container (Table  [[tab:containers.allocatoraware]]).
709
- In addition, a `forward_list` provides the `assign` member functions
710
- (Table  [[tab:containers.sequence.requirements]]) and several of the
711
- optional container requirements (Table 
712
- [[tab:containers.sequence.optional]]). Descriptions are provided here
713
- only for operations on `forward_list` that are not described in that
714
- table or for operations where there is additional semantic information.
715
 
716
  [*Note 2*: Modifying any list requires access to the element preceding
717
  the first element of interest, but in a `forward_list` there is no
718
  constant-time way to access a preceding element. For this reason, ranges
719
  that are modified, such as those supplied to `erase` and `splice`, must
@@ -722,11 +781,11 @@ be open at the beginning. — *end note*]
722
  ``` cpp
723
  namespace std {
724
  template<class T, class Allocator = allocator<T>>
725
  class forward_list {
726
  public:
727
- // types:
728
  using value_type = T;
729
  using allocator_type = Allocator;
730
  using pointer = typename allocator_traits<Allocator>::pointer;
731
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
732
  using reference = value_type&;
@@ -738,15 +797,13 @@ namespace std {
738
 
739
  // [forwardlist.cons], construct/copy/destroy
740
  forward_list() : forward_list(Allocator()) { }
741
  explicit forward_list(const Allocator&);
742
  explicit forward_list(size_type n, const Allocator& = Allocator());
743
- forward_list(size_type n, const T& value,
744
- const Allocator& = Allocator());
745
  template<class InputIterator>
746
- forward_list(InputIterator first, InputIterator last,
747
- const Allocator& = Allocator());
748
  forward_list(const forward_list& x);
749
  forward_list(forward_list&& x);
750
  forward_list(const forward_list& x, const Allocator&);
751
  forward_list(forward_list&& x, const Allocator&);
752
  forward_list(initializer_list<T>, const Allocator& = Allocator());
@@ -771,12 +828,12 @@ namespace std {
771
 
772
  const_iterator cbegin() const noexcept;
773
  const_iterator cbefore_begin() const noexcept;
774
  const_iterator cend() const noexcept;
775
 
776
- // capacity:
777
- bool empty() const noexcept;
778
  size_type max_size() const noexcept;
779
 
780
  // [forwardlist.access], element access
781
  reference front();
782
  const_reference front() const;
@@ -806,24 +863,22 @@ namespace std {
806
  void clear() noexcept;
807
 
808
  // [forwardlist.ops], forward_list operations
809
  void splice_after(const_iterator position, forward_list& x);
810
  void splice_after(const_iterator position, forward_list&& x);
811
- void splice_after(const_iterator position, forward_list& x,
812
- const_iterator i);
813
- void splice_after(const_iterator position, forward_list&& x,
814
- const_iterator i);
815
  void splice_after(const_iterator position, forward_list& x,
816
  const_iterator first, const_iterator last);
817
  void splice_after(const_iterator position, forward_list&& x,
818
  const_iterator first, const_iterator last);
819
 
820
- void remove(const T& value);
821
- template <class Predicate> void remove_if(Predicate pred);
822
 
823
- void unique();
824
- template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
825
 
826
  void merge(forward_list& x);
827
  void merge(forward_list&& x);
828
  template<class Compare> void merge(forward_list& x, Compare comp);
829
  template<class Compare> void merge(forward_list&& x, Compare comp);
@@ -832,42 +887,28 @@ namespace std {
832
  template<class Compare> void sort(Compare comp);
833
 
834
  void reverse() noexcept;
835
  };
836
 
837
- template<class InputIterator,
838
- class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
839
  forward_list(InputIterator, InputIterator, Allocator = Allocator())
840
- -> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>;
841
 
842
- template <class T, class Allocator>
843
- bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
844
- template <class T, class Allocator>
845
- bool operator< (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
846
- template <class T, class Allocator>
847
- bool operator!=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
848
- template <class T, class Allocator>
849
- bool operator> (const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
850
- template <class T, class Allocator>
851
- bool operator>=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
852
- template <class T, class Allocator>
853
- bool operator<=(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
854
-
855
- // [forwardlist.spec], specialized algorithms
856
  template<class T, class Allocator>
857
  void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
858
  noexcept(noexcept(x.swap(y)));
859
  }
860
  ```
861
 
862
  An incomplete type `T` may be used when instantiating `forward_list` if
863
- the allocator satisfies the allocator completeness requirements (
864
- [[allocator.requirements.completeness]]). `T` shall be complete before
865
  any member of the resulting specialization of `forward_list` is
866
  referenced.
867
 
868
- #### `forward_list` constructors, copy, assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
869
 
870
  ``` cpp
871
  explicit forward_list(const Allocator&);
872
  ```
873
 
@@ -878,26 +919,26 @@ allocator.
878
 
879
  ``` cpp
880
  explicit forward_list(size_type n, const Allocator& = Allocator());
881
  ```
882
 
 
 
883
  *Effects:* Constructs a `forward_list` object with `n` default-inserted
884
  elements using the specified allocator.
885
 
886
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
887
-
888
  *Complexity:* Linear in `n`.
889
 
890
  ``` cpp
891
  forward_list(size_type n, const T& value, const Allocator& = Allocator());
892
  ```
893
 
 
 
894
  *Effects:* Constructs a `forward_list` object with `n` copies of `value`
895
  using the specified allocator.
896
 
897
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
898
-
899
  *Complexity:* Linear in `n`.
900
 
901
  ``` cpp
902
  template<class InputIterator>
903
  forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator());
@@ -906,11 +947,11 @@ template <class InputIterator>
906
  *Effects:* Constructs a `forward_list` object equal to the range
907
  \[`first`, `last`).
908
 
909
  *Complexity:* Linear in `distance(first, last)`.
910
 
911
- #### `forward_list` iterators <a id="forwardlist.iter">[[forwardlist.iter]]</a>
912
 
913
  ``` cpp
914
  iterator before_begin() noexcept;
915
  const_iterator before_begin() const noexcept;
916
  const_iterator cbefore_begin() const noexcept;
@@ -922,20 +963,20 @@ equal to the iterator returned by `begin()`.
922
  *Effects:* `cbefore_begin()` is equivalent to
923
  `const_cast<forward_list const&>(*this).before_begin()`.
924
 
925
  *Remarks:* `before_begin() == end()` shall equal `false`.
926
 
927
- #### `forward_list` element access <a id="forwardlist.access">[[forwardlist.access]]</a>
928
 
929
  ``` cpp
930
  reference front();
931
  const_reference front() const;
932
  ```
933
 
934
  *Returns:* `*begin()`
935
 
936
- #### `forward_list` modifiers <a id="forwardlist.modifiers">[[forwardlist.modifiers]]</a>
937
 
938
  None of the overloads of `insert_after` shall affect the validity of
939
  iterators and references, and `erase_after` shall invalidate only
940
  iterators and references to the erased elements. If an exception is
941
  thrown during `insert_after` there shall be no effect. Inserting `n`
@@ -967,22 +1008,22 @@ void pop_front();
967
  ``` cpp
968
  iterator insert_after(const_iterator position, const T& x);
969
  iterator insert_after(const_iterator position, T&& x);
970
  ```
971
 
972
- *Requires:* `position` is `before_begin()` or is a dereferenceable
973
  iterator in the range \[`begin()`, `end()`).
974
 
975
  *Effects:* Inserts a copy of `x` after `position`.
976
 
977
  *Returns:* An iterator pointing to the copy of `x`.
978
 
979
  ``` cpp
980
  iterator insert_after(const_iterator position, size_type n, const T& x);
981
  ```
982
 
983
- *Requires:* `position` is `before_begin()` or is a dereferenceable
984
  iterator in the range \[`begin()`, `end()`).
985
 
986
  *Effects:* Inserts `n` copies of `x` after `position`.
987
 
988
  *Returns:* An iterator pointing to the last inserted copy of `x` or
@@ -991,13 +1032,13 @@ iterator in the range \[`begin()`, `end()`).
991
  ``` cpp
992
  template<class InputIterator>
993
  iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
994
  ```
995
 
996
- *Requires:* `position` is `before_begin()` or is a dereferenceable
997
- iterator in the range \[`begin()`, `end()`). `first` and `last` are not
998
- iterators in `*this`.
999
 
1000
  *Effects:* Inserts copies of elements in \[`first`, `last`) after
1001
  `position`.
1002
 
1003
  *Returns:* An iterator pointing to the last inserted element or
@@ -1015,11 +1056,11 @@ iterator insert_after(const_iterator position, initializer_list<T> il);
1015
  ``` cpp
1016
  template<class... Args>
1017
  iterator emplace_after(const_iterator position, Args&&... args);
1018
  ```
1019
 
1020
- *Requires:* `position` is `before_begin()` or is a dereferenceable
1021
  iterator in the range \[`begin()`, `end()`).
1022
 
1023
  *Effects:* Inserts an object of type `value_type` constructed with
1024
  `value_type(std::forward<Args>(args)...)` after `position`.
1025
 
@@ -1027,11 +1068,11 @@ iterator in the range \[`begin()`, `end()`).
1027
 
1028
  ``` cpp
1029
  iterator erase_after(const_iterator position);
1030
  ```
1031
 
1032
- *Requires:* The iterator following `position` is dereferenceable.
1033
 
1034
  *Effects:* Erases the element pointed to by the iterator following
1035
  `position`.
1036
 
1037
  *Returns:* An iterator pointing to the element following the one that
@@ -1041,11 +1082,11 @@ was erased, or `end()` if no such element exists.
1041
 
1042
  ``` cpp
1043
  iterator erase_after(const_iterator position, const_iterator last);
1044
  ```
1045
 
1046
- *Requires:* All iterators in the range (`position`, `last`) are
1047
  dereferenceable.
1048
 
1049
  *Effects:* Erases the elements in the range (`position`, `last`).
1050
 
1051
  *Returns:* `last`.
@@ -1054,46 +1095,52 @@ dereferenceable.
1054
 
1055
  ``` cpp
1056
  void resize(size_type sz);
1057
  ```
1058
 
 
 
1059
  *Effects:* If `sz < distance(begin(), end())`, erases the last
1060
  `distance(begin(), end()) - sz` elements from the list. Otherwise,
1061
  inserts `sz - distance(begin(), end())` default-inserted elements at the
1062
  end of the list.
1063
 
1064
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
1065
-
1066
  ``` cpp
1067
  void resize(size_type sz, const value_type& c);
1068
  ```
1069
 
 
 
1070
  *Effects:* If `sz < distance(begin(), end())`, erases the last
1071
  `distance(begin(), end()) - sz` elements from the list. Otherwise,
1072
  inserts `sz - distance(begin(), end())` copies of `c` at the end of the
1073
  list.
1074
 
1075
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
1076
-
1077
  ``` cpp
1078
  void clear() noexcept;
1079
  ```
1080
 
1081
  *Effects:* Erases all elements in the range \[`begin()`, `end()`).
1082
 
1083
  *Remarks:* Does not invalidate past-the-end iterators.
1084
 
1085
- #### `forward_list` operations <a id="forwardlist.ops">[[forwardlist.ops]]</a>
 
 
 
 
 
1086
 
1087
  ``` cpp
1088
  void splice_after(const_iterator position, forward_list& x);
1089
  void splice_after(const_iterator position, forward_list&& x);
1090
  ```
1091
 
1092
- *Requires:* `position` is `before_begin()` or is a dereferenceable
1093
  iterator in the range \[`begin()`, `end()`).
1094
- `get_allocator() == x.get_allocator()`. `&x != this`.
 
1095
 
1096
  *Effects:* Inserts the contents of `x` after `position`, and `x` becomes
1097
  empty. Pointers and references to the moved elements of `x` now refer to
1098
  those same elements but as members of `*this`. Iterators referring to
1099
  the moved elements will continue to refer to their elements, but they
@@ -1106,14 +1153,14 @@ now behave as iterators into `*this`, not into `x`.
1106
  ``` cpp
1107
  void splice_after(const_iterator position, forward_list& x, const_iterator i);
1108
  void splice_after(const_iterator position, forward_list&& x, const_iterator i);
1109
  ```
1110
 
1111
- *Requires:* `position` is `before_begin()` or is a dereferenceable
1112
  iterator in the range \[`begin()`, `end()`). The iterator following `i`
1113
  is a dereferenceable iterator in `x`.
1114
- `get_allocator() == x.get_allocator()`.
1115
 
1116
  *Effects:* Inserts the element following `i` into `*this`, following
1117
  `position`, and removes it from `x`. The result is unchanged if
1118
  `position == i` or `position == ++i`. Pointers and references to `*++i`
1119
  continue to refer to the same element but as a member of `*this`.
@@ -1129,15 +1176,15 @@ void splice_after(const_iterator position, forward_list& x,
1129
  const_iterator first, const_iterator last);
1130
  void splice_after(const_iterator position, forward_list&& x,
1131
  const_iterator first, const_iterator last);
1132
  ```
1133
 
1134
- *Requires:* `position` is `before_begin()` or is a dereferenceable
1135
  iterator in the range \[`begin()`, `end()`). (`first`, `last`) is a
1136
  valid range in `x`, and all iterators in the range (`first`, `last`) are
1137
  dereferenceable. `position` is not an iterator in the range (`first`,
1138
- `last`). `get_allocator() == x.get_allocator()`.
1139
 
1140
  *Effects:* Inserts elements in the range (`first`, `last`) after
1141
  `position` and removes the elements from `x`. Pointers and references to
1142
  the moved elements of `x` now refer to those same elements but as
1143
  members of `*this`. Iterators referring to the moved elements will
@@ -1145,39 +1192,43 @@ continue to refer to their elements, but they now behave as iterators
1145
  into `*this`, not into `x`.
1146
 
1147
  *Complexity:* 𝑂(`distance(first, last)`)
1148
 
1149
  ``` cpp
1150
- void remove(const T& value);
1151
- template <class Predicate> void remove_if(Predicate pred);
1152
  ```
1153
 
1154
- *Effects:* Erases all the elements in the list referred by a list
1155
  iterator `i` for which the following conditions hold: `*i == value` (for
1156
  `remove()`), `pred(*i)` is `true` (for `remove_if()`). Invalidates only
1157
  the iterators and references to the erased elements.
1158
 
 
 
1159
  *Throws:* Nothing unless an exception is thrown by the equality
1160
  comparison or the predicate.
1161
 
1162
- *Remarks:* Stable ([[algorithm.stable]]).
1163
 
1164
  *Complexity:* Exactly `distance(begin(), end())` applications of the
1165
  corresponding predicate.
1166
 
1167
  ``` cpp
1168
- void unique();
1169
- template <class BinaryPredicate> void unique(BinaryPredicate pred);
1170
  ```
1171
 
1172
  *Effects:* Erases all but the first element from every consecutive group
1173
  of equal elements referred to by the iterator `i` in the range
1174
  \[`first + 1`, `last`) for which `*i == *(i-1)` (for the version with no
1175
  arguments) or `pred(*i, *(i - 1))` (for the version with a predicate
1176
  argument) holds. Invalidates only the iterators and references to the
1177
  erased elements.
1178
 
 
 
1179
  *Throws:* Nothing unless an exception is thrown by the equality
1180
  comparison or the predicate.
1181
 
1182
  *Complexity:* If the range \[`first`, `last`) is not empty, exactly
1183
  `(last - first) - 1` applications of the corresponding predicate,
@@ -1188,44 +1239,40 @@ void merge(forward_list& x);
1188
  void merge(forward_list&& x);
1189
  template<class Compare> void merge(forward_list& x, Compare comp);
1190
  template<class Compare> void merge(forward_list&& x, Compare comp);
1191
  ```
1192
 
1193
- *Requires:* `comp` defines a strict weak ordering ([[alg.sorting]]),
1194
- and `*this` and `x` are both sorted according to this ordering.
1195
- `get_allocator() == x.get_allocator()`.
 
1196
 
1197
  *Effects:* Merges the two sorted ranges `[begin(), end())` and
1198
  `[x.begin(), x.end())`. `x` is empty after the merge. If an exception is
1199
  thrown other than by a comparison there are no effects. Pointers and
1200
  references to the moved elements of `x` now refer to those same elements
1201
  but as members of `*this`. Iterators referring to the moved elements
1202
  will continue to refer to their elements, but they now behave as
1203
  iterators into `*this`, not into `x`.
1204
 
1205
- *Remarks:* Stable ([[algorithm.stable]]). The behavior is undefined if
1206
- `get_allocator() != x.get_allocator()`.
1207
 
1208
  *Complexity:* At most
1209
  `distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
1210
  comparisons.
1211
 
1212
  ``` cpp
1213
  void sort();
1214
  template<class Compare> void sort(Compare comp);
1215
  ```
1216
 
1217
- *Requires:* `operator<` (for the version with no arguments) or `comp`
1218
- (for the version with a comparison argument) defines a strict weak
1219
- ordering ([[alg.sorting]]).
1220
-
1221
  *Effects:* Sorts the list according to the `operator<` or the `comp`
1222
  function object. If an exception is thrown, the order of the elements in
1223
  `*this` is unspecified. Does not affect the validity of iterators and
1224
  references.
1225
 
1226
- *Remarks:* Stable ([[algorithm.stable]]).
1227
 
1228
  *Complexity:* Approximately N log N comparisons, where N is
1229
  `distance(begin(), end())`.
1230
 
1231
  ``` cpp
@@ -1235,48 +1282,55 @@ void reverse() noexcept;
1235
  *Effects:* Reverses the order of the elements in the list. Does not
1236
  affect the validity of iterators and references.
1237
 
1238
  *Complexity:* Linear time.
1239
 
1240
- #### `forward_list` specialized algorithms <a id="forwardlist.spec">[[forwardlist.spec]]</a>
1241
 
1242
  ``` cpp
1243
- template <class T, class Allocator>
1244
- void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
1245
- noexcept(noexcept(x.swap(y)));
1246
  ```
1247
 
1248
- *Effects:* As if by `x.swap(y)`.
 
 
 
 
 
 
 
 
 
1249
 
1250
  ### Class template `list` <a id="list">[[list]]</a>
1251
 
1252
- #### Class template `list` overview <a id="list.overview">[[list.overview]]</a>
1253
 
1254
  A `list` is a sequence container that supports bidirectional iterators
1255
  and allows constant time insert and erase operations anywhere within the
1256
- sequence, with storage management handled automatically. Unlike
1257
- vectors ([[vector]]) and deques ([[deque]]), fast random access to
1258
- list elements is not supported, but many algorithms only need sequential
1259
- access anyway.
1260
 
1261
- A `list` satisfies all of the requirements of a container, of a
1262
- reversible container (given in two tables in
1263
- [[container.requirements]]), of a sequence container, including most of
1264
- the optional sequence container requirements ([[sequence.reqmts]]), and
1265
- of an allocator-aware container (Table 
1266
- [[tab:containers.allocatoraware]]). The exceptions are the `operator[]`
1267
- and `at` member functions, which are not provided.[^2] Descriptions are
1268
- provided here only for operations on `list` that are not described in
1269
- one of these tables or for operations where there is additional semantic
1270
  information.
1271
 
1272
  ``` cpp
1273
  namespace std {
1274
  template<class T, class Allocator = allocator<T>>
1275
  class list {
1276
  public:
1277
- // types:
1278
  using value_type = T;
1279
  using allocator_type = Allocator;
1280
  using pointer = typename allocator_traits<Allocator>::pointer;
1281
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
1282
  using reference = value_type&;
@@ -1309,11 +1363,11 @@ namespace std {
1309
  void assign(InputIterator first, InputIterator last);
1310
  void assign(size_type n, const T& t);
1311
  void assign(initializer_list<T>);
1312
  allocator_type get_allocator() const noexcept;
1313
 
1314
- // iterators:
1315
  iterator begin() noexcept;
1316
  const_iterator begin() const noexcept;
1317
  iterator end() noexcept;
1318
  const_iterator end() const noexcept;
1319
  reverse_iterator rbegin() noexcept;
@@ -1325,17 +1379,17 @@ namespace std {
1325
  const_iterator cend() const noexcept;
1326
  const_reverse_iterator crbegin() const noexcept;
1327
  const_reverse_iterator crend() const noexcept;
1328
 
1329
  // [list.capacity], capacity
1330
- bool empty() const noexcept;
1331
  size_type size() const noexcept;
1332
  size_type max_size() const noexcept;
1333
  void resize(size_type sz);
1334
  void resize(size_type sz, const T& c);
1335
 
1336
- // element access:
1337
  reference front();
1338
  const_reference front() const;
1339
  reference back();
1340
  const_reference back() const;
1341
 
@@ -1352,36 +1406,32 @@ namespace std {
1352
  template<class... Args> iterator emplace(const_iterator position, Args&&... args);
1353
  iterator insert(const_iterator position, const T& x);
1354
  iterator insert(const_iterator position, T&& x);
1355
  iterator insert(const_iterator position, size_type n, const T& x);
1356
  template<class InputIterator>
1357
- iterator insert(const_iterator position, InputIterator first,
1358
- InputIterator last);
1359
  iterator insert(const_iterator position, initializer_list<T> il);
1360
 
1361
  iterator erase(const_iterator position);
1362
  iterator erase(const_iterator position, const_iterator last);
1363
- void swap(list&)
1364
- noexcept(allocator_traits<Allocator>::is_always_equal::value);
1365
  void clear() noexcept;
1366
 
1367
  // [list.ops], list operations
1368
  void splice(const_iterator position, list& x);
1369
  void splice(const_iterator position, list&& x);
1370
  void splice(const_iterator position, list& x, const_iterator i);
1371
  void splice(const_iterator position, list&& x, const_iterator i);
1372
- void splice(const_iterator position, list& x,
1373
- const_iterator first, const_iterator last);
1374
- void splice(const_iterator position, list&& x,
1375
- const_iterator first, const_iterator last);
1376
 
1377
- void remove(const T& value);
1378
- template <class Predicate> void remove_if(Predicate pred);
1379
 
1380
- void unique();
1381
  template<class BinaryPredicate>
1382
- void unique(BinaryPredicate binary_pred);
1383
 
1384
  void merge(list& x);
1385
  void merge(list&& x);
1386
  template<class Compare> void merge(list& x, Compare comp);
1387
  template<class Compare> void merge(list&& x, Compare comp);
@@ -1390,41 +1440,27 @@ namespace std {
1390
  template<class Compare> void sort(Compare comp);
1391
 
1392
  void reverse() noexcept;
1393
  };
1394
 
1395
- template<class InputIterator,
1396
- class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
1397
  list(InputIterator, InputIterator, Allocator = Allocator())
1398
- -> list<typename iterator_traits<InputIterator>::value_type, Allocator>;
1399
 
1400
- template <class T, class Allocator>
1401
- bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
1402
- template <class T, class Allocator>
1403
- bool operator< (const list<T, Allocator>& x, const list<T, Allocator>& y);
1404
- template <class T, class Allocator>
1405
- bool operator!=(const list<T, Allocator>& x, const list<T, Allocator>& y);
1406
- template <class T, class Allocator>
1407
- bool operator> (const list<T, Allocator>& x, const list<T, Allocator>& y);
1408
- template <class T, class Allocator>
1409
- bool operator>=(const list<T, Allocator>& x, const list<T, Allocator>& y);
1410
- template <class T, class Allocator>
1411
- bool operator<=(const list<T, Allocator>& x, const list<T, Allocator>& y);
1412
-
1413
- // [list.special], specialized algorithms
1414
  template<class T, class Allocator>
1415
  void swap(list<T, Allocator>& x, list<T, Allocator>& y)
1416
  noexcept(noexcept(x.swap(y)));
1417
  }
1418
  ```
1419
 
1420
  An incomplete type `T` may be used when instantiating `list` if the
1421
- allocator satisfies the allocator completeness requirements (
1422
- [[allocator.requirements.completeness]]). `T` shall be complete before
1423
  any member of the resulting specialization of `list` is referenced.
1424
 
1425
- #### `list` constructors, copy, and assignment <a id="list.cons">[[list.cons]]</a>
1426
 
1427
  ``` cpp
1428
  explicit list(const Allocator&);
1429
  ```
1430
 
@@ -1434,26 +1470,26 @@ explicit list(const Allocator&);
1434
 
1435
  ``` cpp
1436
  explicit list(size_type n, const Allocator& = Allocator());
1437
  ```
1438
 
 
 
1439
  *Effects:* Constructs a `list` with `n` default-inserted elements using
1440
  the specified allocator.
1441
 
1442
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
1443
-
1444
  *Complexity:* Linear in `n`.
1445
 
1446
  ``` cpp
1447
  list(size_type n, const T& value, const Allocator& = Allocator());
1448
  ```
1449
 
 
 
1450
  *Effects:* Constructs a `list` with `n` copies of `value`, using the
1451
  specified allocator.
1452
 
1453
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
1454
-
1455
  *Complexity:* Linear in `n`.
1456
 
1457
  ``` cpp
1458
  template<class InputIterator>
1459
  list(InputIterator first, InputIterator last, const Allocator& = Allocator());
@@ -1461,31 +1497,33 @@ template <class InputIterator>
1461
 
1462
  *Effects:* Constructs a `list` equal to the range \[`first`, `last`).
1463
 
1464
  *Complexity:* Linear in `distance(first, last)`.
1465
 
1466
- #### `list` capacity <a id="list.capacity">[[list.capacity]]</a>
1467
 
1468
  ``` cpp
1469
  void resize(size_type sz);
1470
  ```
1471
 
 
 
1472
  *Effects:* If `size() < sz`, appends `sz - size()` default-inserted
1473
  elements to the sequence. If `sz <= size()`, equivalent to:
1474
 
1475
  ``` cpp
1476
  list<T>::iterator it = begin();
1477
  advance(it, sz);
1478
  erase(it, end());
1479
  ```
1480
 
1481
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
1482
-
1483
  ``` cpp
1484
  void resize(size_type sz, const T& c);
1485
  ```
1486
 
 
 
1487
  *Effects:* As if by:
1488
 
1489
  ``` cpp
1490
  if (sz > size())
1491
  insert(end(), sz-size(), c);
@@ -1496,13 +1534,11 @@ else if (sz < size()) {
1496
  }
1497
  else
1498
  ; // do nothing
1499
  ```
1500
 
1501
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
1502
-
1503
- #### `list` modifiers <a id="list.modifiers">[[list.modifiers]]</a>
1504
 
1505
  ``` cpp
1506
  iterator insert(const_iterator position, const T& x);
1507
  iterator insert(const_iterator position, T&& x);
1508
  iterator insert(const_iterator position, size_type n, const T& x);
@@ -1546,14 +1582,18 @@ elements.
1546
  *Complexity:* Erasing a single element is a constant time operation with
1547
  a single call to the destructor of `T`. Erasing a range in a list is
1548
  linear time in the size of the range and the number of calls to the
1549
  destructor of type `T` is exactly equal to the size of the range.
1550
 
1551
- #### `list` operations <a id="list.ops">[[list.ops]]</a>
1552
 
1553
  Since lists allow fast insertion and erasing from the middle of a list,
1554
- certain operations are provided specifically for them.[^3]
 
 
 
 
1555
 
1556
  `list` provides three splice operations that destructively move elements
1557
  from one list to another. The behavior of splice operations is undefined
1558
  if `get_allocator() !=
1559
  x.get_allocator()`.
@@ -1561,11 +1601,11 @@ x.get_allocator()`.
1561
  ``` cpp
1562
  void splice(const_iterator position, list& x);
1563
  void splice(const_iterator position, list&& x);
1564
  ```
1565
 
1566
- *Requires:* `&x != this`.
1567
 
1568
  *Effects:* Inserts the contents of `x` before `position` and `x` becomes
1569
  empty. Pointers and references to the moved elements of `x` now refer to
1570
  those same elements but as members of `*this`. Iterators referring to
1571
  the moved elements will continue to refer to their elements, but they
@@ -1578,11 +1618,11 @@ now behave as iterators into `*this`, not into `x`.
1578
  ``` cpp
1579
  void splice(const_iterator position, list& x, const_iterator i);
1580
  void splice(const_iterator position, list&& x, const_iterator i);
1581
  ```
1582
 
1583
- *Requires:* `i` is a valid dereferenceable iterator of `x`.
1584
 
1585
  *Effects:* Inserts an element pointed to by `i` from list `x` before
1586
  `position` and removes the element from `x`. The result is unchanged if
1587
  `position == i` or `position == ++i`. Pointers and references to `*i`
1588
  continue to refer to this same element but as a member of `*this`.
@@ -1598,55 +1638,59 @@ void splice(const_iterator position, list& x, const_iterator first,
1598
  const_iterator last);
1599
  void splice(const_iterator position, list&& x, const_iterator first,
1600
  const_iterator last);
1601
  ```
1602
 
1603
- *Requires:* `[first, last)` is a valid range in `x`. The program has
1604
- undefined behavior if `position` is an iterator in the range \[`first`,
1605
- `last`).
1606
 
1607
  *Effects:* Inserts elements in the range \[`first`, `last`) before
1608
  `position` and removes the elements from `x`. Pointers and references to
1609
  the moved elements of `x` now refer to those same elements but as
1610
  members of `*this`. Iterators referring to the moved elements will
1611
  continue to refer to their elements, but they now behave as iterators
1612
  into `*this`, not into `x`.
1613
 
1614
  *Throws:* Nothing.
1615
 
1616
- *Complexity:* Constant time if `&x == this`; otherwise, linear time.
 
1617
 
1618
  ``` cpp
1619
- void remove(const T& value);
1620
- template <class Predicate> void remove_if(Predicate pred);
1621
  ```
1622
 
1623
- *Effects:* Erases all the elements in the list referred by a list
1624
- iterator `i` for which the following conditions hold:
1625
- `*i == value, pred(*i) != false`. Invalidates only the iterators and
1626
- references to the erased elements.
 
 
1627
 
1628
  *Throws:* Nothing unless an exception is thrown by `*i == value` or
1629
  `pred(*i) != false`.
1630
 
1631
- *Remarks:* Stable ([[algorithm.stable]]).
1632
 
1633
  *Complexity:* Exactly `size()` applications of the corresponding
1634
  predicate.
1635
 
1636
  ``` cpp
1637
- void unique();
1638
- template <class BinaryPredicate> void unique(BinaryPredicate binary_pred);
1639
  ```
1640
 
1641
  *Effects:* Erases all but the first element from every consecutive group
1642
  of equal elements referred to by the iterator `i` in the range
1643
  \[`first + 1`, `last`) for which `*i == *(i-1)` (for the version of
1644
  `unique` with no arguments) or `pred(*i, *(i - 1))` (for the version of
1645
  `unique` with a predicate argument) holds. Invalidates only the
1646
  iterators and references to the erased elements.
1647
 
 
 
1648
  *Throws:* Nothing unless an exception is thrown by `*i == *(i-1)` or
1649
  `pred(*i, *(i - 1))`
1650
 
1651
  *Complexity:* If the range `[first, last)` is not empty, exactly
1652
  `(last - first) - 1` applications of the corresponding predicate,
@@ -1657,33 +1701,34 @@ void merge(list& x);
1657
  void merge(list&& x);
1658
  template<class Compare> void merge(list& x, Compare comp);
1659
  template<class Compare> void merge(list&& x, Compare comp);
1660
  ```
1661
 
1662
- *Requires:* `comp` shall define a strict weak
1663
- ordering ([[alg.sorting]]), and both the list and the argument list
1664
- shall be sorted according to this ordering.
 
1665
 
1666
- *Effects:* If `(&x == this)` does nothing; otherwise, merges the two
1667
- sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The result
1668
- is a range in which the elements will be sorted in non-decreasing order
1669
- according to the ordering defined by `comp`; that is, for every iterator
1670
- `i`, in the range other than the first, the condition
1671
  `comp(*i, *(i - 1))` will be `false`. Pointers and references to the
1672
  moved elements of `x` now refer to those same elements but as members of
1673
  `*this`. Iterators referring to the moved elements will continue to
1674
  refer to their elements, but they now behave as iterators into `*this`,
1675
  not into `x`.
1676
 
1677
- *Remarks:* Stable ([[algorithm.stable]]). If `(&x != this)` the range
1678
- `[x.begin(), x.end())` is empty after the merge. No elements are copied
1679
- by this operation. The behavior is undefined if
1680
- `get_allocator() != x.get_allocator()`.
1681
 
1682
  *Complexity:* At most `size() + x.size() - 1` applications of `comp` if
1683
- `(&x != this)`; otherwise, no applications of `comp` are performed. If
1684
- an exception is thrown other than by a comparison there are no effects.
 
1685
 
1686
  ``` cpp
1687
  void reverse() noexcept;
1688
  ```
1689
 
@@ -1695,59 +1740,68 @@ affect the validity of iterators and references.
1695
  ``` cpp
1696
  void sort();
1697
  template<class Compare> void sort(Compare comp);
1698
  ```
1699
 
1700
- *Requires:* `operator<` (for the first version) or `comp` (for the
1701
- second version) shall define a strict weak ordering ([[alg.sorting]]).
1702
-
1703
  *Effects:* Sorts the list according to the `operator<` or a `Compare`
1704
  function object. If an exception is thrown, the order of the elements in
1705
  `*this` is unspecified. Does not affect the validity of iterators and
1706
  references.
1707
 
1708
- *Remarks:* Stable ([[algorithm.stable]]).
1709
 
1710
  *Complexity:* Approximately N log N comparisons, where `N == size()`.
1711
 
1712
- #### `list` specialized algorithms <a id="list.special">[[list.special]]</a>
1713
 
1714
  ``` cpp
1715
- template <class T, class Allocator>
1716
- void swap(list<T, Allocator>& x, list<T, Allocator>& y)
1717
- noexcept(noexcept(x.swap(y)));
1718
  ```
1719
 
1720
- *Effects:* As if by `x.swap(y)`.
 
 
 
 
 
 
 
 
 
1721
 
1722
  ### Class template `vector` <a id="vector">[[vector]]</a>
1723
 
1724
- #### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
1725
 
1726
  A `vector` is a sequence container that supports (amortized) constant
1727
  time insert and erase operations at the end; insert and erase in the
1728
  middle take linear time. Storage management is handled automatically,
1729
  though hints can be given to improve efficiency.
1730
 
1731
- A `vector` satisfies all of the requirements of a container and of a
1732
  reversible container (given in two tables in 
1733
  [[container.requirements]]), of a sequence container, including most of
1734
- the optional sequence container requirements ([[sequence.reqmts]]), of
1735
- an allocator-aware container (Table  [[tab:containers.allocatoraware]]),
1736
- and, for an element type other than `bool`, of a contiguous container (
1737
- [[container.requirements.general]]). The exceptions are the
1738
- `push_front`, `pop_front`, and `emplace_front` member functions, which
1739
- are not provided. Descriptions are provided here only for operations on
1740
- `vector` that are not described in one of these tables or for operations
1741
- where there is additional semantic information.
 
 
 
1742
 
1743
  ``` cpp
1744
  namespace std {
1745
  template<class T, class Allocator = allocator<T>>
1746
  class vector {
1747
  public:
1748
- // types:
1749
  using value_type = T;
1750
  using allocator_type = Allocator;
1751
  using pointer = typename allocator_traits<Allocator>::pointer;
1752
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
1753
  using reference = value_type&;
@@ -1758,159 +1812,146 @@ namespace std {
1758
  using const_iterator = implementation-defined // type of vector::const_iterator; // see [container.requirements]
1759
  using reverse_iterator = std::reverse_iterator<iterator>;
1760
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1761
 
1762
  // [vector.cons], construct/copy/destroy
1763
- vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
1764
- explicit vector(const Allocator&) noexcept;
1765
- explicit vector(size_type n, const Allocator& = Allocator());
1766
- vector(size_type n, const T& value, const Allocator& = Allocator());
1767
  template<class InputIterator>
1768
- vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
1769
- vector(const vector& x);
1770
- vector(vector&&) noexcept;
1771
- vector(const vector&, const Allocator&);
1772
- vector(vector&&, const Allocator&);
1773
- vector(initializer_list<T>, const Allocator& = Allocator());
1774
- ~vector();
1775
- vector& operator=(const vector& x);
1776
- vector& operator=(vector&& x)
1777
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
1778
  allocator_traits<Allocator>::is_always_equal::value);
1779
- vector& operator=(initializer_list<T>);
1780
  template<class InputIterator>
1781
- void assign(InputIterator first, InputIterator last);
1782
- void assign(size_type n, const T& u);
1783
- void assign(initializer_list<T>);
1784
- allocator_type get_allocator() const noexcept;
1785
 
1786
- // iterators:
1787
- iterator begin() noexcept;
1788
- const_iterator begin() const noexcept;
1789
- iterator end() noexcept;
1790
- const_iterator end() const noexcept;
1791
- reverse_iterator rbegin() noexcept;
1792
- const_reverse_iterator rbegin() const noexcept;
1793
- reverse_iterator rend() noexcept;
1794
- const_reverse_iterator rend() const noexcept;
1795
 
1796
- const_iterator cbegin() const noexcept;
1797
- const_iterator cend() const noexcept;
1798
- const_reverse_iterator crbegin() const noexcept;
1799
- const_reverse_iterator crend() const noexcept;
1800
 
1801
  // [vector.capacity], capacity
1802
- bool empty() const noexcept;
1803
- size_type size() const noexcept;
1804
- size_type max_size() const noexcept;
1805
- size_type capacity() const noexcept;
1806
- void resize(size_type sz);
1807
- void resize(size_type sz, const T& c);
1808
- void reserve(size_type n);
1809
- void shrink_to_fit();
1810
 
1811
- // element access:
1812
- reference operator[](size_type n);
1813
- const_reference operator[](size_type n) const;
1814
- const_reference at(size_type n) const;
1815
- reference at(size_type n);
1816
- reference front();
1817
- const_reference front() const;
1818
- reference back();
1819
- const_reference back() const;
1820
 
1821
  // [vector.data], data access
1822
- T* data() noexcept;
1823
- const T* data() const noexcept;
1824
 
1825
  // [vector.modifiers], modifiers
1826
- template <class... Args> reference emplace_back(Args&&... args);
1827
- void push_back(const T& x);
1828
- void push_back(T&& x);
1829
- void pop_back();
1830
 
1831
- template <class... Args> iterator emplace(const_iterator position, Args&&... args);
1832
- iterator insert(const_iterator position, const T& x);
1833
- iterator insert(const_iterator position, T&& x);
1834
- iterator insert(const_iterator position, size_type n, const T& x);
1835
  template<class InputIterator>
1836
- iterator insert(const_iterator position, InputIterator first, InputIterator last);
1837
- iterator insert(const_iterator position, initializer_list<T> il);
1838
- iterator erase(const_iterator position);
1839
- iterator erase(const_iterator first, const_iterator last);
1840
- void swap(vector&)
 
1841
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1842
  allocator_traits<Allocator>::is_always_equal::value);
1843
- void clear() noexcept;
1844
  };
1845
 
1846
- template<class InputIterator,
1847
- class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
1848
  vector(InputIterator, InputIterator, Allocator = Allocator())
1849
- -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
1850
 
 
1851
  template<class T, class Allocator>
1852
- bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
1853
- template <class T, class Allocator>
1854
- bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
1855
- template <class T, class Allocator>
1856
- bool operator!=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
1857
- template <class T, class Allocator>
1858
- bool operator> (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
1859
- template <class T, class Allocator>
1860
- bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
1861
- template <class T, class Allocator>
1862
- bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
1863
-
1864
- // [vector.special], specialized algorithms
1865
- template <class T, class Allocator>
1866
- void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
1867
  noexcept(noexcept(x.swap(y)));
1868
  }
1869
  ```
1870
 
1871
  An incomplete type `T` may be used when instantiating `vector` if the
1872
- allocator satisfies the allocator completeness requirements (
1873
- [[allocator.requirements.completeness]]). `T` shall be complete before
1874
  any member of the resulting specialization of `vector` is referenced.
1875
 
1876
- #### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
1877
 
1878
  ``` cpp
1879
- explicit vector(const Allocator&);
1880
  ```
1881
 
1882
  *Effects:* Constructs an empty `vector`, using the specified allocator.
1883
 
1884
  *Complexity:* Constant.
1885
 
1886
  ``` cpp
1887
- explicit vector(size_type n, const Allocator& = Allocator());
1888
  ```
1889
 
 
 
1890
  *Effects:* Constructs a `vector` with `n` default-inserted elements
1891
  using the specified allocator.
1892
 
1893
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
1894
-
1895
  *Complexity:* Linear in `n`.
1896
 
1897
  ``` cpp
1898
- vector(size_type n, const T& value,
1899
  const Allocator& = Allocator());
1900
  ```
1901
 
 
 
1902
  *Effects:* Constructs a `vector` with `n` copies of `value`, using the
1903
  specified allocator.
1904
 
1905
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
1906
-
1907
  *Complexity:* Linear in `n`.
1908
 
1909
  ``` cpp
1910
  template<class InputIterator>
1911
- vector(InputIterator first, InputIterator last,
1912
  const Allocator& = Allocator());
1913
  ```
1914
 
1915
  *Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
1916
  using the specified allocator.
@@ -1919,152 +1960,166 @@ using the specified allocator.
1919
  is the distance between `first` and `last`) and no reallocations if
1920
  iterators `first` and `last` are of forward, bidirectional, or random
1921
  access categories. It makes order `N` calls to the copy constructor of
1922
  `T` and order log N reallocations if they are just input iterators.
1923
 
1924
- #### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
1925
 
1926
  ``` cpp
1927
- size_type capacity() const noexcept;
1928
  ```
1929
 
1930
  *Returns:* The total number of elements that the vector can hold without
1931
  requiring reallocation.
1932
 
 
 
1933
  ``` cpp
1934
- void reserve(size_type n);
1935
  ```
1936
 
1937
- *Requires:* `T` shall be `MoveInsertable` into `*this`.
1938
 
1939
  *Effects:* A directive that informs a `vector` of a planned change in
1940
  size, so that it can manage the storage allocation accordingly. After
1941
  `reserve()`, `capacity()` is greater or equal to the argument of
1942
  `reserve` if reallocation happens; and equal to the previous value of
1943
  `capacity()` otherwise. Reallocation happens at this point if and only
1944
  if the current capacity is less than the argument of `reserve()`. If an
1945
  exception is thrown other than by the move constructor of a
1946
- non-`CopyInsertable` type, there are no effects.
1947
 
1948
  *Complexity:* It does not change the size of the sequence and takes at
1949
  most linear time in the size of the sequence.
1950
 
1951
  *Throws:* `length_error` if `n > max_size()`.[^4]
1952
 
1953
  *Remarks:* Reallocation invalidates all the references, pointers, and
1954
- iterators referring to the elements in the sequence. No reallocation
1955
- shall take place during insertions that happen after a call to
1956
- `reserve()` until the time when an insertion would make the size of the
1957
- vector greater than the value of `capacity()`.
 
 
 
 
 
1958
 
1959
  ``` cpp
1960
- void shrink_to_fit();
1961
  ```
1962
 
1963
- *Requires:* `T` shall be `MoveInsertable` into `*this`.
1964
 
1965
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
1966
  `capacity()` to `size()`.
1967
 
1968
- [*Note 1*: The request is non-binding to allow latitude for
1969
  implementation-specific optimizations. — *end note*]
1970
 
1971
  It does not increase `capacity()`, but may reduce `capacity()` by
1972
  causing reallocation. If an exception is thrown other than by the move
1973
- constructor of a non-`CopyInsertable` `T` there are no effects.
1974
 
1975
- *Complexity:* Linear in the size of the sequence.
 
1976
 
1977
  *Remarks:* Reallocation invalidates all the references, pointers, and
1978
  iterators referring to the elements in the sequence as well as the
1979
- past-the-end iterator. If no reallocation happens, they remain valid.
 
 
 
1980
 
1981
  ``` cpp
1982
- void swap(vector& x)
1983
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1984
  allocator_traits<Allocator>::is_always_equal::value);
1985
  ```
1986
 
1987
  *Effects:* Exchanges the contents and `capacity()` of `*this` with that
1988
  of `x`.
1989
 
1990
  *Complexity:* Constant time.
1991
 
1992
  ``` cpp
1993
- void resize(size_type sz);
1994
  ```
1995
 
 
 
 
1996
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
1997
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
1998
  to the sequence.
1999
 
2000
- *Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
2001
- `*this`.
2002
-
2003
  *Remarks:* If an exception is thrown other than by the move constructor
2004
- of a non-`CopyInsertable` `T` there are no effects.
2005
 
2006
  ``` cpp
2007
- void resize(size_type sz, const T& c);
2008
  ```
2009
 
 
 
2010
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
2011
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
2012
  sequence.
2013
 
2014
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
2015
-
2016
  *Remarks:* If an exception is thrown there are no effects.
2017
 
2018
- #### `vector` data <a id="vector.data">[[vector.data]]</a>
2019
 
2020
  ``` cpp
2021
- T* data() noexcept;
2022
- const T* data() const noexcept;
2023
  ```
2024
 
2025
  *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
2026
  range. For a non-empty vector, `data()` `==` `addressof(front())`.
2027
 
2028
  *Complexity:* Constant time.
2029
 
2030
- #### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
2031
 
2032
  ``` cpp
2033
- iterator insert(const_iterator position, const T& x);
2034
- iterator insert(const_iterator position, T&& x);
2035
- iterator insert(const_iterator position, size_type n, const T& x);
2036
  template<class InputIterator>
2037
- iterator insert(const_iterator position, InputIterator first, InputIterator last);
2038
- iterator insert(const_iterator position, initializer_list<T>);
2039
 
2040
- template <class... Args> reference emplace_back(Args&&... args);
2041
- template <class... Args> iterator emplace(const_iterator position, Args&&... args);
2042
- void push_back(const T& x);
2043
- void push_back(T&& x);
2044
  ```
2045
 
2046
  *Remarks:* Causes reallocation if the new size is greater than the old
2047
  capacity. Reallocation invalidates all the references, pointers, and
2048
- iterators referring to the elements in the sequence. If no reallocation
2049
- happens, all the iterators and references before the insertion point
2050
- remain valid. If an exception is thrown other than by the copy
2051
- constructor, move constructor, assignment operator, or move assignment
2052
- operator of `T` or by any `InputIterator` operation there are no
2053
- effects. If an exception is thrown while inserting a single element at
2054
- the end and `T` is `CopyInsertable` or
 
 
2055
  `is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
2056
  Otherwise, if an exception is thrown by the move constructor of a
2057
- non-`CopyInsertable` `T`, the effects are unspecified.
2058
 
2059
- *Complexity:* The complexity is linear in the number of elements
 
2060
  inserted plus the distance to the end of the vector.
2061
 
2062
  ``` cpp
2063
- iterator erase(const_iterator position);
2064
- iterator erase(const_iterator first, const_iterator last);
2065
- void pop_back();
2066
  ```
2067
 
2068
  *Effects:* Invalidates iterators and references at or after the point of
2069
  the erase.
2070
 
@@ -2074,19 +2129,41 @@ is called the number of times equal to the number of elements in the
2074
  vector after the erased elements.
2075
 
2076
  *Throws:* Nothing unless an exception is thrown by the assignment
2077
  operator or move assignment operator of `T`.
2078
 
2079
- #### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
2080
 
2081
  ``` cpp
2082
- template <class T, class Allocator>
2083
- void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
2084
- noexcept(noexcept(x.swap(y)));
2085
  ```
2086
 
2087
- *Effects:* As if by `x.swap(y)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2088
 
2089
  ### Class `vector<bool>` <a id="vector.bool">[[vector.bool]]</a>
2090
 
2091
  To optimize space allocation, a specialization of vector for `bool`
2092
  elements is provided:
@@ -2094,11 +2171,11 @@ elements is provided:
2094
  ``` cpp
2095
  namespace std {
2096
  template<class Allocator>
2097
  class vector<bool, Allocator> {
2098
  public:
2099
- // types:
2100
  using value_type = bool;
2101
  using allocator_type = Allocator;
2102
  using pointer = implementation-defined;
2103
  using const_pointer = implementation-defined;
2104
  using const_reference = bool;
@@ -2107,107 +2184,106 @@ namespace std {
2107
  using iterator = implementation-defined // type of vector<bool>::iterator; // see [container.requirements]
2108
  using const_iterator = implementation-defined // type of vector<bool>::const_iterator; // see [container.requirements]
2109
  using reverse_iterator = std::reverse_iterator<iterator>;
2110
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
2111
 
2112
- // bit reference:
2113
  class reference {
2114
  friend class vector;
2115
- reference() noexcept;
2116
  public:
2117
- ~reference();
2118
- operator bool() const noexcept;
2119
- reference& operator=(const bool x) noexcept;
2120
- reference& operator=(const reference& x) noexcept;
2121
- void flip() noexcept; // flips the bit
 
2122
  };
2123
 
2124
- // construct/copy/destroy:
2125
- vector() : vector(Allocator()) { }
2126
- explicit vector(const Allocator&);
2127
- explicit vector(size_type n, const Allocator& = Allocator());
2128
- vector(size_type n, const bool& value,
2129
- const Allocator& = Allocator());
2130
  template<class InputIterator>
2131
- vector(InputIterator first, InputIterator last,
2132
- const Allocator& = Allocator());
2133
- vector(const vector<bool, Allocator>& x);
2134
- vector(vector<bool, Allocator>&& x);
2135
- vector(const vector&, const Allocator&);
2136
- vector(vector&&, const Allocator&);
2137
- vector(initializer_list<bool>, const Allocator& = Allocator()));
2138
- ~vector();
2139
- vector<bool, Allocator>& operator=(const vector<bool, Allocator>& x);
2140
- vector<bool, Allocator>& operator=(vector<bool, Allocator>&& x);
2141
- vector& operator=(initializer_list<bool>);
2142
  template<class InputIterator>
2143
- void assign(InputIterator first, InputIterator last);
2144
- void assign(size_type n, const bool& t);
2145
- void assign(initializer_list<bool>);
2146
- allocator_type get_allocator() const noexcept;
2147
 
2148
- // iterators:
2149
- iterator begin() noexcept;
2150
- const_iterator begin() const noexcept;
2151
- iterator end() noexcept;
2152
- const_iterator end() const noexcept;
2153
- reverse_iterator rbegin() noexcept;
2154
- const_reverse_iterator rbegin() const noexcept;
2155
- reverse_iterator rend() noexcept;
2156
- const_reverse_iterator rend() const noexcept;
2157
 
2158
- const_iterator cbegin() const noexcept;
2159
- const_iterator cend() const noexcept;
2160
- const_reverse_iterator crbegin() const noexcept;
2161
- const_reverse_iterator crend() const noexcept;
2162
 
2163
- // capacity:
2164
- bool empty() const noexcept;
2165
- size_type size() const noexcept;
2166
- size_type max_size() const noexcept;
2167
- size_type capacity() const noexcept;
2168
- void resize(size_type sz, bool c = false);
2169
- void reserve(size_type n);
2170
- void shrink_to_fit();
2171
 
2172
- // element access:
2173
- reference operator[](size_type n);
2174
- const_reference operator[](size_type n) const;
2175
- const_reference at(size_type n) const;
2176
- reference at(size_type n);
2177
- reference front();
2178
- const_reference front() const;
2179
- reference back();
2180
- const_reference back() const;
2181
 
2182
- // modifiers:
2183
- template <class... Args> reference emplace_back(Args&&... args);
2184
- void push_back(const bool& x);
2185
- void pop_back();
2186
- template <class... Args> iterator emplace(const_iterator position, Args&&... args);
2187
- iterator insert(const_iterator position, const bool& x);
2188
- iterator insert(const_iterator position, size_type n, const bool& x);
2189
  template<class InputIterator>
2190
- iterator insert(const_iterator position,
2191
  InputIterator first, InputIterator last);
2192
- iterator insert(const_iterator position, initializer_list<bool> il);
2193
 
2194
- iterator erase(const_iterator position);
2195
- iterator erase(const_iterator first, const_iterator last);
2196
- void swap(vector<bool, Allocator>&);
2197
- static void swap(reference x, reference y) noexcept;
2198
- void flip() noexcept; // flips all bits
2199
- void clear() noexcept;
2200
  };
2201
  }
2202
  ```
2203
 
2204
  Unless described below, all operations have the same requirements and
2205
  semantics as the primary `vector` template, except that operations
2206
  dealing with the `bool` value type map to bit values in the container
2207
- storage and `allocator_traits::construct` (
2208
- [[allocator.traits.members]]) is not used to construct these values.
2209
 
2210
  There is no requirement that the data be stored as a contiguous
2211
  allocation of `bool` values. A space-optimized representation of bits is
2212
  recommended instead.
2213
 
@@ -2218,17 +2294,17 @@ is a class that simulates the behavior of references of a single bit in
2218
  set, and `false` otherwise. The assignment operator sets the bit when
2219
  the argument is (convertible to) `true` and clears it otherwise. `flip`
2220
  reverses the state of the bit.
2221
 
2222
  ``` cpp
2223
- void flip() noexcept;
2224
  ```
2225
 
2226
  *Effects:* Replaces each element in the container with its complement.
2227
 
2228
  ``` cpp
2229
- static void swap(reference x, reference y) noexcept;
2230
  ```
2231
 
2232
  *Effects:* Exchanges the contents of `x` and `y` as if by:
2233
 
2234
  ``` cpp
@@ -2239,7 +2315,7 @@ y = b;
2239
 
2240
  ``` cpp
2241
  template<class Allocator> struct hash<vector<bool, Allocator>>;
2242
  ```
2243
 
2244
- The specialization is enabled ([[unord.hash]]).
2245
 
 
4
 
5
  The headers `<array>`, `<deque>`, `<forward_list>`, `<list>`, and
6
  `<vector>` define class templates that meet the requirements for
7
  sequence containers.
8
 
9
+ The following exposition-only alias template may appear in deduction
10
+ guides for sequence containers:
11
+
12
+ ``` cpp
13
+ template<class InputIterator>
14
+ using iter-value-type = typename iterator_traits<InputIterator>::value_type; // exposition only
15
+ ```
16
+
17
  ### Header `<array>` synopsis <a id="array.syn">[[array.syn]]</a>
18
 
19
  ``` cpp
20
+ #include <compare> // see [compare.syn]
21
+ #include <initializer_list> // see [initializer.list.syn]
22
 
23
  namespace std {
24
  // [array], class template array
25
  template<class T, size_t N> struct array;
26
+
27
  template<class T, size_t N>
28
+ constexpr bool operator==(const array<T, N>& x, const array<T, N>& y);
 
 
 
 
29
  template<class T, size_t N>
30
+ constexpr synth-three-way-result<T>
31
+ operator<=>(const array<T, N>& x, const array<T, N>& y);
32
+
33
+ // [array.special], specialized algorithms
34
  template<class T, size_t N>
35
+ constexpr void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
36
+
37
+ // [array.creation], array creation functions
38
  template<class T, size_t N>
39
+ constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);
40
  template<class T, size_t N>
41
+ constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
42
 
43
+ // [array.tuple], tuple interface
44
+ template<class T> struct tuple_size;
45
+ template<size_t I, class T> struct tuple_element;
46
  template<class T, size_t N>
47
  struct tuple_size<array<T, N>>;
48
  template<size_t I, class T, size_t N>
49
  struct tuple_element<I, array<T, N>>;
50
  template<size_t I, class T, size_t N>
 
59
  ```
60
 
61
  ### Header `<deque>` synopsis <a id="deque.syn">[[deque.syn]]</a>
62
 
63
  ``` cpp
64
+ #include <compare> // see [compare.syn]
65
+ #include <initializer_list> // see [initializer.list.syn]
66
 
67
  namespace std {
68
  // [deque], class template deque
69
  template<class T, class Allocator = allocator<T>> class deque;
70
+
71
  template<class T, class Allocator>
72
  bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
73
  template<class T, class Allocator>
74
+ synth-three-way-result<T> operator<=>(const deque<T, Allocator>& x,
75
+ \itcorr const deque<T, Allocator>& y);
76
+
 
 
 
 
 
 
77
  template<class T, class Allocator>
78
  void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
79
  noexcept(noexcept(x.swap(y)));
80
 
81
+ template<class T, class Allocator, class U>
82
+ typename deque<T, Allocator>::size_type
83
+ erase(deque<T, Allocator>& c, const U& value);
84
+ template<class T, class Allocator, class Predicate>
85
+ typename deque<T, Allocator>::size_type
86
+ erase_if(deque<T, Allocator>& c, Predicate pred);
87
+
88
  namespace pmr {
89
  template<class T>
90
  using deque = std::deque<T, polymorphic_allocator<T>>;
91
  }
92
  }
93
  ```
94
 
95
+ ### Header `<forward_list>` synopsis <a id="forward.list.syn">[[forward.list.syn]]</a>
96
 
97
  ``` cpp
98
+ #include <compare> // see [compare.syn]
99
+ #include <initializer_list> // see [initializer.list.syn]
100
 
101
  namespace std {
102
  // [forwardlist], class template forward_list
103
  template<class T, class Allocator = allocator<T>> class forward_list;
104
+
105
  template<class T, class Allocator>
106
  bool operator==(const forward_list<T, Allocator>& x, const forward_list<T, Allocator>& y);
107
  template<class T, class Allocator>
108
+ synth-three-way-result<T> operator<=>(const forward_list<T, Allocator>& x,
109
+ \itcorr const forward_list<T, Allocator>& y);
110
+
 
 
 
 
 
 
111
  template<class T, class Allocator>
112
  void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
113
  noexcept(noexcept(x.swap(y)));
114
 
115
+ template<class T, class Allocator, class U>
116
+ typename forward_list<T, Allocator>::size_type
117
+ erase(forward_list<T, Allocator>& c, const U& value);
118
+ template<class T, class Allocator, class Predicate>
119
+ typename forward_list<T, Allocator>::size_type
120
+ erase_if(forward_list<T, Allocator>& c, Predicate pred);
121
+
122
  namespace pmr {
123
  template<class T>
124
  using forward_list = std::forward_list<T, polymorphic_allocator<T>>;
125
  }
126
  }
127
  ```
128
 
129
  ### Header `<list>` synopsis <a id="list.syn">[[list.syn]]</a>
130
 
131
  ``` cpp
132
+ #include <compare> // see [compare.syn]
133
+ #include <initializer_list> // see [initializer.list.syn]
134
 
135
  namespace std {
136
  // [list], class template list
137
  template<class T, class Allocator = allocator<T>> class list;
138
+
139
  template<class T, class Allocator>
140
  bool operator==(const list<T, Allocator>& x, const list<T, Allocator>& y);
141
  template<class T, class Allocator>
142
+ synth-three-way-result<T> operator<=>(const list<T, Allocator>& x,
143
+ \itcorr const list<T, Allocator>& y);
144
+
 
 
 
 
 
 
145
  template<class T, class Allocator>
146
  void swap(list<T, Allocator>& x, list<T, Allocator>& y)
147
  noexcept(noexcept(x.swap(y)));
148
 
149
+ template<class T, class Allocator, class U>
150
+ typename list<T, Allocator>::size_type
151
+ erase(list<T, Allocator>& c, const U& value);
152
+ template<class T, class Allocator, class Predicate>
153
+ typename list<T, Allocator>::size_type
154
+ erase_if(list<T, Allocator>& c, Predicate pred);
155
+
156
  namespace pmr {
157
  template<class T>
158
  using list = std::list<T, polymorphic_allocator<T>>;
159
  }
160
  }
161
  ```
162
 
163
  ### Header `<vector>` synopsis <a id="vector.syn">[[vector.syn]]</a>
164
 
165
  ``` cpp
166
+ #include <compare> // see [compare.syn]
167
+ #include <initializer_list> // see [initializer.list.syn]
168
 
169
  namespace std {
170
  // [vector], class template vector
171
  template<class T, class Allocator = allocator<T>> class vector;
172
+
173
  template<class T, class Allocator>
174
+ constexpr bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
175
  template<class T, class Allocator>
176
+ constexpr synth-three-way-result<T> operator<=>(const vector<T, Allocator>& x,
177
+ \itcorr const vector<T, Allocator>& y);
178
+
179
  template<class T, class Allocator>
180
+ constexpr void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
 
 
 
 
 
 
 
 
181
  noexcept(noexcept(x.swap(y)));
182
 
183
+ template<class T, class Allocator, class U>
184
+ constexpr typename vector<T, Allocator>::size_type
185
+ erase(vector<T, Allocator>& c, const U& value);
186
+ template<class T, class Allocator, class Predicate>
187
+ constexpr typename vector<T, Allocator>::size_type
188
+ erase_if(vector<T, Allocator>& c, Predicate pred);
189
+
190
  // [vector.bool], class vector<bool>
191
  template<class Allocator> class vector<bool, Allocator>;
192
 
193
  // hash support
194
  template<class T> struct hash;
 
201
  }
202
  ```
203
 
204
  ### Class template `array` <a id="array">[[array]]</a>
205
 
206
+ #### Overview <a id="array.overview">[[array.overview]]</a>
207
 
208
  The header `<array>` defines a class template for storing fixed-size
209
+ sequences of objects. An `array` is a contiguous container
210
+ [[container.requirements.general]]. An instance of `array<T, N>` stores
211
  `N` elements of type `T`, so that `size() == N` is an invariant.
212
 
213
+ An `array` is an aggregate [[dcl.init.aggr]] that can be
214
  list-initialized with up to `N` elements whose types are convertible to
215
  `T`.
216
 
217
+ An `array` meets all of the requirements of a container and of a
218
+ reversible container [[container.requirements]], except that a default
219
+ constructed `array` object is not empty and that `swap` does not have
220
+ constant complexity. An `array` meets some of the requirements of a
221
+ sequence container [[sequence.reqmts]]. Descriptions are provided here
222
+ only for operations on `array` that are not described in one of these
223
+ tables and for operations where there is additional semantic
224
+ information.
225
+
226
+ `array<T, N>` is a structural type [[temp.param]] if `T` is a structural
227
+ type. Two values `a1` and `a2` of type `array<T, N>` are
228
+ template-argument-equivalent [[temp.type]] if and only if each pair of
229
+ corresponding elements in `a1` and `a2` are
230
+ template-argument-equivalent.
231
+
232
+ The types `iterator` and `const_iterator` meet the constexpr iterator
233
+ requirements [[iterator.requirements.general]].
234
 
235
  ``` cpp
236
  namespace std {
237
  template<class T, size_t N>
238
  struct array {
239
+ // types
240
  using value_type = T;
241
  using pointer = T*;
242
  using const_pointer = const T*;
243
  using reference = T&;
244
  using const_reference = const T&;
 
249
  using reverse_iterator = std::reverse_iterator<iterator>;
250
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
251
 
252
  // no explicit construct/copy/destroy for aggregate type
253
 
254
+ constexpr void fill(const T& u);
255
+ constexpr void swap(array&) noexcept(is_nothrow_swappable_v<T>);
256
 
257
+ // iterators
258
  constexpr iterator begin() noexcept;
259
  constexpr const_iterator begin() const noexcept;
260
  constexpr iterator end() noexcept;
261
  constexpr const_iterator end() const noexcept;
262
 
 
268
  constexpr const_iterator cbegin() const noexcept;
269
  constexpr const_iterator cend() const noexcept;
270
  constexpr const_reverse_iterator crbegin() const noexcept;
271
  constexpr const_reverse_iterator crend() const noexcept;
272
 
273
+ // capacity
274
+ [[nodiscard]] constexpr bool empty() const noexcept;
275
  constexpr size_type size() const noexcept;
276
  constexpr size_type max_size() const noexcept;
277
 
278
+ // element access
279
  constexpr reference operator[](size_type n);
280
  constexpr const_reference operator[](size_type n) const;
281
  constexpr reference at(size_type n);
282
  constexpr const_reference at(size_type n) const;
283
  constexpr reference front();
 
292
  template<class T, class... U>
293
  array(T, U...) -> array<T, 1 + sizeof...(U)>;
294
  }
295
  ```
296
 
297
+ #### Constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
298
 
299
+ The conditions for an aggregate [[dcl.init.aggr]] shall be met. Class
300
  `array` relies on the implicitly-declared special member functions (
301
+ [[class.default.ctor]], [[class.dtor]], and [[class.copy.ctor]]) to
302
+ conform to the container requirements table in 
303
+ [[container.requirements]]. In addition to the requirements specified in
304
+ the container requirements table, the implicit move constructor and move
305
+ assignment operator for `array` require that `T` be
306
+ *Cpp17MoveConstructible* or *Cpp17MoveAssignable*, respectively.
307
 
308
  ``` cpp
309
  template<class T, class... U>
310
  array(T, U...) -> array<T, 1 + sizeof...(U)>;
311
  ```
312
 
313
+ *Mandates:* `(is_same_v<T, U> && ...)` is `true`.
 
314
 
315
+ #### Member functions <a id="array.members">[[array.members]]</a>
316
 
317
  ``` cpp
318
+ constexpr size_type size() const noexcept;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  ```
320
 
321
  *Returns:* `N`.
322
 
 
 
323
  ``` cpp
324
  constexpr T* data() noexcept;
325
  constexpr const T* data() const noexcept;
326
  ```
327
 
328
+ *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
329
+ range. For a non-empty array, `data()` `==` `addressof(front())`.
 
 
330
 
331
  ``` cpp
332
+ constexpr void fill(const T& u);
333
  ```
334
 
335
  *Effects:* As if by `fill_n(begin(), N, u)`.
336
 
 
 
337
  ``` cpp
338
+ constexpr void swap(array& y) noexcept(is_nothrow_swappable_v<T>);
339
  ```
340
 
341
  *Effects:* Equivalent to `swap_ranges(begin(), end(), y.begin())`.
342
 
343
  [*Note 1*: Unlike the `swap` function for other containers,
344
  `array::swap` takes linear time, may exit via an exception, and does not
345
  cause iterators to become associated with the other
346
  container. — *end note*]
347
 
348
+ #### Specialized algorithms <a id="array.special">[[array.special]]</a>
349
+
350
+ ``` cpp
351
+ template<class T, size_t N>
352
+ constexpr void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
353
+ ```
354
+
355
+ *Constraints:* `N == 0` or `is_swappable_v<T>` is `true`.
356
+
357
+ *Effects:* As if by `x.swap(y)`.
358
+
359
+ *Complexity:* Linear in `N`.
360
+
361
+ #### Zero-sized arrays <a id="array.zero">[[array.zero]]</a>
362
 
363
  `array` shall provide support for the special case `N == 0`.
364
 
365
  In the case that `N == 0`, `begin() == end() ==` unique value. The
366
  return value of `data()` is unspecified.
 
369
  undefined.
370
 
371
  Member function `swap()` shall have a non-throwing exception
372
  specification.
373
 
374
+ #### Array creation functions <a id="array.creation">[[array.creation]]</a>
375
+
376
+ ``` cpp
377
+ template<class T, size_t N>
378
+ constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);
379
+ ```
380
+
381
+ *Mandates:* `is_array_v<T>` is `false` and `is_constructible_v<T, T&>`
382
+ is `true`.
383
+
384
+ *Preconditions:* `T` meets the *Cpp17CopyConstructible* requirements.
385
+
386
+ *Returns:* `{{ a[0], `…`, a[N - 1] }}`.
387
+
388
+ ``` cpp
389
+ template<class T, size_t N>
390
+ constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
391
+ ```
392
+
393
+ *Mandates:* `is_array_v<T>` is `false` and `is_move_constructible_v<T>`
394
+ is `true`.
395
+
396
+ *Preconditions:* `T` meets the *Cpp17MoveConstructible* requirements.
397
+
398
+ *Returns:* `{{ std::move(a[0]), `…`, std::move(a[N - 1]) }}`.
399
+
400
+ #### Tuple interface <a id="array.tuple">[[array.tuple]]</a>
401
 
402
  ``` cpp
403
  template<class T, size_t N>
404
  struct tuple_size<array<T, N>> : integral_constant<size_t, N> { };
405
  ```
406
 
407
  ``` cpp
408
+ template<size_t I, class T, size_t N>
409
+ struct tuple_element<I, array<T, N>> {
410
+ using type = T;
411
+ };
412
  ```
413
 
414
+ *Mandates:* `I < N` is `true`.
 
 
415
 
416
  ``` cpp
417
  template<size_t I, class T, size_t N>
418
  constexpr T& get(array<T, N>& a) noexcept;
419
  template<size_t I, class T, size_t N>
 
422
  constexpr const T& get(const array<T, N>& a) noexcept;
423
  template<size_t I, class T, size_t N>
424
  constexpr const T&& get(const array<T, N>&& a) noexcept;
425
  ```
426
 
427
+ *Mandates:* `I < N` is `true`.
428
 
429
+ *Returns:* A reference to the `I`ᵗʰ element of `a`, where indexing is
430
  zero-based.
431
 
432
  ### Class template `deque` <a id="deque">[[deque]]</a>
433
 
434
+ #### Overview <a id="deque.overview">[[deque.overview]]</a>
435
 
436
  A `deque` is a sequence container that supports random access iterators
437
+ [[random.access.iterators]]. In addition, it supports constant time
438
  insert and erase operations at the beginning or the end; insert and
439
  erase in the middle take linear time. That is, a deque is especially
440
  optimized for pushing and popping elements at the beginning and end.
441
  Storage management is handled automatically.
442
 
443
+ A `deque` meets all of the requirements of a container, of a reversible
444
+ container (given in tables in  [[container.requirements]]), of a
445
+ sequence container, including the optional sequence container
446
+ requirements [[sequence.reqmts]], and of an allocator-aware container (
447
+ [[container.alloc.req]]). Descriptions are provided here only for
448
+ operations on `deque` that are not described in one of these tables or
449
+ for operations where there is additional semantic information.
 
450
 
451
  ``` cpp
452
  namespace std {
453
  template<class T, class Allocator = allocator<T>>
454
  class deque {
455
  public:
456
+ // types
457
  using value_type = T;
458
  using allocator_type = Allocator;
459
  using pointer = typename allocator_traits<Allocator>::pointer;
460
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
461
  using reference = value_type&;
 
489
  void assign(InputIterator first, InputIterator last);
490
  void assign(size_type n, const T& t);
491
  void assign(initializer_list<T>);
492
  allocator_type get_allocator() const noexcept;
493
 
494
+ // iterators
495
  iterator begin() noexcept;
496
  const_iterator begin() const noexcept;
497
  iterator end() noexcept;
498
  const_iterator end() const noexcept;
499
  reverse_iterator rbegin() noexcept;
 
505
  const_iterator cend() const noexcept;
506
  const_reverse_iterator crbegin() const noexcept;
507
  const_reverse_iterator crend() const noexcept;
508
 
509
  // [deque.capacity], capacity
510
+ [[nodiscard]] bool empty() const noexcept;
511
  size_type size() const noexcept;
512
  size_type max_size() const noexcept;
513
  void resize(size_type sz);
514
  void resize(size_type sz, const T& c);
515
  void shrink_to_fit();
516
 
517
+ // element access
518
  reference operator[](size_type n);
519
  const_reference operator[](size_type n) const;
520
  reference at(size_type n);
521
  const_reference at(size_type n) const;
522
  reference front();
 
549
  void swap(deque&)
550
  noexcept(allocator_traits<Allocator>::is_always_equal::value);
551
  void clear() noexcept;
552
  };
553
 
554
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
 
555
  deque(InputIterator, InputIterator, Allocator = Allocator())
556
+ -> deque<iter-value-type<InputIterator>, Allocator>;
557
 
558
+ // swap
 
 
 
 
 
 
 
 
 
 
 
 
 
559
  template<class T, class Allocator>
560
  void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
561
  noexcept(noexcept(x.swap(y)));
562
  }
563
  ```
564
 
565
+ #### Constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
566
 
567
  ``` cpp
568
  explicit deque(const Allocator&);
569
  ```
570
 
 
577
  ```
578
 
579
  *Effects:* Constructs a `deque` with `n` default-inserted elements using
580
  the specified allocator.
581
 
582
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
583
 
584
  *Complexity:* Linear in `n`.
585
 
586
  ``` cpp
587
  deque(size_type n, const T& value, const Allocator& = Allocator());
588
  ```
589
 
590
  *Effects:* Constructs a `deque` with `n` copies of `value`, using the
591
  specified allocator.
592
 
593
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
594
 
595
  *Complexity:* Linear in `n`.
596
 
597
  ``` cpp
598
  template<class InputIterator>
 
602
  *Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
603
  using the specified allocator.
604
 
605
  *Complexity:* Linear in `distance(first, last)`.
606
 
607
+ #### Capacity <a id="deque.capacity">[[deque.capacity]]</a>
608
 
609
  ``` cpp
610
  void resize(size_type sz);
611
  ```
612
 
613
+ *Preconditions:* `T` is *Cpp17MoveInsertable* and
614
+ *Cpp17DefaultInsertable* into `*this`.
615
+
616
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
617
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
618
  to the sequence.
619
 
 
 
 
620
  ``` cpp
621
  void resize(size_type sz, const T& c);
622
  ```
623
 
624
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
625
+
626
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
627
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
628
  sequence.
629
 
 
 
630
  ``` cpp
631
  void shrink_to_fit();
632
  ```
633
 
634
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
635
 
636
  *Effects:* `shrink_to_fit` is a non-binding request to reduce memory use
637
  but does not change the size of the sequence.
638
 
639
  [*Note 1*: The request is non-binding to allow latitude for
640
  implementation-specific optimizations. — *end note*]
641
 
642
+ If the size is equal to the old capacity, or if an exception is thrown
643
+ other than by the move constructor of a non-*Cpp17CopyInsertable* `T`,
644
+ then there are no effects.
645
 
646
+ *Complexity:* If the size is not equal to the old capacity, linear in
647
+ the size of the sequence; otherwise constant.
648
 
649
+ *Remarks:* If the size is not equal to the old capacity, then
650
+ invalidates all the references, pointers, and iterators referring to the
651
+ elements in the sequence, as well as the past-the-end iterator.
652
 
653
+ #### Modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
654
 
655
  ``` cpp
656
  iterator insert(const_iterator position, const T& x);
657
  iterator insert(const_iterator position, T&& x);
658
  iterator insert(const_iterator position, size_type n, const T& x);
 
677
 
678
  *Remarks:* If an exception is thrown other than by the copy constructor,
679
  move constructor, assignment operator, or move assignment operator of
680
  `T` there are no effects. If an exception is thrown while inserting a
681
  single element at either end, there are no effects. Otherwise, if an
682
+ exception is thrown by the move constructor of a
683
+ non-*Cpp17CopyInsertable* `T`, the effects are unspecified.
684
 
685
  *Complexity:* The complexity is linear in the number of elements
686
  inserted plus the lesser of the distances to the beginning and end of
687
+ the deque. Inserting a single element at either the beginning or end of
688
  a deque always takes constant time and causes a single call to a
689
  constructor of `T`.
690
 
691
  ``` cpp
692
  iterator erase(const_iterator position);
 
711
  as the number of elements erased, but the number of calls to the
712
  assignment operator of `T` is no more than the lesser of the number of
713
  elements before the erased elements and the number of elements after the
714
  erased elements.
715
 
716
+ *Throws:* Nothing unless an exception is thrown by the assignment
717
+ operator of `T`.
 
718
 
719
+ #### Erasure <a id="deque.erasure">[[deque.erasure]]</a>
720
 
721
  ``` cpp
722
+ template<class T, class Allocator, class U>
723
+ typename deque<T, Allocator>::size_type
724
+ erase(deque<T, Allocator>& c, const U& value);
725
  ```
726
 
727
+ *Effects:* Equivalent to:
728
+
729
+ ``` cpp
730
+ auto it = remove(c.begin(), c.end(), value);
731
+ auto r = distance(it, c.end());
732
+ c.erase(it, c.end());
733
+ return r;
734
+ ```
735
+
736
+ ``` cpp
737
+ template<class T, class Allocator, class Predicate>
738
+ typename deque<T, Allocator>::size_type
739
+ erase_if(deque<T, Allocator>& c, Predicate pred);
740
+ ```
741
+
742
+ *Effects:* Equivalent to:
743
+
744
+ ``` cpp
745
+ auto it = remove_if(c.begin(), c.end(), pred);
746
+ auto r = distance(it, c.end());
747
+ c.erase(it, c.end());
748
+ return r;
749
+ ```
750
 
751
  ### Class template `forward_list` <a id="forwardlist">[[forwardlist]]</a>
752
 
753
+ #### Overview <a id="forwardlist.overview">[[forwardlist.overview]]</a>
754
 
755
  A `forward_list` is a container that supports forward iterators and
756
  allows constant time insert and erase operations anywhere within the
757
  sequence, with storage management handled automatically. Fast random
758
  access to list elements is not supported.
759
 
760
  [*Note 1*: It is intended that `forward_list` have zero space or time
761
  overhead relative to a hand-written C-style singly linked list. Features
762
  that would conflict with that goal have been omitted. — *end note*]
763
 
764
+ A `forward_list` meets all of the requirements of a container (
765
+ [[container.req]]), except that the `size()` member function is not
766
+ provided and `operator==` has linear complexity. A `forward_list` also
767
+ meets all of the requirements for an allocator-aware container (
768
+ [[container.alloc.req]]). In addition, a `forward_list` provides the
769
+ `assign` member functions ([[container.seq.req]]) and several of the
770
+ optional container requirements ([[container.seq.opt]]). Descriptions
771
+ are provided here only for operations on `forward_list` that are not
772
+ described in that table or for operations where there is additional
773
+ semantic information.
 
774
 
775
  [*Note 2*: Modifying any list requires access to the element preceding
776
  the first element of interest, but in a `forward_list` there is no
777
  constant-time way to access a preceding element. For this reason, ranges
778
  that are modified, such as those supplied to `erase` and `splice`, must
 
781
  ``` cpp
782
  namespace std {
783
  template<class T, class Allocator = allocator<T>>
784
  class forward_list {
785
  public:
786
+ // types
787
  using value_type = T;
788
  using allocator_type = Allocator;
789
  using pointer = typename allocator_traits<Allocator>::pointer;
790
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
791
  using reference = value_type&;
 
797
 
798
  // [forwardlist.cons], construct/copy/destroy
799
  forward_list() : forward_list(Allocator()) { }
800
  explicit forward_list(const Allocator&);
801
  explicit forward_list(size_type n, const Allocator& = Allocator());
802
+ forward_list(size_type n, const T& value, const Allocator& = Allocator());
 
803
  template<class InputIterator>
804
+ forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator());
 
805
  forward_list(const forward_list& x);
806
  forward_list(forward_list&& x);
807
  forward_list(const forward_list& x, const Allocator&);
808
  forward_list(forward_list&& x, const Allocator&);
809
  forward_list(initializer_list<T>, const Allocator& = Allocator());
 
828
 
829
  const_iterator cbegin() const noexcept;
830
  const_iterator cbefore_begin() const noexcept;
831
  const_iterator cend() const noexcept;
832
 
833
+ // capacity
834
+ [[nodiscard]] bool empty() const noexcept;
835
  size_type max_size() const noexcept;
836
 
837
  // [forwardlist.access], element access
838
  reference front();
839
  const_reference front() const;
 
863
  void clear() noexcept;
864
 
865
  // [forwardlist.ops], forward_list operations
866
  void splice_after(const_iterator position, forward_list& x);
867
  void splice_after(const_iterator position, forward_list&& x);
868
+ void splice_after(const_iterator position, forward_list& x, const_iterator i);
869
+ void splice_after(const_iterator position, forward_list&& x, const_iterator i);
 
 
870
  void splice_after(const_iterator position, forward_list& x,
871
  const_iterator first, const_iterator last);
872
  void splice_after(const_iterator position, forward_list&& x,
873
  const_iterator first, const_iterator last);
874
 
875
+ size_type remove(const T& value);
876
+ template<class Predicate> size_type remove_if(Predicate pred);
877
 
878
+ size_type unique();
879
+ template<class BinaryPredicate> size_type unique(BinaryPredicate binary_pred);
880
 
881
  void merge(forward_list& x);
882
  void merge(forward_list&& x);
883
  template<class Compare> void merge(forward_list& x, Compare comp);
884
  template<class Compare> void merge(forward_list&& x, Compare comp);
 
887
  template<class Compare> void sort(Compare comp);
888
 
889
  void reverse() noexcept;
890
  };
891
 
892
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
 
893
  forward_list(InputIterator, InputIterator, Allocator = Allocator())
894
+ -> forward_list<iter-value-type<InputIterator>, Allocator>;
895
 
896
+ // swap
 
 
 
 
 
 
 
 
 
 
 
 
 
897
  template<class T, class Allocator>
898
  void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
899
  noexcept(noexcept(x.swap(y)));
900
  }
901
  ```
902
 
903
  An incomplete type `T` may be used when instantiating `forward_list` if
904
+ the allocator meets the allocator completeness requirements
905
+ [[allocator.requirements.completeness]]. `T` shall be complete before
906
  any member of the resulting specialization of `forward_list` is
907
  referenced.
908
 
909
+ #### Constructors, copy, and assignment <a id="forwardlist.cons">[[forwardlist.cons]]</a>
910
 
911
  ``` cpp
912
  explicit forward_list(const Allocator&);
913
  ```
914
 
 
919
 
920
  ``` cpp
921
  explicit forward_list(size_type n, const Allocator& = Allocator());
922
  ```
923
 
924
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
925
+
926
  *Effects:* Constructs a `forward_list` object with `n` default-inserted
927
  elements using the specified allocator.
928
 
 
 
929
  *Complexity:* Linear in `n`.
930
 
931
  ``` cpp
932
  forward_list(size_type n, const T& value, const Allocator& = Allocator());
933
  ```
934
 
935
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
936
+
937
  *Effects:* Constructs a `forward_list` object with `n` copies of `value`
938
  using the specified allocator.
939
 
 
 
940
  *Complexity:* Linear in `n`.
941
 
942
  ``` cpp
943
  template<class InputIterator>
944
  forward_list(InputIterator first, InputIterator last, const Allocator& = Allocator());
 
947
  *Effects:* Constructs a `forward_list` object equal to the range
948
  \[`first`, `last`).
949
 
950
  *Complexity:* Linear in `distance(first, last)`.
951
 
952
+ #### Iterators <a id="forwardlist.iter">[[forwardlist.iter]]</a>
953
 
954
  ``` cpp
955
  iterator before_begin() noexcept;
956
  const_iterator before_begin() const noexcept;
957
  const_iterator cbefore_begin() const noexcept;
 
963
  *Effects:* `cbefore_begin()` is equivalent to
964
  `const_cast<forward_list const&>(*this).before_begin()`.
965
 
966
  *Remarks:* `before_begin() == end()` shall equal `false`.
967
 
968
+ #### Element access <a id="forwardlist.access">[[forwardlist.access]]</a>
969
 
970
  ``` cpp
971
  reference front();
972
  const_reference front() const;
973
  ```
974
 
975
  *Returns:* `*begin()`
976
 
977
+ #### Modifiers <a id="forwardlist.modifiers">[[forwardlist.modifiers]]</a>
978
 
979
  None of the overloads of `insert_after` shall affect the validity of
980
  iterators and references, and `erase_after` shall invalidate only
981
  iterators and references to the erased elements. If an exception is
982
  thrown during `insert_after` there shall be no effect. Inserting `n`
 
1008
  ``` cpp
1009
  iterator insert_after(const_iterator position, const T& x);
1010
  iterator insert_after(const_iterator position, T&& x);
1011
  ```
1012
 
1013
+ *Preconditions:* `position` is `before_begin()` or is a dereferenceable
1014
  iterator in the range \[`begin()`, `end()`).
1015
 
1016
  *Effects:* Inserts a copy of `x` after `position`.
1017
 
1018
  *Returns:* An iterator pointing to the copy of `x`.
1019
 
1020
  ``` cpp
1021
  iterator insert_after(const_iterator position, size_type n, const T& x);
1022
  ```
1023
 
1024
+ *Preconditions:* `position` is `before_begin()` or is a dereferenceable
1025
  iterator in the range \[`begin()`, `end()`).
1026
 
1027
  *Effects:* Inserts `n` copies of `x` after `position`.
1028
 
1029
  *Returns:* An iterator pointing to the last inserted copy of `x` or
 
1032
  ``` cpp
1033
  template<class InputIterator>
1034
  iterator insert_after(const_iterator position, InputIterator first, InputIterator last);
1035
  ```
1036
 
1037
+ *Preconditions:* `position` is `before_begin()` or is a dereferenceable
1038
+ iterator in the range \[`begin()`, `end()`). Neither `first` nor `last`
1039
+ are iterators in `*this`.
1040
 
1041
  *Effects:* Inserts copies of elements in \[`first`, `last`) after
1042
  `position`.
1043
 
1044
  *Returns:* An iterator pointing to the last inserted element or
 
1056
  ``` cpp
1057
  template<class... Args>
1058
  iterator emplace_after(const_iterator position, Args&&... args);
1059
  ```
1060
 
1061
+ *Preconditions:* `position` is `before_begin()` or is a dereferenceable
1062
  iterator in the range \[`begin()`, `end()`).
1063
 
1064
  *Effects:* Inserts an object of type `value_type` constructed with
1065
  `value_type(std::forward<Args>(args)...)` after `position`.
1066
 
 
1068
 
1069
  ``` cpp
1070
  iterator erase_after(const_iterator position);
1071
  ```
1072
 
1073
+ *Preconditions:* The iterator following `position` is dereferenceable.
1074
 
1075
  *Effects:* Erases the element pointed to by the iterator following
1076
  `position`.
1077
 
1078
  *Returns:* An iterator pointing to the element following the one that
 
1082
 
1083
  ``` cpp
1084
  iterator erase_after(const_iterator position, const_iterator last);
1085
  ```
1086
 
1087
+ *Preconditions:* All iterators in the range (`position`, `last`) are
1088
  dereferenceable.
1089
 
1090
  *Effects:* Erases the elements in the range (`position`, `last`).
1091
 
1092
  *Returns:* `last`.
 
1095
 
1096
  ``` cpp
1097
  void resize(size_type sz);
1098
  ```
1099
 
1100
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
1101
+
1102
  *Effects:* If `sz < distance(begin(), end())`, erases the last
1103
  `distance(begin(), end()) - sz` elements from the list. Otherwise,
1104
  inserts `sz - distance(begin(), end())` default-inserted elements at the
1105
  end of the list.
1106
 
 
 
1107
  ``` cpp
1108
  void resize(size_type sz, const value_type& c);
1109
  ```
1110
 
1111
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
1112
+
1113
  *Effects:* If `sz < distance(begin(), end())`, erases the last
1114
  `distance(begin(), end()) - sz` elements from the list. Otherwise,
1115
  inserts `sz - distance(begin(), end())` copies of `c` at the end of the
1116
  list.
1117
 
 
 
1118
  ``` cpp
1119
  void clear() noexcept;
1120
  ```
1121
 
1122
  *Effects:* Erases all elements in the range \[`begin()`, `end()`).
1123
 
1124
  *Remarks:* Does not invalidate past-the-end iterators.
1125
 
1126
+ #### Operations <a id="forwardlist.ops">[[forwardlist.ops]]</a>
1127
+
1128
+ In this subclause, arguments for a template parameter named `Predicate`
1129
+ or `BinaryPredicate` shall meet the corresponding requirements in
1130
+ [[algorithms.requirements]]. For `merge` and `sort`, the definitions and
1131
+ requirements in [[alg.sorting]] apply.
1132
 
1133
  ``` cpp
1134
  void splice_after(const_iterator position, forward_list& x);
1135
  void splice_after(const_iterator position, forward_list&& x);
1136
  ```
1137
 
1138
+ *Preconditions:* `position` is `before_begin()` or is a dereferenceable
1139
  iterator in the range \[`begin()`, `end()`).
1140
+ `get_allocator() == x.get_allocator()` is `true`. `addressof(x) != this`
1141
+ is `true`.
1142
 
1143
  *Effects:* Inserts the contents of `x` after `position`, and `x` becomes
1144
  empty. Pointers and references to the moved elements of `x` now refer to
1145
  those same elements but as members of `*this`. Iterators referring to
1146
  the moved elements will continue to refer to their elements, but they
 
1153
  ``` cpp
1154
  void splice_after(const_iterator position, forward_list& x, const_iterator i);
1155
  void splice_after(const_iterator position, forward_list&& x, const_iterator i);
1156
  ```
1157
 
1158
+ *Preconditions:* `position` is `before_begin()` or is a dereferenceable
1159
  iterator in the range \[`begin()`, `end()`). The iterator following `i`
1160
  is a dereferenceable iterator in `x`.
1161
+ `get_allocator() == x.get_allocator()` is `true`.
1162
 
1163
  *Effects:* Inserts the element following `i` into `*this`, following
1164
  `position`, and removes it from `x`. The result is unchanged if
1165
  `position == i` or `position == ++i`. Pointers and references to `*++i`
1166
  continue to refer to the same element but as a member of `*this`.
 
1176
  const_iterator first, const_iterator last);
1177
  void splice_after(const_iterator position, forward_list&& x,
1178
  const_iterator first, const_iterator last);
1179
  ```
1180
 
1181
+ *Preconditions:* `position` is `before_begin()` or is a dereferenceable
1182
  iterator in the range \[`begin()`, `end()`). (`first`, `last`) is a
1183
  valid range in `x`, and all iterators in the range (`first`, `last`) are
1184
  dereferenceable. `position` is not an iterator in the range (`first`,
1185
+ `last`). `get_allocator() == x.get_allocator()` is `true`.
1186
 
1187
  *Effects:* Inserts elements in the range (`first`, `last`) after
1188
  `position` and removes the elements from `x`. Pointers and references to
1189
  the moved elements of `x` now refer to those same elements but as
1190
  members of `*this`. Iterators referring to the moved elements will
 
1192
  into `*this`, not into `x`.
1193
 
1194
  *Complexity:* 𝑂(`distance(first, last)`)
1195
 
1196
  ``` cpp
1197
+ size_type remove(const T& value);
1198
+ template<class Predicate> size_type remove_if(Predicate pred);
1199
  ```
1200
 
1201
+ *Effects:* Erases all the elements in the list referred to by a list
1202
  iterator `i` for which the following conditions hold: `*i == value` (for
1203
  `remove()`), `pred(*i)` is `true` (for `remove_if()`). Invalidates only
1204
  the iterators and references to the erased elements.
1205
 
1206
+ *Returns:* The number of elements erased.
1207
+
1208
  *Throws:* Nothing unless an exception is thrown by the equality
1209
  comparison or the predicate.
1210
 
1211
+ *Remarks:* Stable [[algorithm.stable]].
1212
 
1213
  *Complexity:* Exactly `distance(begin(), end())` applications of the
1214
  corresponding predicate.
1215
 
1216
  ``` cpp
1217
+ size_type unique();
1218
+ template<class BinaryPredicate> size_type unique(BinaryPredicate pred);
1219
  ```
1220
 
1221
  *Effects:* Erases all but the first element from every consecutive group
1222
  of equal elements referred to by the iterator `i` in the range
1223
  \[`first + 1`, `last`) for which `*i == *(i-1)` (for the version with no
1224
  arguments) or `pred(*i, *(i - 1))` (for the version with a predicate
1225
  argument) holds. Invalidates only the iterators and references to the
1226
  erased elements.
1227
 
1228
+ *Returns:* The number of elements erased.
1229
+
1230
  *Throws:* Nothing unless an exception is thrown by the equality
1231
  comparison or the predicate.
1232
 
1233
  *Complexity:* If the range \[`first`, `last`) is not empty, exactly
1234
  `(last - first) - 1` applications of the corresponding predicate,
 
1239
  void merge(forward_list&& x);
1240
  template<class Compare> void merge(forward_list& x, Compare comp);
1241
  template<class Compare> void merge(forward_list&& x, Compare comp);
1242
  ```
1243
 
1244
+ *Preconditions:* `*this` and `x` are both sorted with respect to the
1245
+ comparator `operator<` (for the first two overloads) or `comp` (for the
1246
+ last two overloads), and `get_allocator() == x.get_allocator()` is
1247
+ `true`.
1248
 
1249
  *Effects:* Merges the two sorted ranges `[begin(), end())` and
1250
  `[x.begin(), x.end())`. `x` is empty after the merge. If an exception is
1251
  thrown other than by a comparison there are no effects. Pointers and
1252
  references to the moved elements of `x` now refer to those same elements
1253
  but as members of `*this`. Iterators referring to the moved elements
1254
  will continue to refer to their elements, but they now behave as
1255
  iterators into `*this`, not into `x`.
1256
 
1257
+ *Remarks:* Stable [[algorithm.stable]].
 
1258
 
1259
  *Complexity:* At most
1260
  `distance(begin(), end()) + distance(x.begin(), x.end()) - 1`
1261
  comparisons.
1262
 
1263
  ``` cpp
1264
  void sort();
1265
  template<class Compare> void sort(Compare comp);
1266
  ```
1267
 
 
 
 
 
1268
  *Effects:* Sorts the list according to the `operator<` or the `comp`
1269
  function object. If an exception is thrown, the order of the elements in
1270
  `*this` is unspecified. Does not affect the validity of iterators and
1271
  references.
1272
 
1273
+ *Remarks:* Stable [[algorithm.stable]].
1274
 
1275
  *Complexity:* Approximately N log N comparisons, where N is
1276
  `distance(begin(), end())`.
1277
 
1278
  ``` cpp
 
1282
  *Effects:* Reverses the order of the elements in the list. Does not
1283
  affect the validity of iterators and references.
1284
 
1285
  *Complexity:* Linear time.
1286
 
1287
+ #### Erasure <a id="forward.list.erasure">[[forward.list.erasure]]</a>
1288
 
1289
  ``` cpp
1290
+ template<class T, class Allocator, class U>
1291
+ typename forward_list<T, Allocator>::size_type
1292
+ erase(forward_list<T, Allocator>& c, const U& value);
1293
  ```
1294
 
1295
+ *Effects:* Equivalent to:
1296
+ `return erase_if(c, [&](auto& elem) { return elem == value; });`
1297
+
1298
+ ``` cpp
1299
+ template<class T, class Allocator, class Predicate>
1300
+ typename forward_list<T, Allocator>::size_type
1301
+ erase_if(forward_list<T, Allocator>& c, Predicate pred);
1302
+ ```
1303
+
1304
+ *Effects:* Equivalent to: `return c.remove_if(pred);`
1305
 
1306
  ### Class template `list` <a id="list">[[list]]</a>
1307
 
1308
+ #### Overview <a id="list.overview">[[list.overview]]</a>
1309
 
1310
  A `list` is a sequence container that supports bidirectional iterators
1311
  and allows constant time insert and erase operations anywhere within the
1312
+ sequence, with storage management handled automatically. Unlike vectors
1313
+ [[vector]] and deques [[deque]], fast random access to list elements is
1314
+ not supported, but many algorithms only need sequential access anyway.
 
1315
 
1316
+ A `list` meets all of the requirements of a container, of a reversible
1317
+ container (given in two tables in [[container.requirements]]), of a
1318
+ sequence container, including most of the optional sequence container
1319
+ requirements [[sequence.reqmts]], and of an allocator-aware container (
1320
+ [[container.alloc.req]]). The exceptions are the `operator[]` and `at`
1321
+ member functions, which are not provided.[^2] Descriptions are provided
1322
+ here only for operations on `list` that are not described in one of
1323
+ these tables or for operations where there is additional semantic
 
1324
  information.
1325
 
1326
  ``` cpp
1327
  namespace std {
1328
  template<class T, class Allocator = allocator<T>>
1329
  class list {
1330
  public:
1331
+ // types
1332
  using value_type = T;
1333
  using allocator_type = Allocator;
1334
  using pointer = typename allocator_traits<Allocator>::pointer;
1335
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
1336
  using reference = value_type&;
 
1363
  void assign(InputIterator first, InputIterator last);
1364
  void assign(size_type n, const T& t);
1365
  void assign(initializer_list<T>);
1366
  allocator_type get_allocator() const noexcept;
1367
 
1368
+ // iterators
1369
  iterator begin() noexcept;
1370
  const_iterator begin() const noexcept;
1371
  iterator end() noexcept;
1372
  const_iterator end() const noexcept;
1373
  reverse_iterator rbegin() noexcept;
 
1379
  const_iterator cend() const noexcept;
1380
  const_reverse_iterator crbegin() const noexcept;
1381
  const_reverse_iterator crend() const noexcept;
1382
 
1383
  // [list.capacity], capacity
1384
+ [[nodiscard]] bool empty() const noexcept;
1385
  size_type size() const noexcept;
1386
  size_type max_size() const noexcept;
1387
  void resize(size_type sz);
1388
  void resize(size_type sz, const T& c);
1389
 
1390
+ // element access
1391
  reference front();
1392
  const_reference front() const;
1393
  reference back();
1394
  const_reference back() const;
1395
 
 
1406
  template<class... Args> iterator emplace(const_iterator position, Args&&... args);
1407
  iterator insert(const_iterator position, const T& x);
1408
  iterator insert(const_iterator position, T&& x);
1409
  iterator insert(const_iterator position, size_type n, const T& x);
1410
  template<class InputIterator>
1411
+ iterator insert(const_iterator position, InputIterator first, InputIterator last);
 
1412
  iterator insert(const_iterator position, initializer_list<T> il);
1413
 
1414
  iterator erase(const_iterator position);
1415
  iterator erase(const_iterator position, const_iterator last);
1416
+ void swap(list&) noexcept(allocator_traits<Allocator>::is_always_equal::value);
 
1417
  void clear() noexcept;
1418
 
1419
  // [list.ops], list operations
1420
  void splice(const_iterator position, list& x);
1421
  void splice(const_iterator position, list&& x);
1422
  void splice(const_iterator position, list& x, const_iterator i);
1423
  void splice(const_iterator position, list&& x, const_iterator i);
1424
+ void splice(const_iterator position, list& x, const_iterator first, const_iterator last);
1425
+ void splice(const_iterator position, list&& x, const_iterator first, const_iterator last);
 
 
1426
 
1427
+ size_type remove(const T& value);
1428
+ template<class Predicate> size_type remove_if(Predicate pred);
1429
 
1430
+ size_type unique();
1431
  template<class BinaryPredicate>
1432
+ size_type unique(BinaryPredicate binary_pred);
1433
 
1434
  void merge(list& x);
1435
  void merge(list&& x);
1436
  template<class Compare> void merge(list& x, Compare comp);
1437
  template<class Compare> void merge(list&& x, Compare comp);
 
1440
  template<class Compare> void sort(Compare comp);
1441
 
1442
  void reverse() noexcept;
1443
  };
1444
 
1445
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
 
1446
  list(InputIterator, InputIterator, Allocator = Allocator())
1447
+ -> list<iter-value-type<InputIterator>, Allocator>;
1448
 
1449
+ // swap
 
 
 
 
 
 
 
 
 
 
 
 
 
1450
  template<class T, class Allocator>
1451
  void swap(list<T, Allocator>& x, list<T, Allocator>& y)
1452
  noexcept(noexcept(x.swap(y)));
1453
  }
1454
  ```
1455
 
1456
  An incomplete type `T` may be used when instantiating `list` if the
1457
+ allocator meets the allocator completeness requirements
1458
+ [[allocator.requirements.completeness]]. `T` shall be complete before
1459
  any member of the resulting specialization of `list` is referenced.
1460
 
1461
+ #### Constructors, copy, and assignment <a id="list.cons">[[list.cons]]</a>
1462
 
1463
  ``` cpp
1464
  explicit list(const Allocator&);
1465
  ```
1466
 
 
1470
 
1471
  ``` cpp
1472
  explicit list(size_type n, const Allocator& = Allocator());
1473
  ```
1474
 
1475
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
1476
+
1477
  *Effects:* Constructs a `list` with `n` default-inserted elements using
1478
  the specified allocator.
1479
 
 
 
1480
  *Complexity:* Linear in `n`.
1481
 
1482
  ``` cpp
1483
  list(size_type n, const T& value, const Allocator& = Allocator());
1484
  ```
1485
 
1486
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
1487
+
1488
  *Effects:* Constructs a `list` with `n` copies of `value`, using the
1489
  specified allocator.
1490
 
 
 
1491
  *Complexity:* Linear in `n`.
1492
 
1493
  ``` cpp
1494
  template<class InputIterator>
1495
  list(InputIterator first, InputIterator last, const Allocator& = Allocator());
 
1497
 
1498
  *Effects:* Constructs a `list` equal to the range \[`first`, `last`).
1499
 
1500
  *Complexity:* Linear in `distance(first, last)`.
1501
 
1502
+ #### Capacity <a id="list.capacity">[[list.capacity]]</a>
1503
 
1504
  ``` cpp
1505
  void resize(size_type sz);
1506
  ```
1507
 
1508
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
1509
+
1510
  *Effects:* If `size() < sz`, appends `sz - size()` default-inserted
1511
  elements to the sequence. If `sz <= size()`, equivalent to:
1512
 
1513
  ``` cpp
1514
  list<T>::iterator it = begin();
1515
  advance(it, sz);
1516
  erase(it, end());
1517
  ```
1518
 
 
 
1519
  ``` cpp
1520
  void resize(size_type sz, const T& c);
1521
  ```
1522
 
1523
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
1524
+
1525
  *Effects:* As if by:
1526
 
1527
  ``` cpp
1528
  if (sz > size())
1529
  insert(end(), sz-size(), c);
 
1534
  }
1535
  else
1536
  ; // do nothing
1537
  ```
1538
 
1539
+ #### Modifiers <a id="list.modifiers">[[list.modifiers]]</a>
 
 
1540
 
1541
  ``` cpp
1542
  iterator insert(const_iterator position, const T& x);
1543
  iterator insert(const_iterator position, T&& x);
1544
  iterator insert(const_iterator position, size_type n, const T& x);
 
1582
  *Complexity:* Erasing a single element is a constant time operation with
1583
  a single call to the destructor of `T`. Erasing a range in a list is
1584
  linear time in the size of the range and the number of calls to the
1585
  destructor of type `T` is exactly equal to the size of the range.
1586
 
1587
+ #### Operations <a id="list.ops">[[list.ops]]</a>
1588
 
1589
  Since lists allow fast insertion and erasing from the middle of a list,
1590
+ certain operations are provided specifically for them.[^3] In this
1591
+ subclause, arguments for a template parameter named `Predicate` or
1592
+ `BinaryPredicate` shall meet the corresponding requirements in
1593
+ [[algorithms.requirements]]. For `merge` and `sort`, the definitions and
1594
+ requirements in [[alg.sorting]] apply.
1595
 
1596
  `list` provides three splice operations that destructively move elements
1597
  from one list to another. The behavior of splice operations is undefined
1598
  if `get_allocator() !=
1599
  x.get_allocator()`.
 
1601
  ``` cpp
1602
  void splice(const_iterator position, list& x);
1603
  void splice(const_iterator position, list&& x);
1604
  ```
1605
 
1606
+ *Preconditions:* `addressof(x) != this` is `true`.
1607
 
1608
  *Effects:* Inserts the contents of `x` before `position` and `x` becomes
1609
  empty. Pointers and references to the moved elements of `x` now refer to
1610
  those same elements but as members of `*this`. Iterators referring to
1611
  the moved elements will continue to refer to their elements, but they
 
1618
  ``` cpp
1619
  void splice(const_iterator position, list& x, const_iterator i);
1620
  void splice(const_iterator position, list&& x, const_iterator i);
1621
  ```
1622
 
1623
+ *Preconditions:* `i` is a valid dereferenceable iterator of `x`.
1624
 
1625
  *Effects:* Inserts an element pointed to by `i` from list `x` before
1626
  `position` and removes the element from `x`. The result is unchanged if
1627
  `position == i` or `position == ++i`. Pointers and references to `*i`
1628
  continue to refer to this same element but as a member of `*this`.
 
1638
  const_iterator last);
1639
  void splice(const_iterator position, list&& x, const_iterator first,
1640
  const_iterator last);
1641
  ```
1642
 
1643
+ *Preconditions:* `[first, last)` is a valid range in `x`. `position` is
1644
+ not an iterator in the range \[`first`, `last`).
 
1645
 
1646
  *Effects:* Inserts elements in the range \[`first`, `last`) before
1647
  `position` and removes the elements from `x`. Pointers and references to
1648
  the moved elements of `x` now refer to those same elements but as
1649
  members of `*this`. Iterators referring to the moved elements will
1650
  continue to refer to their elements, but they now behave as iterators
1651
  into `*this`, not into `x`.
1652
 
1653
  *Throws:* Nothing.
1654
 
1655
+ *Complexity:* Constant time if `addressof(x) == this`; otherwise, linear
1656
+ time.
1657
 
1658
  ``` cpp
1659
+ size_type remove(const T& value);
1660
+ template<class Predicate> size_type remove_if(Predicate pred);
1661
  ```
1662
 
1663
+ *Effects:* Erases all the elements in the list referred to by a list
1664
+ iterator `i` for which the following conditions hold: `*i == value`,
1665
+ `pred(*i) != false`. Invalidates only the iterators and references to
1666
+ the erased elements.
1667
+
1668
+ *Returns:* The number of elements erased.
1669
 
1670
  *Throws:* Nothing unless an exception is thrown by `*i == value` or
1671
  `pred(*i) != false`.
1672
 
1673
+ *Remarks:* Stable [[algorithm.stable]].
1674
 
1675
  *Complexity:* Exactly `size()` applications of the corresponding
1676
  predicate.
1677
 
1678
  ``` cpp
1679
+ size_type unique();
1680
+ template<class BinaryPredicate> size_type unique(BinaryPredicate binary_pred);
1681
  ```
1682
 
1683
  *Effects:* Erases all but the first element from every consecutive group
1684
  of equal elements referred to by the iterator `i` in the range
1685
  \[`first + 1`, `last`) for which `*i == *(i-1)` (for the version of
1686
  `unique` with no arguments) or `pred(*i, *(i - 1))` (for the version of
1687
  `unique` with a predicate argument) holds. Invalidates only the
1688
  iterators and references to the erased elements.
1689
 
1690
+ *Returns:* The number of elements erased.
1691
+
1692
  *Throws:* Nothing unless an exception is thrown by `*i == *(i-1)` or
1693
  `pred(*i, *(i - 1))`
1694
 
1695
  *Complexity:* If the range `[first, last)` is not empty, exactly
1696
  `(last - first) - 1` applications of the corresponding predicate,
 
1701
  void merge(list&& x);
1702
  template<class Compare> void merge(list& x, Compare comp);
1703
  template<class Compare> void merge(list&& x, Compare comp);
1704
  ```
1705
 
1706
+ *Preconditions:* Both the list and the argument list shall be sorted
1707
+ with respect to the comparator `operator<` (for the first two overloads)
1708
+ or `comp` (for the last two overloads), and
1709
+ `get_allocator() == x.get_allocator()` is `true`.
1710
 
1711
+ *Effects:* If `addressof(x) == this`, does nothing; otherwise, merges
1712
+ the two sorted ranges `[begin(), end())` and `[x.begin(), x.end())`. The
1713
+ result is a range in which the elements will be sorted in non-decreasing
1714
+ order according to the ordering defined by `comp`; that is, for every
1715
+ iterator `i`, in the range other than the first, the condition
1716
  `comp(*i, *(i - 1))` will be `false`. Pointers and references to the
1717
  moved elements of `x` now refer to those same elements but as members of
1718
  `*this`. Iterators referring to the moved elements will continue to
1719
  refer to their elements, but they now behave as iterators into `*this`,
1720
  not into `x`.
1721
 
1722
+ *Remarks:* Stable [[algorithm.stable]]. If `addressof(x) != this`, the
1723
+ range `[x.begin(), x.end())` is empty after the merge. No elements are
1724
+ copied by this operation.
 
1725
 
1726
  *Complexity:* At most `size() + x.size() - 1` applications of `comp` if
1727
+ `addressof(x) != this`; otherwise, no applications of `comp` are
1728
+ performed. If an exception is thrown other than by a comparison there
1729
+ are no effects.
1730
 
1731
  ``` cpp
1732
  void reverse() noexcept;
1733
  ```
1734
 
 
1740
  ``` cpp
1741
  void sort();
1742
  template<class Compare> void sort(Compare comp);
1743
  ```
1744
 
 
 
 
1745
  *Effects:* Sorts the list according to the `operator<` or a `Compare`
1746
  function object. If an exception is thrown, the order of the elements in
1747
  `*this` is unspecified. Does not affect the validity of iterators and
1748
  references.
1749
 
1750
+ *Remarks:* Stable [[algorithm.stable]].
1751
 
1752
  *Complexity:* Approximately N log N comparisons, where `N == size()`.
1753
 
1754
+ #### Erasure <a id="list.erasure">[[list.erasure]]</a>
1755
 
1756
  ``` cpp
1757
+ template<class T, class Allocator, class U>
1758
+ typename list<T, Allocator>::size_type
1759
+ erase(list<T, Allocator>& c, const U& value);
1760
  ```
1761
 
1762
+ *Effects:* Equivalent to:
1763
+ `return erase_if(c, [&](auto& elem) { return elem == value; });`
1764
+
1765
+ ``` cpp
1766
+ template<class T, class Allocator, class Predicate>
1767
+ typename list<T, Allocator>::size_type
1768
+ erase_if(list<T, Allocator>& c, Predicate pred);
1769
+ ```
1770
+
1771
+ *Effects:* Equivalent to: `return c.remove_if(pred);`
1772
 
1773
  ### Class template `vector` <a id="vector">[[vector]]</a>
1774
 
1775
+ #### Overview <a id="vector.overview">[[vector.overview]]</a>
1776
 
1777
  A `vector` is a sequence container that supports (amortized) constant
1778
  time insert and erase operations at the end; insert and erase in the
1779
  middle take linear time. Storage management is handled automatically,
1780
  though hints can be given to improve efficiency.
1781
 
1782
+ A `vector` meets all of the requirements of a container and of a
1783
  reversible container (given in two tables in 
1784
  [[container.requirements]]), of a sequence container, including most of
1785
+ the optional sequence container requirements [[sequence.reqmts]], of an
1786
+ allocator-aware container ([[container.alloc.req]]), and, for an
1787
+ element type other than `bool`, of a contiguous container
1788
+ [[container.requirements.general]]. The exceptions are the `push_front`,
1789
+ `pop_front`, and `emplace_front` member functions, which are not
1790
+ provided. Descriptions are provided here only for operations on `vector`
1791
+ that are not described in one of these tables or for operations where
1792
+ there is additional semantic information.
1793
+
1794
+ The types `iterator` and `const_iterator` meet the constexpr iterator
1795
+ requirements [[iterator.requirements.general]].
1796
 
1797
  ``` cpp
1798
  namespace std {
1799
  template<class T, class Allocator = allocator<T>>
1800
  class vector {
1801
  public:
1802
+ // types
1803
  using value_type = T;
1804
  using allocator_type = Allocator;
1805
  using pointer = typename allocator_traits<Allocator>::pointer;
1806
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
1807
  using reference = value_type&;
 
1812
  using const_iterator = implementation-defined // type of vector::const_iterator; // see [container.requirements]
1813
  using reverse_iterator = std::reverse_iterator<iterator>;
1814
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1815
 
1816
  // [vector.cons], construct/copy/destroy
1817
+ constexpr vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
1818
+ constexpr explicit vector(const Allocator&) noexcept;
1819
+ constexpr explicit vector(size_type n, const Allocator& = Allocator());
1820
+ constexpr vector(size_type n, const T& value, const Allocator& = Allocator());
1821
  template<class InputIterator>
1822
+ constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
1823
+ constexpr vector(const vector& x);
1824
+ constexpr vector(vector&&) noexcept;
1825
+ constexpr vector(const vector&, const Allocator&);
1826
+ constexpr vector(vector&&, const Allocator&);
1827
+ constexpr vector(initializer_list<T>, const Allocator& = Allocator());
1828
+ constexpr ~vector();
1829
+ constexpr vector& operator=(const vector& x);
1830
+ constexpr vector& operator=(vector&& x)
1831
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
1832
  allocator_traits<Allocator>::is_always_equal::value);
1833
+ constexpr vector& operator=(initializer_list<T>);
1834
  template<class InputIterator>
1835
+ constexpr void assign(InputIterator first, InputIterator last);
1836
+ constexpr void assign(size_type n, const T& u);
1837
+ constexpr void assign(initializer_list<T>);
1838
+ constexpr allocator_type get_allocator() const noexcept;
1839
 
1840
+ // iterators
1841
+ constexpr iterator begin() noexcept;
1842
+ constexpr const_iterator begin() const noexcept;
1843
+ constexpr iterator end() noexcept;
1844
+ constexpr const_iterator end() const noexcept;
1845
+ constexpr reverse_iterator rbegin() noexcept;
1846
+ constexpr const_reverse_iterator rbegin() const noexcept;
1847
+ constexpr reverse_iterator rend() noexcept;
1848
+ constexpr const_reverse_iterator rend() const noexcept;
1849
 
1850
+ constexpr const_iterator cbegin() const noexcept;
1851
+ constexpr const_iterator cend() const noexcept;
1852
+ constexpr const_reverse_iterator crbegin() const noexcept;
1853
+ constexpr const_reverse_iterator crend() const noexcept;
1854
 
1855
  // [vector.capacity], capacity
1856
+ [[nodiscard]] constexpr bool empty() const noexcept;
1857
+ constexpr size_type size() const noexcept;
1858
+ constexpr size_type max_size() const noexcept;
1859
+ constexpr size_type capacity() const noexcept;
1860
+ constexpr void resize(size_type sz);
1861
+ constexpr void resize(size_type sz, const T& c);
1862
+ constexpr void reserve(size_type n);
1863
+ constexpr void shrink_to_fit();
1864
 
1865
+ // element access
1866
+ constexpr reference operator[](size_type n);
1867
+ constexpr const_reference operator[](size_type n) const;
1868
+ constexpr const_reference at(size_type n) const;
1869
+ constexpr reference at(size_type n);
1870
+ constexpr reference front();
1871
+ constexpr const_reference front() const;
1872
+ constexpr reference back();
1873
+ constexpr const_reference back() const;
1874
 
1875
  // [vector.data], data access
1876
+ constexpr T* data() noexcept;
1877
+ constexpr const T* data() const noexcept;
1878
 
1879
  // [vector.modifiers], modifiers
1880
+ template<class... Args> constexpr reference emplace_back(Args&&... args);
1881
+ constexpr void push_back(const T& x);
1882
+ constexpr void push_back(T&& x);
1883
+ constexpr void pop_back();
1884
 
1885
+ template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
1886
+ constexpr iterator insert(const_iterator position, const T& x);
1887
+ constexpr iterator insert(const_iterator position, T&& x);
1888
+ constexpr iterator insert(const_iterator position, size_type n, const T& x);
1889
  template<class InputIterator>
1890
+ constexpr iterator insert(const_iterator position,
1891
+ InputIterator first, InputIterator last);
1892
+ constexpr iterator insert(const_iterator position, initializer_list<T> il);
1893
+ constexpr iterator erase(const_iterator position);
1894
+ constexpr iterator erase(const_iterator first, const_iterator last);
1895
+ constexpr void swap(vector&)
1896
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1897
  allocator_traits<Allocator>::is_always_equal::value);
1898
+ constexpr void clear() noexcept;
1899
  };
1900
 
1901
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
 
1902
  vector(InputIterator, InputIterator, Allocator = Allocator())
1903
+ -> vector<iter-value-type<InputIterator>, Allocator>;
1904
 
1905
+ // swap
1906
  template<class T, class Allocator>
1907
+ constexpr void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1908
  noexcept(noexcept(x.swap(y)));
1909
  }
1910
  ```
1911
 
1912
  An incomplete type `T` may be used when instantiating `vector` if the
1913
+ allocator meets the allocator completeness requirements
1914
+ [[allocator.requirements.completeness]]. `T` shall be complete before
1915
  any member of the resulting specialization of `vector` is referenced.
1916
 
1917
+ #### Constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
1918
 
1919
  ``` cpp
1920
+ constexpr explicit vector(const Allocator&) noexcept;
1921
  ```
1922
 
1923
  *Effects:* Constructs an empty `vector`, using the specified allocator.
1924
 
1925
  *Complexity:* Constant.
1926
 
1927
  ``` cpp
1928
+ constexpr explicit vector(size_type n, const Allocator& = Allocator());
1929
  ```
1930
 
1931
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
1932
+
1933
  *Effects:* Constructs a `vector` with `n` default-inserted elements
1934
  using the specified allocator.
1935
 
 
 
1936
  *Complexity:* Linear in `n`.
1937
 
1938
  ``` cpp
1939
+ constexpr vector(size_type n, const T& value,
1940
  const Allocator& = Allocator());
1941
  ```
1942
 
1943
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
1944
+
1945
  *Effects:* Constructs a `vector` with `n` copies of `value`, using the
1946
  specified allocator.
1947
 
 
 
1948
  *Complexity:* Linear in `n`.
1949
 
1950
  ``` cpp
1951
  template<class InputIterator>
1952
+ constexpr vector(InputIterator first, InputIterator last,
1953
  const Allocator& = Allocator());
1954
  ```
1955
 
1956
  *Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
1957
  using the specified allocator.
 
1960
  is the distance between `first` and `last`) and no reallocations if
1961
  iterators `first` and `last` are of forward, bidirectional, or random
1962
  access categories. It makes order `N` calls to the copy constructor of
1963
  `T` and order log N reallocations if they are just input iterators.
1964
 
1965
+ #### Capacity <a id="vector.capacity">[[vector.capacity]]</a>
1966
 
1967
  ``` cpp
1968
+ constexpr size_type capacity() const noexcept;
1969
  ```
1970
 
1971
  *Returns:* The total number of elements that the vector can hold without
1972
  requiring reallocation.
1973
 
1974
+ *Complexity:* Constant time.
1975
+
1976
  ``` cpp
1977
+ constexpr void reserve(size_type n);
1978
  ```
1979
 
1980
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
1981
 
1982
  *Effects:* A directive that informs a `vector` of a planned change in
1983
  size, so that it can manage the storage allocation accordingly. After
1984
  `reserve()`, `capacity()` is greater or equal to the argument of
1985
  `reserve` if reallocation happens; and equal to the previous value of
1986
  `capacity()` otherwise. Reallocation happens at this point if and only
1987
  if the current capacity is less than the argument of `reserve()`. If an
1988
  exception is thrown other than by the move constructor of a
1989
+ non-*Cpp17CopyInsertable* type, there are no effects.
1990
 
1991
  *Complexity:* It does not change the size of the sequence and takes at
1992
  most linear time in the size of the sequence.
1993
 
1994
  *Throws:* `length_error` if `n > max_size()`.[^4]
1995
 
1996
  *Remarks:* Reallocation invalidates all the references, pointers, and
1997
+ iterators referring to the elements in the sequence, as well as the
1998
+ past-the-end iterator.
1999
+
2000
+ [*Note 1*: If no reallocation happens, they remain
2001
+ valid. — *end note*]
2002
+
2003
+ No reallocation shall take place during insertions that happen after a
2004
+ call to `reserve()` until an insertion would make the size of the vector
2005
+ greater than the value of `capacity()`.
2006
 
2007
  ``` cpp
2008
+ constexpr void shrink_to_fit();
2009
  ```
2010
 
2011
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
2012
 
2013
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
2014
  `capacity()` to `size()`.
2015
 
2016
+ [*Note 2*: The request is non-binding to allow latitude for
2017
  implementation-specific optimizations. — *end note*]
2018
 
2019
  It does not increase `capacity()`, but may reduce `capacity()` by
2020
  causing reallocation. If an exception is thrown other than by the move
2021
+ constructor of a non-*Cpp17CopyInsertable* `T` there are no effects.
2022
 
2023
+ *Complexity:* If reallocation happens, linear in the size of the
2024
+ sequence.
2025
 
2026
  *Remarks:* Reallocation invalidates all the references, pointers, and
2027
  iterators referring to the elements in the sequence as well as the
2028
+ past-the-end iterator.
2029
+
2030
+ [*Note 3*: If no reallocation happens, they remain
2031
+ valid. — *end note*]
2032
 
2033
  ``` cpp
2034
+ constexpr void swap(vector& x)
2035
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
2036
  allocator_traits<Allocator>::is_always_equal::value);
2037
  ```
2038
 
2039
  *Effects:* Exchanges the contents and `capacity()` of `*this` with that
2040
  of `x`.
2041
 
2042
  *Complexity:* Constant time.
2043
 
2044
  ``` cpp
2045
+ constexpr void resize(size_type sz);
2046
  ```
2047
 
2048
+ *Preconditions:* `T` is *Cpp17MoveInsertable* and
2049
+ *Cpp17DefaultInsertable* into `*this`.
2050
+
2051
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
2052
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
2053
  to the sequence.
2054
 
 
 
 
2055
  *Remarks:* If an exception is thrown other than by the move constructor
2056
+ of a non-*Cpp17CopyInsertable* `T` there are no effects.
2057
 
2058
  ``` cpp
2059
+ constexpr void resize(size_type sz, const T& c);
2060
  ```
2061
 
2062
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
2063
+
2064
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
2065
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
2066
  sequence.
2067
 
 
 
2068
  *Remarks:* If an exception is thrown there are no effects.
2069
 
2070
+ #### Data <a id="vector.data">[[vector.data]]</a>
2071
 
2072
  ``` cpp
2073
+ constexpr T* data() noexcept;
2074
+ constexpr const T* data() const noexcept;
2075
  ```
2076
 
2077
  *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
2078
  range. For a non-empty vector, `data()` `==` `addressof(front())`.
2079
 
2080
  *Complexity:* Constant time.
2081
 
2082
+ #### Modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
2083
 
2084
  ``` cpp
2085
+ constexpr iterator insert(const_iterator position, const T& x);
2086
+ constexpr iterator insert(const_iterator position, T&& x);
2087
+ constexpr iterator insert(const_iterator position, size_type n, const T& x);
2088
  template<class InputIterator>
2089
+ constexpr iterator insert(const_iterator position, InputIterator first, InputIterator last);
2090
+ constexpr iterator insert(const_iterator position, initializer_list<T>);
2091
 
2092
+ template<class... Args> constexpr reference emplace_back(Args&&... args);
2093
+ template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
2094
+ constexpr void push_back(const T& x);
2095
+ constexpr void push_back(T&& x);
2096
  ```
2097
 
2098
  *Remarks:* Causes reallocation if the new size is greater than the old
2099
  capacity. Reallocation invalidates all the references, pointers, and
2100
+ iterators referring to the elements in the sequence, as well as the
2101
+ past-the-end iterator. If no reallocation happens, then references,
2102
+ pointers, and iterators before the insertion point remain valid but
2103
+ those at or after the insertion point, including the past-the-end
2104
+ iterator, are invalidated. If an exception is thrown other than by the
2105
+ copy constructor, move constructor, assignment operator, or move
2106
+ assignment operator of `T` or by any `InputIterator` operation there are
2107
+ no effects. If an exception is thrown while inserting a single element
2108
+ at the end and `T` is *Cpp17CopyInsertable* or
2109
  `is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
2110
  Otherwise, if an exception is thrown by the move constructor of a
2111
+ non-*Cpp17CopyInsertable* `T`, the effects are unspecified.
2112
 
2113
+ *Complexity:* If reallocation happens, linear in the number of elements
2114
+ of the resulting vector; otherwise, linear in the number of elements
2115
  inserted plus the distance to the end of the vector.
2116
 
2117
  ``` cpp
2118
+ constexpr iterator erase(const_iterator position);
2119
+ constexpr iterator erase(const_iterator first, const_iterator last);
2120
+ constexpr void pop_back();
2121
  ```
2122
 
2123
  *Effects:* Invalidates iterators and references at or after the point of
2124
  the erase.
2125
 
 
2129
  vector after the erased elements.
2130
 
2131
  *Throws:* Nothing unless an exception is thrown by the assignment
2132
  operator or move assignment operator of `T`.
2133
 
2134
+ #### Erasure <a id="vector.erasure">[[vector.erasure]]</a>
2135
 
2136
  ``` cpp
2137
+ template<class T, class Allocator, class U>
2138
+ constexpr typename vector<T, Allocator>::size_type
2139
+ erase(vector<T, Allocator>& c, const U& value);
2140
  ```
2141
 
2142
+ *Effects:* Equivalent to:
2143
+
2144
+ ``` cpp
2145
+ auto it = remove(c.begin(), c.end(), value);
2146
+ auto r = distance(it, c.end());
2147
+ c.erase(it, c.end());
2148
+ return r;
2149
+ ```
2150
+
2151
+ ``` cpp
2152
+ template<class T, class Allocator, class Predicate>
2153
+ constexpr typename vector<T, Allocator>::size_type
2154
+ erase_if(vector<T, Allocator>& c, Predicate pred);
2155
+ ```
2156
+
2157
+ *Effects:* Equivalent to:
2158
+
2159
+ ``` cpp
2160
+ auto it = remove_if(c.begin(), c.end(), pred);
2161
+ auto r = distance(it, c.end());
2162
+ c.erase(it, c.end());
2163
+ return r;
2164
+ ```
2165
 
2166
  ### Class `vector<bool>` <a id="vector.bool">[[vector.bool]]</a>
2167
 
2168
  To optimize space allocation, a specialization of vector for `bool`
2169
  elements is provided:
 
2171
  ``` cpp
2172
  namespace std {
2173
  template<class Allocator>
2174
  class vector<bool, Allocator> {
2175
  public:
2176
+ // types
2177
  using value_type = bool;
2178
  using allocator_type = Allocator;
2179
  using pointer = implementation-defined;
2180
  using const_pointer = implementation-defined;
2181
  using const_reference = bool;
 
2184
  using iterator = implementation-defined // type of vector<bool>::iterator; // see [container.requirements]
2185
  using const_iterator = implementation-defined // type of vector<bool>::const_iterator; // see [container.requirements]
2186
  using reverse_iterator = std::reverse_iterator<iterator>;
2187
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
2188
 
2189
+ // bit reference
2190
  class reference {
2191
  friend class vector;
2192
+ constexpr reference() noexcept;
2193
  public:
2194
+ constexpr reference(const reference&) = default;
2195
+ constexpr ~reference();
2196
+ constexpr operator bool() const noexcept;
2197
+ constexpr reference& operator=(const bool x) noexcept;
2198
+ constexpr reference& operator=(const reference& x) noexcept;
2199
+ constexpr void flip() noexcept; // flips the bit
2200
  };
2201
 
2202
+ // construct/copy/destroy
2203
+ constexpr vector() : vector(Allocator()) { }
2204
+ constexpr explicit vector(const Allocator&);
2205
+ constexpr explicit vector(size_type n, const Allocator& = Allocator());
2206
+ constexpr vector(size_type n, const bool& value, const Allocator& = Allocator());
 
2207
  template<class InputIterator>
2208
+ constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
2209
+ constexpr vector(const vector& x);
2210
+ constexpr vector(vector&& x);
2211
+ constexpr vector(const vector&, const Allocator&);
2212
+ constexpr vector(vector&&, const Allocator&);
2213
+ constexpr vector(initializer_list<bool>, const Allocator& = Allocator()));
2214
+ constexpr ~vector();
2215
+ constexpr vector& operator=(const vector& x);
2216
+ constexpr vector& operator=(vector&& x);
2217
+ constexpr vector& operator=(initializer_list<bool>);
 
2218
  template<class InputIterator>
2219
+ constexpr void assign(InputIterator first, InputIterator last);
2220
+ constexpr void assign(size_type n, const bool& t);
2221
+ constexpr void assign(initializer_list<bool>);
2222
+ constexpr allocator_type get_allocator() const noexcept;
2223
 
2224
+ // iterators
2225
+ constexpr iterator begin() noexcept;
2226
+ constexpr const_iterator begin() const noexcept;
2227
+ constexpr iterator end() noexcept;
2228
+ constexpr const_iterator end() const noexcept;
2229
+ constexpr reverse_iterator rbegin() noexcept;
2230
+ constexpr const_reverse_iterator rbegin() const noexcept;
2231
+ constexpr reverse_iterator rend() noexcept;
2232
+ constexpr const_reverse_iterator rend() const noexcept;
2233
 
2234
+ constexpr const_iterator cbegin() const noexcept;
2235
+ constexpr const_iterator cend() const noexcept;
2236
+ constexpr const_reverse_iterator crbegin() const noexcept;
2237
+ constexpr const_reverse_iterator crend() const noexcept;
2238
 
2239
+ // capacity
2240
+ [[nodiscard]] constexpr bool empty() const noexcept;
2241
+ constexpr size_type size() const noexcept;
2242
+ constexpr size_type max_size() const noexcept;
2243
+ constexpr size_type capacity() const noexcept;
2244
+ constexpr void resize(size_type sz, bool c = false);
2245
+ constexpr void reserve(size_type n);
2246
+ constexpr void shrink_to_fit();
2247
 
2248
+ // element access
2249
+ constexpr reference operator[](size_type n);
2250
+ constexpr const_reference operator[](size_type n) const;
2251
+ constexpr const_reference at(size_type n) const;
2252
+ constexpr reference at(size_type n);
2253
+ constexpr reference front();
2254
+ constexpr const_reference front() const;
2255
+ constexpr reference back();
2256
+ constexpr const_reference back() const;
2257
 
2258
+ // modifiers
2259
+ template<class... Args> constexpr reference emplace_back(Args&&... args);
2260
+ constexpr void push_back(const bool& x);
2261
+ constexpr void pop_back();
2262
+ template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
2263
+ constexpr iterator insert(const_iterator position, const bool& x);
2264
+ constexpr iterator insert(const_iterator position, size_type n, const bool& x);
2265
  template<class InputIterator>
2266
+ constexpr iterator insert(const_iterator position,
2267
  InputIterator first, InputIterator last);
2268
+ constexpr iterator insert(const_iterator position, initializer_list<bool> il);
2269
 
2270
+ constexpr iterator erase(const_iterator position);
2271
+ constexpr iterator erase(const_iterator first, const_iterator last);
2272
+ constexpr void swap(vector&);
2273
+ constexpr static void swap(reference x, reference y) noexcept;
2274
+ constexpr void flip() noexcept; // flips all bits
2275
+ constexpr void clear() noexcept;
2276
  };
2277
  }
2278
  ```
2279
 
2280
  Unless described below, all operations have the same requirements and
2281
  semantics as the primary `vector` template, except that operations
2282
  dealing with the `bool` value type map to bit values in the container
2283
+ storage and `allocator_traits::construct` [[allocator.traits.members]]
2284
+ is not used to construct these values.
2285
 
2286
  There is no requirement that the data be stored as a contiguous
2287
  allocation of `bool` values. A space-optimized representation of bits is
2288
  recommended instead.
2289
 
 
2294
  set, and `false` otherwise. The assignment operator sets the bit when
2295
  the argument is (convertible to) `true` and clears it otherwise. `flip`
2296
  reverses the state of the bit.
2297
 
2298
  ``` cpp
2299
+ constexpr void flip() noexcept;
2300
  ```
2301
 
2302
  *Effects:* Replaces each element in the container with its complement.
2303
 
2304
  ``` cpp
2305
+ constexpr static void swap(reference x, reference y) noexcept;
2306
  ```
2307
 
2308
  *Effects:* Exchanges the contents of `x` and `y` as if by:
2309
 
2310
  ``` cpp
 
2315
 
2316
  ``` cpp
2317
  template<class Allocator> struct hash<vector<bool, Allocator>>;
2318
  ```
2319
 
2320
+ The specialization is enabled [[unord.hash]].
2321