From Jason Turner

[vector]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmphpwjezv3/{from.md → to.md} +48 -30
tmp/tmphpwjezv3/{from.md → to.md} RENAMED
@@ -28,12 +28,12 @@ namespace std {
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&;
36
  using const_reference = const value_type&;
37
  using size_type = implementation-defined // type of vector::size_type; // see [container.requirements]
38
  using difference_type = implementation-defined // type of vector::difference_type; // see [container.requirements]
39
  using iterator = implementation-defined // type of vector::iterator; // see [container.requirements]
@@ -83,11 +83,11 @@ namespace std {
83
  constexpr const_iterator cend() const noexcept;
84
  constexpr const_reverse_iterator crbegin() const noexcept;
85
  constexpr const_reverse_iterator crend() const noexcept;
86
 
87
  // [vector.capacity], capacity
88
- [[nodiscard]] constexpr bool empty() const noexcept;
89
  constexpr size_type size() const noexcept;
90
  constexpr size_type max_size() const noexcept;
91
  constexpr size_type capacity() const noexcept;
92
  constexpr void resize(size_type sz);
93
  constexpr void resize(size_type sz, const T& c);
@@ -95,12 +95,12 @@ namespace std {
95
  constexpr void shrink_to_fit();
96
 
97
  // element access
98
  constexpr reference operator[](size_type n);
99
  constexpr const_reference operator[](size_type n) const;
100
- constexpr const_reference at(size_type n) const;
101
  constexpr reference at(size_type n);
 
102
  constexpr reference front();
103
  constexpr const_reference front() const;
104
  constexpr reference back();
105
  constexpr const_reference back() const;
106
 
@@ -161,11 +161,11 @@ constexpr explicit vector(const Allocator&) noexcept;
161
 
162
  ``` cpp
163
  constexpr explicit vector(size_type n, const Allocator& = Allocator());
164
  ```
165
 
166
- *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
167
 
168
  *Effects:* Constructs a `vector` with `n` default-inserted elements
169
  using the specified allocator.
170
 
171
  *Complexity:* Linear in `n`.
@@ -173,11 +173,11 @@ using the specified allocator.
173
  ``` cpp
174
  constexpr vector(size_type n, const T& value,
175
  const Allocator& = Allocator());
176
  ```
177
 
178
- *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
179
 
180
  *Effects:* Constructs a `vector` with `n` copies of `value`, using the
181
  specified allocator.
182
 
183
  *Complexity:* Linear in `n`.
@@ -191,13 +191,13 @@ template<class InputIterator>
191
  *Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
192
  using the specified allocator.
193
 
194
  *Complexity:* Makes only N calls to the copy constructor of `T` (where N
195
  is the distance between `first` and `last`) and no reallocations if
196
- iterators `first` and `last` are of forward, bidirectional, or random
197
- access categories. It makes order N calls to the copy constructor of `T`
198
- and order log N reallocations if they are just input iterators.
199
 
200
  ``` cpp
201
  template<container-compatible-range<T> R>
202
  constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());
203
  ```
@@ -205,14 +205,21 @@ template<container-compatible-range<T> R>
205
  *Effects:* Constructs a `vector` object with the elements of the range
206
  `rg`, using the specified allocator.
207
 
208
  *Complexity:* Initializes exactly N elements from the results of
209
  dereferencing successive iterators of `rg`, where N is
210
- `ranges::distance(rg)`. Performs no reallocations if `R` models
211
- `ranges::forward_range` or `ranges::sized_range`; otherwise, performs
212
- order log N reallocations and order N calls to the copy or move
213
- constructor of `T`.
 
 
 
 
 
 
 
214
 
215
  #### Capacity <a id="vector.capacity">[[vector.capacity]]</a>
216
 
217
  ``` cpp
218
  constexpr size_type capacity() const noexcept;
@@ -225,11 +232,11 @@ requiring reallocation.
225
 
226
  ``` cpp
227
  constexpr void reserve(size_type n);
228
  ```
229
 
230
- *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
231
 
232
  *Effects:* A directive that informs a `vector` of a planned change in
233
  size, so that it can manage the storage allocation accordingly. After
234
  `reserve()`, `capacity()` is greater or equal to the argument of
235
  `reserve` if reallocation happens; and equal to the previous value of
@@ -238,16 +245,15 @@ if the current capacity is less than the argument of `reserve()`. If an
238
  exception is thrown other than by the move constructor of a
239
  non-*Cpp17CopyInsertable* type, there are no effects.
240
 
241
  *Throws:* `length_error` if `n > max_size()`.[^4]
242
 
243
- *Complexity:* It does not change the size of the sequence and takes at
244
- most linear time in the size of the sequence.
245
 
246
- *Remarks:* Reallocation invalidates all the references, pointers, and
247
- iterators referring to the elements in the sequence, as well as the
248
- past-the-end iterator.
249
 
250
  [*Note 1*: If no reallocation happens, they remain
251
  valid. — *end note*]
252
 
253
  No reallocation shall take place during insertions that happen after a
@@ -256,21 +262,21 @@ greater than the value of `capacity()`.
256
 
257
  ``` cpp
258
  constexpr void shrink_to_fit();
259
  ```
260
 
261
- *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
262
 
263
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
264
  `capacity()` to `size()`.
265
 
266
  [*Note 2*: The request is non-binding to allow latitude for
267
  implementation-specific optimizations. — *end note*]
268
 
269
  It does not increase `capacity()`, but may reduce `capacity()` by
270
  causing reallocation. If an exception is thrown other than by the move
271
- constructor of a non-*Cpp17CopyInsertable* `T` there are no effects.
272
 
273
  *Complexity:* If reallocation happens, linear in the size of the
274
  sequence.
275
 
276
  *Remarks:* Reallocation invalidates all the references, pointers, and
@@ -294,40 +300,40 @@ of `x`.
294
  ``` cpp
295
  constexpr void resize(size_type sz);
296
  ```
297
 
298
  *Preconditions:* `T` is *Cpp17MoveInsertable* and
299
- *Cpp17DefaultInsertable* into `*this`.
300
 
301
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
302
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
303
  to the sequence.
304
 
305
  *Remarks:* If an exception is thrown other than by the move constructor
306
- of a non-*Cpp17CopyInsertable* `T` there are no effects.
307
 
308
  ``` cpp
309
  constexpr void resize(size_type sz, const T& c);
310
  ```
311
 
312
- *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
313
 
314
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
315
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
316
  sequence.
317
 
318
- *Remarks:* If an exception is thrown there are no effects.
319
 
320
  #### Data <a id="vector.data">[[vector.data]]</a>
321
 
322
  ``` cpp
323
  constexpr T* data() noexcept;
324
  constexpr const T* data() const noexcept;
325
  ```
326
 
327
  *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
328
- range. For a non-empty vector, `data()` `==` `addressof(front())`.
329
 
330
  *Complexity:* Constant time.
331
 
332
  #### Modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
333
 
@@ -359,17 +365,29 @@ iterators referring to the elements in the sequence, as well as the
359
  past-the-end iterator. If no reallocation happens, then references,
360
  pointers, and iterators before the insertion point remain valid but
361
  those at or after the insertion point, including the past-the-end
362
  iterator, are invalidated. If an exception is thrown other than by the
363
  copy constructor, move constructor, assignment operator, or move
364
- assignment operator of `T` or by any `InputIterator` operation there are
365
- no effects. If an exception is thrown while inserting a single element
366
- at the end and `T` is *Cpp17CopyInsertable* or
367
  `is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
368
  Otherwise, if an exception is thrown by the move constructor of a
369
  non-*Cpp17CopyInsertable* `T`, the effects are unspecified.
370
 
 
 
 
 
 
 
 
 
 
 
 
 
371
  ``` cpp
372
  constexpr iterator erase(const_iterator position);
373
  constexpr iterator erase(const_iterator first, const_iterator last);
374
  constexpr void pop_back();
375
  ```
@@ -386,11 +404,11 @@ is called the number of times equal to the number of elements in the
386
  vector after the erased elements.
387
 
388
  #### Erasure <a id="vector.erasure">[[vector.erasure]]</a>
389
 
390
  ``` cpp
391
- template<class T, class Allocator, class U>
392
  constexpr typename vector<T, Allocator>::size_type
393
  erase(vector<T, Allocator>& c, const U& value);
394
  ```
395
 
396
  *Effects:* Equivalent to:
 
28
  class vector {
29
  public:
30
  // types
31
  using value_type = T;
32
  using allocator_type = Allocator;
33
+ using pointer = allocator_traits<Allocator>::pointer;
34
+ using const_pointer = allocator_traits<Allocator>::const_pointer;
35
  using reference = value_type&;
36
  using const_reference = const value_type&;
37
  using size_type = implementation-defined // type of vector::size_type; // see [container.requirements]
38
  using difference_type = implementation-defined // type of vector::difference_type; // see [container.requirements]
39
  using iterator = implementation-defined // type of vector::iterator; // see [container.requirements]
 
83
  constexpr const_iterator cend() const noexcept;
84
  constexpr const_reverse_iterator crbegin() const noexcept;
85
  constexpr const_reverse_iterator crend() const noexcept;
86
 
87
  // [vector.capacity], capacity
88
+ constexpr bool empty() const noexcept;
89
  constexpr size_type size() const noexcept;
90
  constexpr size_type max_size() const noexcept;
91
  constexpr size_type capacity() const noexcept;
92
  constexpr void resize(size_type sz);
93
  constexpr void resize(size_type sz, const T& c);
 
95
  constexpr void shrink_to_fit();
96
 
97
  // element access
98
  constexpr reference operator[](size_type n);
99
  constexpr const_reference operator[](size_type n) const;
 
100
  constexpr reference at(size_type n);
101
+ constexpr const_reference at(size_type n) const;
102
  constexpr reference front();
103
  constexpr const_reference front() const;
104
  constexpr reference back();
105
  constexpr const_reference back() const;
106
 
 
161
 
162
  ``` cpp
163
  constexpr explicit vector(size_type n, const Allocator& = Allocator());
164
  ```
165
 
166
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `vector`.
167
 
168
  *Effects:* Constructs a `vector` with `n` default-inserted elements
169
  using the specified allocator.
170
 
171
  *Complexity:* Linear in `n`.
 
173
  ``` cpp
174
  constexpr vector(size_type n, const T& value,
175
  const Allocator& = Allocator());
176
  ```
177
 
178
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `vector`.
179
 
180
  *Effects:* Constructs a `vector` with `n` copies of `value`, using the
181
  specified allocator.
182
 
183
  *Complexity:* Linear in `n`.
 
191
  *Effects:* Constructs a `vector` equal to the range \[`first`, `last`),
192
  using the specified allocator.
193
 
194
  *Complexity:* Makes only N calls to the copy constructor of `T` (where N
195
  is the distance between `first` and `last`) and no reallocations if
196
+ `InputIterator` meets the *Cpp17ForwardIterator* requirements. It makes
197
+ order N calls to the copy constructor of `T` and order log N
198
+ reallocations if they are just input iterators.
199
 
200
  ``` cpp
201
  template<container-compatible-range<T> R>
202
  constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());
203
  ```
 
205
  *Effects:* Constructs a `vector` object with the elements of the range
206
  `rg`, using the specified allocator.
207
 
208
  *Complexity:* Initializes exactly N elements from the results of
209
  dereferencing successive iterators of `rg`, where N is
210
+ `ranges::distance(rg)`.
211
+
212
+ Performs no reallocations if:
213
+
214
+ - `R` models `ranges::approximately_sized_range`, and
215
+ `ranges::distance(rg) <= ranges::reserve_hint(rg)` is `true`, or
216
+ - `R` models `ranges::forward_range` and `R` does not model
217
+ `ranges::approximately_sized_range`.
218
+
219
+ Otherwise, performs order log N reallocations and order N calls to the
220
+ copy or move constructor of `T`.
221
 
222
  #### Capacity <a id="vector.capacity">[[vector.capacity]]</a>
223
 
224
  ``` cpp
225
  constexpr size_type capacity() const noexcept;
 
232
 
233
  ``` cpp
234
  constexpr void reserve(size_type n);
235
  ```
236
 
237
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `vector`.
238
 
239
  *Effects:* A directive that informs a `vector` of a planned change in
240
  size, so that it can manage the storage allocation accordingly. After
241
  `reserve()`, `capacity()` is greater or equal to the argument of
242
  `reserve` if reallocation happens; and equal to the previous value of
 
245
  exception is thrown other than by the move constructor of a
246
  non-*Cpp17CopyInsertable* type, there are no effects.
247
 
248
  *Throws:* `length_error` if `n > max_size()`.[^4]
249
 
250
+ *Complexity:* Linear in the size of the sequence.
 
251
 
252
+ *Remarks:* The size of the sequence is not changed. Reallocation
253
+ invalidates all the references, pointers, and iterators referring to the
254
+ elements in the sequence, as well as the past-the-end iterator.
255
 
256
  [*Note 1*: If no reallocation happens, they remain
257
  valid. — *end note*]
258
 
259
  No reallocation shall take place during insertions that happen after a
 
262
 
263
  ``` cpp
264
  constexpr void shrink_to_fit();
265
  ```
266
 
267
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `vector`.
268
 
269
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
270
  `capacity()` to `size()`.
271
 
272
  [*Note 2*: The request is non-binding to allow latitude for
273
  implementation-specific optimizations. — *end note*]
274
 
275
  It does not increase `capacity()`, but may reduce `capacity()` by
276
  causing reallocation. If an exception is thrown other than by the move
277
+ constructor of a non-*Cpp17CopyInsertable* `T`, there are no effects.
278
 
279
  *Complexity:* If reallocation happens, linear in the size of the
280
  sequence.
281
 
282
  *Remarks:* Reallocation invalidates all the references, pointers, and
 
300
  ``` cpp
301
  constexpr void resize(size_type sz);
302
  ```
303
 
304
  *Preconditions:* `T` is *Cpp17MoveInsertable* and
305
+ *Cpp17DefaultInsertable* into `vector`.
306
 
307
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
308
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
309
  to the sequence.
310
 
311
  *Remarks:* If an exception is thrown other than by the move constructor
312
+ of a non-*Cpp17CopyInsertable* `T`, there are no effects.
313
 
314
  ``` cpp
315
  constexpr void resize(size_type sz, const T& c);
316
  ```
317
 
318
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `vector`.
319
 
320
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
321
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
322
  sequence.
323
 
324
+ *Remarks:* If an exception is thrown, there are no effects.
325
 
326
  #### Data <a id="vector.data">[[vector.data]]</a>
327
 
328
  ``` cpp
329
  constexpr T* data() noexcept;
330
  constexpr const T* data() const noexcept;
331
  ```
332
 
333
  *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
334
+ range. For a non-empty vector, `data() == addressof(front())` is `true`.
335
 
336
  *Complexity:* Constant time.
337
 
338
  #### Modifiers <a id="vector.modifiers">[[vector.modifiers]]</a>
339
 
 
365
  past-the-end iterator. If no reallocation happens, then references,
366
  pointers, and iterators before the insertion point remain valid but
367
  those at or after the insertion point, including the past-the-end
368
  iterator, are invalidated. If an exception is thrown other than by the
369
  copy constructor, move constructor, assignment operator, or move
370
+ assignment operator of `T` or by any `InputIterator` operation, there
371
+ are no effects. If an exception is thrown while inserting a single
372
+ element at the end and `T` is *Cpp17CopyInsertable* or
373
  `is_nothrow_move_constructible_v<T>` is `true`, there are no effects.
374
  Otherwise, if an exception is thrown by the move constructor of a
375
  non-*Cpp17CopyInsertable* `T`, the effects are unspecified.
376
 
377
+ For the declarations taking a range `R`, performs at most one
378
+ reallocation if:
379
+
380
+ - `R` models `ranges::approximately_sized_range` and
381
+ `ranges::distance(rg) <= ranges::reserve_hint(rg)` is `true`, or
382
+ - `R` models `ranges::forward_range` and `R` does not model
383
+ `ranges::approximately_sized_range`.
384
+
385
+ For the declarations taking a pair of `InputIterator`, performs at most
386
+ one reallocation if `InputIterator` meets the *Cpp17ForwardIterator*
387
+ requirements.
388
+
389
  ``` cpp
390
  constexpr iterator erase(const_iterator position);
391
  constexpr iterator erase(const_iterator first, const_iterator last);
392
  constexpr void pop_back();
393
  ```
 
404
  vector after the erased elements.
405
 
406
  #### Erasure <a id="vector.erasure">[[vector.erasure]]</a>
407
 
408
  ``` cpp
409
+ template<class T, class Allocator, class U = T>
410
  constexpr typename vector<T, Allocator>::size_type
411
  erase(vector<T, Allocator>& c, const U& value);
412
  ```
413
 
414
  *Effects:* Equivalent to: