From Jason Turner

[vector]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpznmk2nzj/{from.md → to.md} +184 -158
tmp/tmpznmk2nzj/{from.md → to.md} RENAMED
@@ -1,32 +1,35 @@
1
  ### Class template `vector` <a id="vector">[[vector]]</a>
2
 
3
- #### Class template `vector` overview <a id="vector.overview">[[vector.overview]]</a>
4
 
5
  A `vector` is a sequence container that supports (amortized) constant
6
  time insert and erase operations at the end; insert and erase in the
7
  middle take linear time. Storage management is handled automatically,
8
  though hints can be given to improve efficiency.
9
 
10
- A `vector` satisfies all of the requirements of a container and of a
11
  reversible container (given in two tables in 
12
  [[container.requirements]]), of a sequence container, including most of
13
- the optional sequence container requirements ([[sequence.reqmts]]), of
14
- an allocator-aware container (Table  [[tab:containers.allocatoraware]]),
15
- and, for an element type other than `bool`, of a contiguous container (
16
- [[container.requirements.general]]). The exceptions are the
17
- `push_front`, `pop_front`, and `emplace_front` member functions, which
18
- are not provided. Descriptions are provided here only for operations on
19
- `vector` that are not described in one of these tables or for operations
20
- where there is additional semantic information.
 
 
 
21
 
22
  ``` cpp
23
  namespace std {
24
  template<class T, class Allocator = allocator<T>>
25
  class vector {
26
  public:
27
- // types:
28
  using value_type = T;
29
  using allocator_type = Allocator;
30
  using pointer = typename allocator_traits<Allocator>::pointer;
31
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
32
  using reference = value_type&;
@@ -37,159 +40,146 @@ namespace std {
37
  using const_iterator = implementation-defined // type of vector::const_iterator; // see [container.requirements]
38
  using reverse_iterator = std::reverse_iterator<iterator>;
39
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
40
 
41
  // [vector.cons], construct/copy/destroy
42
- vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
43
- explicit vector(const Allocator&) noexcept;
44
- explicit vector(size_type n, const Allocator& = Allocator());
45
- vector(size_type n, const T& value, const Allocator& = Allocator());
46
  template<class InputIterator>
47
- vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
48
- vector(const vector& x);
49
- vector(vector&&) noexcept;
50
- vector(const vector&, const Allocator&);
51
- vector(vector&&, const Allocator&);
52
- vector(initializer_list<T>, const Allocator& = Allocator());
53
- ~vector();
54
- vector& operator=(const vector& x);
55
- vector& operator=(vector&& x)
56
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
57
  allocator_traits<Allocator>::is_always_equal::value);
58
- vector& operator=(initializer_list<T>);
59
  template<class InputIterator>
60
- void assign(InputIterator first, InputIterator last);
61
- void assign(size_type n, const T& u);
62
- void assign(initializer_list<T>);
63
- allocator_type get_allocator() const noexcept;
64
 
65
- // iterators:
66
- iterator begin() noexcept;
67
- const_iterator begin() const noexcept;
68
- iterator end() noexcept;
69
- const_iterator end() const noexcept;
70
- reverse_iterator rbegin() noexcept;
71
- const_reverse_iterator rbegin() const noexcept;
72
- reverse_iterator rend() noexcept;
73
- const_reverse_iterator rend() const noexcept;
74
 
75
- const_iterator cbegin() const noexcept;
76
- const_iterator cend() const noexcept;
77
- const_reverse_iterator crbegin() const noexcept;
78
- const_reverse_iterator crend() const noexcept;
79
 
80
  // [vector.capacity], capacity
81
- bool empty() const noexcept;
82
- size_type size() const noexcept;
83
- size_type max_size() const noexcept;
84
- size_type capacity() const noexcept;
85
- void resize(size_type sz);
86
- void resize(size_type sz, const T& c);
87
- void reserve(size_type n);
88
- void shrink_to_fit();
89
 
90
- // element access:
91
- reference operator[](size_type n);
92
- const_reference operator[](size_type n) const;
93
- const_reference at(size_type n) const;
94
- reference at(size_type n);
95
- reference front();
96
- const_reference front() const;
97
- reference back();
98
- const_reference back() const;
99
 
100
  // [vector.data], data access
101
- T* data() noexcept;
102
- const T* data() const noexcept;
103
 
104
  // [vector.modifiers], modifiers
105
- template <class... Args> reference emplace_back(Args&&... args);
106
- void push_back(const T& x);
107
- void push_back(T&& x);
108
- void pop_back();
109
 
110
- template <class... Args> iterator emplace(const_iterator position, Args&&... args);
111
- iterator insert(const_iterator position, const T& x);
112
- iterator insert(const_iterator position, T&& x);
113
- iterator insert(const_iterator position, size_type n, const T& x);
114
  template<class InputIterator>
115
- iterator insert(const_iterator position, InputIterator first, InputIterator last);
116
- iterator insert(const_iterator position, initializer_list<T> il);
117
- iterator erase(const_iterator position);
118
- iterator erase(const_iterator first, const_iterator last);
119
- void swap(vector&)
 
120
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
121
  allocator_traits<Allocator>::is_always_equal::value);
122
- void clear() noexcept;
123
  };
124
 
125
- template<class InputIterator,
126
- class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
127
  vector(InputIterator, InputIterator, Allocator = Allocator())
128
- -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
129
 
 
130
  template<class T, class Allocator>
131
- bool operator==(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
132
- template <class T, class Allocator>
133
- bool operator< (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
134
- template <class T, class Allocator>
135
- bool operator!=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
136
- template <class T, class Allocator>
137
- bool operator> (const vector<T, Allocator>& x, const vector<T, Allocator>& y);
138
- template <class T, class Allocator>
139
- bool operator>=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
140
- template <class T, class Allocator>
141
- bool operator<=(const vector<T, Allocator>& x, const vector<T, Allocator>& y);
142
-
143
- // [vector.special], specialized algorithms
144
- template <class T, class Allocator>
145
- void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
146
  noexcept(noexcept(x.swap(y)));
147
  }
148
  ```
149
 
150
  An incomplete type `T` may be used when instantiating `vector` if the
151
- allocator satisfies the allocator completeness requirements (
152
- [[allocator.requirements.completeness]]). `T` shall be complete before
153
  any member of the resulting specialization of `vector` is referenced.
154
 
155
- #### `vector` constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
156
 
157
  ``` cpp
158
- explicit vector(const Allocator&);
159
  ```
160
 
161
  *Effects:* Constructs an empty `vector`, using the specified allocator.
162
 
163
  *Complexity:* Constant.
164
 
165
  ``` cpp
166
- explicit vector(size_type n, const Allocator& = Allocator());
167
  ```
168
 
 
 
169
  *Effects:* Constructs a `vector` with `n` default-inserted elements
170
  using the specified allocator.
171
 
172
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
173
-
174
  *Complexity:* Linear in `n`.
175
 
176
  ``` cpp
177
- vector(size_type n, const T& value,
178
  const Allocator& = Allocator());
179
  ```
180
 
 
 
181
  *Effects:* Constructs a `vector` with `n` copies of `value`, using the
182
  specified allocator.
183
 
184
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
185
-
186
  *Complexity:* Linear in `n`.
187
 
188
  ``` cpp
189
  template<class InputIterator>
190
- vector(InputIterator first, InputIterator last,
191
  const Allocator& = Allocator());
192
  ```
193
 
194
  *Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
195
  using the specified allocator.
@@ -198,152 +188,166 @@ using the specified allocator.
198
  is the distance between `first` and `last`) and no reallocations if
199
  iterators `first` and `last` are of forward, bidirectional, or random
200
  access categories. It makes order `N` calls to the copy constructor of
201
  `T` and order log N reallocations if they are just input iterators.
202
 
203
- #### `vector` capacity <a id="vector.capacity">[[vector.capacity]]</a>
204
 
205
  ``` cpp
206
- size_type capacity() const noexcept;
207
  ```
208
 
209
  *Returns:* The total number of elements that the vector can hold without
210
  requiring reallocation.
211
 
 
 
212
  ``` cpp
213
- void reserve(size_type n);
214
  ```
215
 
216
- *Requires:* `T` shall be `MoveInsertable` into `*this`.
217
 
218
  *Effects:* A directive that informs a `vector` of a planned change in
219
  size, so that it can manage the storage allocation accordingly. After
220
  `reserve()`, `capacity()` is greater or equal to the argument of
221
  `reserve` if reallocation happens; and equal to the previous value of
222
  `capacity()` otherwise. Reallocation happens at this point if and only
223
  if the current capacity is less than the argument of `reserve()`. If an
224
  exception is thrown other than by the move constructor of a
225
- non-`CopyInsertable` type, there are no effects.
226
 
227
  *Complexity:* It does not change the size of the sequence and takes at
228
  most linear time in the size of the sequence.
229
 
230
  *Throws:* `length_error` if `n > max_size()`.[^4]
231
 
232
  *Remarks:* Reallocation invalidates all the references, pointers, and
233
- iterators referring to the elements in the sequence. No reallocation
234
- shall take place during insertions that happen after a call to
235
- `reserve()` until the time when an insertion would make the size of the
236
- vector greater than the value of `capacity()`.
 
 
 
 
 
237
 
238
  ``` cpp
239
- void shrink_to_fit();
240
  ```
241
 
242
- *Requires:* `T` shall be `MoveInsertable` into `*this`.
243
 
244
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
245
  `capacity()` to `size()`.
246
 
247
- [*Note 1*: The request is non-binding to allow latitude for
248
  implementation-specific optimizations. — *end note*]
249
 
250
  It does not increase `capacity()`, but may reduce `capacity()` by
251
  causing reallocation. If an exception is thrown other than by the move
252
- constructor of a non-`CopyInsertable` `T` there are no effects.
253
 
254
- *Complexity:* Linear in the size of the sequence.
 
255
 
256
  *Remarks:* Reallocation invalidates all the references, pointers, and
257
  iterators referring to the elements in the sequence as well as the
258
- past-the-end iterator. If no reallocation happens, they remain valid.
 
 
 
259
 
260
  ``` cpp
261
- void swap(vector& x)
262
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
263
  allocator_traits<Allocator>::is_always_equal::value);
264
  ```
265
 
266
  *Effects:* Exchanges the contents and `capacity()` of `*this` with that
267
  of `x`.
268
 
269
  *Complexity:* Constant time.
270
 
271
  ``` cpp
272
- void resize(size_type sz);
273
  ```
274
 
 
 
 
275
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
276
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
277
  to the sequence.
278
 
279
- *Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
280
- `*this`.
281
-
282
  *Remarks:* If an exception is thrown other than by the move constructor
283
- of a non-`CopyInsertable` `T` there are no effects.
284
 
285
  ``` cpp
286
- void resize(size_type sz, const T& c);
287
  ```
288
 
 
 
289
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
290
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
291
  sequence.
292
 
293
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
294
-
295
  *Remarks:* If an exception is thrown there are no effects.
296
 
297
- #### `vector` data <a id="vector.data">[[vector.data]]</a>
298
 
299
  ``` cpp
300
- T* data() noexcept;
301
- const T* data() const noexcept;
302
  ```
303
 
304
  *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
305
  range. For a non-empty vector, `data()` `==` `addressof(front())`.
306
 
307
  *Complexity:* Constant time.
308
 
309
- #### `vector` modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
310
 
311
  ``` cpp
312
- iterator insert(const_iterator position, const T& x);
313
- iterator insert(const_iterator position, T&& x);
314
- iterator insert(const_iterator position, size_type n, const T& x);
315
  template<class InputIterator>
316
- iterator insert(const_iterator position, InputIterator first, InputIterator last);
317
- iterator insert(const_iterator position, initializer_list<T>);
318
 
319
- template <class... Args> reference emplace_back(Args&&... args);
320
- template <class... Args> iterator emplace(const_iterator position, Args&&... args);
321
- void push_back(const T& x);
322
- void push_back(T&& x);
323
  ```
324
 
325
  *Remarks:* Causes reallocation if the new size is greater than the old
326
  capacity. Reallocation invalidates all the references, pointers, and
327
- iterators referring to the elements in the sequence. If no reallocation
328
- happens, all the iterators and references before the insertion point
329
- remain valid. If an exception is thrown other than by the copy
330
- constructor, move constructor, assignment operator, or move assignment
331
- operator of `T` or by any `InputIterator` operation there are no
332
- effects. If an exception is thrown while inserting a single element at
333
- the end and `T` is `CopyInsertable` or
 
 
334
  `is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
335
  Otherwise, if an exception is thrown by the move constructor of a
336
- non-`CopyInsertable` `T`, the effects are unspecified.
337
 
338
- *Complexity:* The complexity is linear in the number of elements
 
339
  inserted plus the distance to the end of the vector.
340
 
341
  ``` cpp
342
- iterator erase(const_iterator position);
343
- iterator erase(const_iterator first, const_iterator last);
344
- void pop_back();
345
  ```
346
 
347
  *Effects:* Invalidates iterators and references at or after the point of
348
  the erase.
349
 
@@ -353,15 +357,37 @@ is called the number of times equal to the number of elements in the
353
  vector after the erased elements.
354
 
355
  *Throws:* Nothing unless an exception is thrown by the assignment
356
  operator or move assignment operator of `T`.
357
 
358
- #### `vector` specialized algorithms <a id="vector.special">[[vector.special]]</a>
359
 
360
  ``` cpp
361
- template <class T, class Allocator>
362
- void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
363
- noexcept(noexcept(x.swap(y)));
364
  ```
365
 
366
- *Effects:* As if by `x.swap(y)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
 
 
1
  ### Class template `vector` <a id="vector">[[vector]]</a>
2
 
3
+ #### Overview <a id="vector.overview">[[vector.overview]]</a>
4
 
5
  A `vector` is a sequence container that supports (amortized) constant
6
  time insert and erase operations at the end; insert and erase in the
7
  middle take linear time. Storage management is handled automatically,
8
  though hints can be given to improve efficiency.
9
 
10
+ A `vector` meets all of the requirements of a container and of a
11
  reversible container (given in two tables in 
12
  [[container.requirements]]), of a sequence container, including most of
13
+ the optional sequence container requirements [[sequence.reqmts]], of an
14
+ allocator-aware container ([[container.alloc.req]]), and, for an
15
+ element type other than `bool`, of a contiguous container
16
+ [[container.requirements.general]]. The exceptions are the `push_front`,
17
+ `pop_front`, and `emplace_front` member functions, which are not
18
+ provided. Descriptions are provided here only for operations on `vector`
19
+ that are not described in one of these tables or for operations where
20
+ there is additional semantic information.
21
+
22
+ The types `iterator` and `const_iterator` meet the constexpr iterator
23
+ requirements [[iterator.requirements.general]].
24
 
25
  ``` cpp
26
  namespace std {
27
  template<class T, class Allocator = allocator<T>>
28
  class vector {
29
  public:
30
+ // types
31
  using value_type = T;
32
  using allocator_type = Allocator;
33
  using pointer = typename allocator_traits<Allocator>::pointer;
34
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
35
  using reference = value_type&;
 
40
  using const_iterator = implementation-defined // type of vector::const_iterator; // see [container.requirements]
41
  using reverse_iterator = std::reverse_iterator<iterator>;
42
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
43
 
44
  // [vector.cons], construct/copy/destroy
45
+ constexpr vector() noexcept(noexcept(Allocator())) : vector(Allocator()) { }
46
+ constexpr explicit vector(const Allocator&) noexcept;
47
+ constexpr explicit vector(size_type n, const Allocator& = Allocator());
48
+ constexpr vector(size_type n, const T& value, const Allocator& = Allocator());
49
  template<class InputIterator>
50
+ constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator());
51
+ constexpr vector(const vector& x);
52
+ constexpr vector(vector&&) noexcept;
53
+ constexpr vector(const vector&, const Allocator&);
54
+ constexpr vector(vector&&, const Allocator&);
55
+ constexpr vector(initializer_list<T>, const Allocator& = Allocator());
56
+ constexpr ~vector();
57
+ constexpr vector& operator=(const vector& x);
58
+ constexpr vector& operator=(vector&& x)
59
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
60
  allocator_traits<Allocator>::is_always_equal::value);
61
+ constexpr vector& operator=(initializer_list<T>);
62
  template<class InputIterator>
63
+ constexpr void assign(InputIterator first, InputIterator last);
64
+ constexpr void assign(size_type n, const T& u);
65
+ constexpr void assign(initializer_list<T>);
66
+ constexpr allocator_type get_allocator() const noexcept;
67
 
68
+ // iterators
69
+ constexpr iterator begin() noexcept;
70
+ constexpr const_iterator begin() const noexcept;
71
+ constexpr iterator end() noexcept;
72
+ constexpr const_iterator end() const noexcept;
73
+ constexpr reverse_iterator rbegin() noexcept;
74
+ constexpr const_reverse_iterator rbegin() const noexcept;
75
+ constexpr reverse_iterator rend() noexcept;
76
+ constexpr const_reverse_iterator rend() const noexcept;
77
 
78
+ constexpr const_iterator cbegin() const noexcept;
79
+ constexpr const_iterator cend() const noexcept;
80
+ constexpr const_reverse_iterator crbegin() const noexcept;
81
+ constexpr const_reverse_iterator crend() const noexcept;
82
 
83
  // [vector.capacity], capacity
84
+ [[nodiscard]] constexpr bool empty() const noexcept;
85
+ constexpr size_type size() const noexcept;
86
+ constexpr size_type max_size() const noexcept;
87
+ constexpr size_type capacity() const noexcept;
88
+ constexpr void resize(size_type sz);
89
+ constexpr void resize(size_type sz, const T& c);
90
+ constexpr void reserve(size_type n);
91
+ constexpr void shrink_to_fit();
92
 
93
+ // element access
94
+ constexpr reference operator[](size_type n);
95
+ constexpr const_reference operator[](size_type n) const;
96
+ constexpr const_reference at(size_type n) const;
97
+ constexpr reference at(size_type n);
98
+ constexpr reference front();
99
+ constexpr const_reference front() const;
100
+ constexpr reference back();
101
+ constexpr const_reference back() const;
102
 
103
  // [vector.data], data access
104
+ constexpr T* data() noexcept;
105
+ constexpr const T* data() const noexcept;
106
 
107
  // [vector.modifiers], modifiers
108
+ template<class... Args> constexpr reference emplace_back(Args&&... args);
109
+ constexpr void push_back(const T& x);
110
+ constexpr void push_back(T&& x);
111
+ constexpr void pop_back();
112
 
113
+ template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
114
+ constexpr iterator insert(const_iterator position, const T& x);
115
+ constexpr iterator insert(const_iterator position, T&& x);
116
+ constexpr iterator insert(const_iterator position, size_type n, const T& x);
117
  template<class InputIterator>
118
+ constexpr iterator insert(const_iterator position,
119
+ InputIterator first, InputIterator last);
120
+ constexpr iterator insert(const_iterator position, initializer_list<T> il);
121
+ constexpr iterator erase(const_iterator position);
122
+ constexpr iterator erase(const_iterator first, const_iterator last);
123
+ constexpr void swap(vector&)
124
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
125
  allocator_traits<Allocator>::is_always_equal::value);
126
+ constexpr void clear() noexcept;
127
  };
128
 
129
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
 
130
  vector(InputIterator, InputIterator, Allocator = Allocator())
131
+ -> vector<iter-value-type<InputIterator>, Allocator>;
132
 
133
+ // swap
134
  template<class T, class Allocator>
135
+ constexpr void swap(vector<T, Allocator>& x, vector<T, Allocator>& y)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  noexcept(noexcept(x.swap(y)));
137
  }
138
  ```
139
 
140
  An incomplete type `T` may be used when instantiating `vector` if the
141
+ allocator meets the allocator completeness requirements
142
+ [[allocator.requirements.completeness]]. `T` shall be complete before
143
  any member of the resulting specialization of `vector` is referenced.
144
 
145
+ #### Constructors, copy, and assignment <a id="vector.cons">[[vector.cons]]</a>
146
 
147
  ``` cpp
148
+ constexpr explicit vector(const Allocator&) noexcept;
149
  ```
150
 
151
  *Effects:* Constructs an empty `vector`, using the specified allocator.
152
 
153
  *Complexity:* Constant.
154
 
155
  ``` cpp
156
+ constexpr explicit vector(size_type n, const Allocator& = Allocator());
157
  ```
158
 
159
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
160
+
161
  *Effects:* Constructs a `vector` with `n` default-inserted elements
162
  using the specified allocator.
163
 
 
 
164
  *Complexity:* Linear in `n`.
165
 
166
  ``` cpp
167
+ constexpr vector(size_type n, const T& value,
168
  const Allocator& = Allocator());
169
  ```
170
 
171
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
172
+
173
  *Effects:* Constructs a `vector` with `n` copies of `value`, using the
174
  specified allocator.
175
 
 
 
176
  *Complexity:* Linear in `n`.
177
 
178
  ``` cpp
179
  template<class InputIterator>
180
+ constexpr vector(InputIterator first, InputIterator last,
181
  const Allocator& = Allocator());
182
  ```
183
 
184
  *Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
185
  using the specified allocator.
 
188
  is the distance between `first` and `last`) and no reallocations if
189
  iterators `first` and `last` are of forward, bidirectional, or random
190
  access categories. It makes order `N` calls to the copy constructor of
191
  `T` and order log N reallocations if they are just input iterators.
192
 
193
+ #### Capacity <a id="vector.capacity">[[vector.capacity]]</a>
194
 
195
  ``` cpp
196
+ constexpr size_type capacity() const noexcept;
197
  ```
198
 
199
  *Returns:* The total number of elements that the vector can hold without
200
  requiring reallocation.
201
 
202
+ *Complexity:* Constant time.
203
+
204
  ``` cpp
205
+ constexpr void reserve(size_type n);
206
  ```
207
 
208
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
209
 
210
  *Effects:* A directive that informs a `vector` of a planned change in
211
  size, so that it can manage the storage allocation accordingly. After
212
  `reserve()`, `capacity()` is greater or equal to the argument of
213
  `reserve` if reallocation happens; and equal to the previous value of
214
  `capacity()` otherwise. Reallocation happens at this point if and only
215
  if the current capacity is less than the argument of `reserve()`. If an
216
  exception is thrown other than by the move constructor of a
217
+ non-*Cpp17CopyInsertable* type, there are no effects.
218
 
219
  *Complexity:* It does not change the size of the sequence and takes at
220
  most linear time in the size of the sequence.
221
 
222
  *Throws:* `length_error` if `n > max_size()`.[^4]
223
 
224
  *Remarks:* Reallocation invalidates all the references, pointers, and
225
+ iterators referring to the elements in the sequence, as well as the
226
+ past-the-end iterator.
227
+
228
+ [*Note 1*: If no reallocation happens, they remain
229
+ valid. — *end note*]
230
+
231
+ No reallocation shall take place during insertions that happen after a
232
+ call to `reserve()` until an insertion would make the size of the vector
233
+ greater than the value of `capacity()`.
234
 
235
  ``` cpp
236
+ constexpr void shrink_to_fit();
237
  ```
238
 
239
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
240
 
241
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
242
  `capacity()` to `size()`.
243
 
244
+ [*Note 2*: The request is non-binding to allow latitude for
245
  implementation-specific optimizations. — *end note*]
246
 
247
  It does not increase `capacity()`, but may reduce `capacity()` by
248
  causing reallocation. If an exception is thrown other than by the move
249
+ constructor of a non-*Cpp17CopyInsertable* `T` there are no effects.
250
 
251
+ *Complexity:* If reallocation happens, linear in the size of the
252
+ sequence.
253
 
254
  *Remarks:* Reallocation invalidates all the references, pointers, and
255
  iterators referring to the elements in the sequence as well as the
256
+ past-the-end iterator.
257
+
258
+ [*Note 3*: If no reallocation happens, they remain
259
+ valid. — *end note*]
260
 
261
  ``` cpp
262
+ constexpr void swap(vector& x)
263
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
264
  allocator_traits<Allocator>::is_always_equal::value);
265
  ```
266
 
267
  *Effects:* Exchanges the contents and `capacity()` of `*this` with that
268
  of `x`.
269
 
270
  *Complexity:* Constant time.
271
 
272
  ``` cpp
273
+ constexpr void resize(size_type sz);
274
  ```
275
 
276
+ *Preconditions:* `T` is *Cpp17MoveInsertable* and
277
+ *Cpp17DefaultInsertable* into `*this`.
278
+
279
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
280
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
281
  to the sequence.
282
 
 
 
 
283
  *Remarks:* If an exception is thrown other than by the move constructor
284
+ of a non-*Cpp17CopyInsertable* `T` there are no effects.
285
 
286
  ``` cpp
287
+ constexpr void resize(size_type sz, const T& c);
288
  ```
289
 
290
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
291
+
292
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
293
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
294
  sequence.
295
 
 
 
296
  *Remarks:* If an exception is thrown there are no effects.
297
 
298
+ #### Data <a id="vector.data">[[vector.data]]</a>
299
 
300
  ``` cpp
301
+ constexpr T* data() noexcept;
302
+ constexpr const T* data() const noexcept;
303
  ```
304
 
305
  *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
306
  range. For a non-empty vector, `data()` `==` `addressof(front())`.
307
 
308
  *Complexity:* Constant time.
309
 
310
+ #### Modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
311
 
312
  ``` cpp
313
+ constexpr iterator insert(const_iterator position, const T& x);
314
+ constexpr iterator insert(const_iterator position, T&& x);
315
+ constexpr iterator insert(const_iterator position, size_type n, const T& x);
316
  template<class InputIterator>
317
+ constexpr iterator insert(const_iterator position, InputIterator first, InputIterator last);
318
+ constexpr iterator insert(const_iterator position, initializer_list<T>);
319
 
320
+ template<class... Args> constexpr reference emplace_back(Args&&... args);
321
+ template<class... Args> constexpr iterator emplace(const_iterator position, Args&&... args);
322
+ constexpr void push_back(const T& x);
323
+ constexpr void push_back(T&& x);
324
  ```
325
 
326
  *Remarks:* Causes reallocation if the new size is greater than the old
327
  capacity. Reallocation invalidates all the references, pointers, and
328
+ iterators referring to the elements in the sequence, as well as the
329
+ past-the-end iterator. If no reallocation happens, then references,
330
+ pointers, and iterators before the insertion point remain valid but
331
+ those at or after the insertion point, including the past-the-end
332
+ iterator, are invalidated. If an exception is thrown other than by the
333
+ copy constructor, move constructor, assignment operator, or move
334
+ assignment operator of `T` or by any `InputIterator` operation there are
335
+ no effects. If an exception is thrown while inserting a single element
336
+ at the end and `T` is *Cpp17CopyInsertable* or
337
  `is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
338
  Otherwise, if an exception is thrown by the move constructor of a
339
+ non-*Cpp17CopyInsertable* `T`, the effects are unspecified.
340
 
341
+ *Complexity:* If reallocation happens, linear in the number of elements
342
+ of the resulting vector; otherwise, linear in the number of elements
343
  inserted plus the distance to the end of the vector.
344
 
345
  ``` cpp
346
+ constexpr iterator erase(const_iterator position);
347
+ constexpr iterator erase(const_iterator first, const_iterator last);
348
+ constexpr void pop_back();
349
  ```
350
 
351
  *Effects:* Invalidates iterators and references at or after the point of
352
  the erase.
353
 
 
357
  vector after the erased elements.
358
 
359
  *Throws:* Nothing unless an exception is thrown by the assignment
360
  operator or move assignment operator of `T`.
361
 
362
+ #### Erasure <a id="vector.erasure">[[vector.erasure]]</a>
363
 
364
  ``` cpp
365
+ template<class T, class Allocator, class U>
366
+ constexpr typename vector<T, Allocator>::size_type
367
+ erase(vector<T, Allocator>& c, const U& value);
368
  ```
369
 
370
+ *Effects:* Equivalent to:
371
+
372
+ ``` cpp
373
+ auto it = remove(c.begin(), c.end(), value);
374
+ auto r = distance(it, c.end());
375
+ c.erase(it, c.end());
376
+ return r;
377
+ ```
378
+
379
+ ``` cpp
380
+ template<class T, class Allocator, class Predicate>
381
+ constexpr typename vector<T, Allocator>::size_type
382
+ erase_if(vector<T, Allocator>& c, Predicate pred);
383
+ ```
384
+
385
+ *Effects:* Equivalent to:
386
+
387
+ ``` cpp
388
+ auto it = remove_if(c.begin(), c.end(), pred);
389
+ auto r = distance(it, c.end());
390
+ c.erase(it, c.end());
391
+ return r;
392
+ ```
393