tmp/tmpfimhed9o/{from.md → to.md}
RENAMED
|
@@ -1,94 +1,105 @@
|
|
| 1 |
-
####
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
-
size_type capacity() const noexcept;
|
| 5 |
```
|
| 6 |
|
| 7 |
*Returns:* The total number of elements that the vector can hold without
|
| 8 |
requiring reallocation.
|
| 9 |
|
|
|
|
|
|
|
| 10 |
``` cpp
|
| 11 |
-
void reserve(size_type n);
|
| 12 |
```
|
| 13 |
|
| 14 |
-
*
|
| 15 |
|
| 16 |
*Effects:* A directive that informs a `vector` of a planned change in
|
| 17 |
size, so that it can manage the storage allocation accordingly. After
|
| 18 |
`reserve()`, `capacity()` is greater or equal to the argument of
|
| 19 |
`reserve` if reallocation happens; and equal to the previous value of
|
| 20 |
`capacity()` otherwise. Reallocation happens at this point if and only
|
| 21 |
if the current capacity is less than the argument of `reserve()`. If an
|
| 22 |
exception is thrown other than by the move constructor of a
|
| 23 |
-
non-
|
| 24 |
|
| 25 |
*Complexity:* It does not change the size of the sequence and takes at
|
| 26 |
most linear time in the size of the sequence.
|
| 27 |
|
| 28 |
*Throws:* `length_error` if `n > max_size()`.[^4]
|
| 29 |
|
| 30 |
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 31 |
-
iterators referring to the elements in the sequence
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
``` cpp
|
| 37 |
-
void shrink_to_fit();
|
| 38 |
```
|
| 39 |
|
| 40 |
-
*
|
| 41 |
|
| 42 |
*Effects:* `shrink_to_fit` is a non-binding request to reduce
|
| 43 |
`capacity()` to `size()`.
|
| 44 |
|
| 45 |
-
[*Note
|
| 46 |
implementation-specific optimizations. — *end note*]
|
| 47 |
|
| 48 |
It does not increase `capacity()`, but may reduce `capacity()` by
|
| 49 |
causing reallocation. If an exception is thrown other than by the move
|
| 50 |
-
constructor of a non-
|
| 51 |
|
| 52 |
-
*Complexity:*
|
|
|
|
| 53 |
|
| 54 |
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 55 |
iterators referring to the elements in the sequence as well as the
|
| 56 |
-
past-the-end iterator.
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
``` cpp
|
| 59 |
-
void swap(vector& x)
|
| 60 |
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 61 |
allocator_traits<Allocator>::is_always_equal::value);
|
| 62 |
```
|
| 63 |
|
| 64 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 65 |
of `x`.
|
| 66 |
|
| 67 |
*Complexity:* Constant time.
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
-
void resize(size_type sz);
|
| 71 |
```
|
| 72 |
|
|
|
|
|
|
|
|
|
|
| 73 |
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 74 |
the sequence. Otherwise, appends `sz - size()` default-inserted elements
|
| 75 |
to the sequence.
|
| 76 |
|
| 77 |
-
*Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
|
| 78 |
-
`*this`.
|
| 79 |
-
|
| 80 |
*Remarks:* If an exception is thrown other than by the move constructor
|
| 81 |
-
of a non-
|
| 82 |
|
| 83 |
``` cpp
|
| 84 |
-
void resize(size_type sz, const T& c);
|
| 85 |
```
|
| 86 |
|
|
|
|
|
|
|
| 87 |
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 88 |
the sequence. Otherwise, appends `sz - size()` copies of `c` to the
|
| 89 |
sequence.
|
| 90 |
|
| 91 |
-
*Requires:* `T` shall be `CopyInsertable` into `*this`.
|
| 92 |
-
|
| 93 |
*Remarks:* If an exception is thrown there are no effects.
|
| 94 |
|
|
|
|
| 1 |
+
#### Capacity <a id="vector.capacity">[[vector.capacity]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
+
constexpr size_type capacity() const noexcept;
|
| 5 |
```
|
| 6 |
|
| 7 |
*Returns:* The total number of elements that the vector can hold without
|
| 8 |
requiring reallocation.
|
| 9 |
|
| 10 |
+
*Complexity:* Constant time.
|
| 11 |
+
|
| 12 |
``` cpp
|
| 13 |
+
constexpr void reserve(size_type n);
|
| 14 |
```
|
| 15 |
|
| 16 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
|
| 17 |
|
| 18 |
*Effects:* A directive that informs a `vector` of a planned change in
|
| 19 |
size, so that it can manage the storage allocation accordingly. After
|
| 20 |
`reserve()`, `capacity()` is greater or equal to the argument of
|
| 21 |
`reserve` if reallocation happens; and equal to the previous value of
|
| 22 |
`capacity()` otherwise. Reallocation happens at this point if and only
|
| 23 |
if the current capacity is less than the argument of `reserve()`. If an
|
| 24 |
exception is thrown other than by the move constructor of a
|
| 25 |
+
non-*Cpp17CopyInsertable* type, there are no effects.
|
| 26 |
|
| 27 |
*Complexity:* It does not change the size of the sequence and takes at
|
| 28 |
most linear time in the size of the sequence.
|
| 29 |
|
| 30 |
*Throws:* `length_error` if `n > max_size()`.[^4]
|
| 31 |
|
| 32 |
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 33 |
+
iterators referring to the elements in the sequence, as well as the
|
| 34 |
+
past-the-end iterator.
|
| 35 |
+
|
| 36 |
+
[*Note 1*: If no reallocation happens, they remain
|
| 37 |
+
valid. — *end note*]
|
| 38 |
+
|
| 39 |
+
No reallocation shall take place during insertions that happen after a
|
| 40 |
+
call to `reserve()` until an insertion would make the size of the vector
|
| 41 |
+
greater than the value of `capacity()`.
|
| 42 |
|
| 43 |
``` cpp
|
| 44 |
+
constexpr void shrink_to_fit();
|
| 45 |
```
|
| 46 |
|
| 47 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
|
| 48 |
|
| 49 |
*Effects:* `shrink_to_fit` is a non-binding request to reduce
|
| 50 |
`capacity()` to `size()`.
|
| 51 |
|
| 52 |
+
[*Note 2*: The request is non-binding to allow latitude for
|
| 53 |
implementation-specific optimizations. — *end note*]
|
| 54 |
|
| 55 |
It does not increase `capacity()`, but may reduce `capacity()` by
|
| 56 |
causing reallocation. If an exception is thrown other than by the move
|
| 57 |
+
constructor of a non-*Cpp17CopyInsertable* `T` there are no effects.
|
| 58 |
|
| 59 |
+
*Complexity:* If reallocation happens, linear in the size of the
|
| 60 |
+
sequence.
|
| 61 |
|
| 62 |
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 63 |
iterators referring to the elements in the sequence as well as the
|
| 64 |
+
past-the-end iterator.
|
| 65 |
+
|
| 66 |
+
[*Note 3*: If no reallocation happens, they remain
|
| 67 |
+
valid. — *end note*]
|
| 68 |
|
| 69 |
``` cpp
|
| 70 |
+
constexpr void swap(vector& x)
|
| 71 |
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
|
| 72 |
allocator_traits<Allocator>::is_always_equal::value);
|
| 73 |
```
|
| 74 |
|
| 75 |
*Effects:* Exchanges the contents and `capacity()` of `*this` with that
|
| 76 |
of `x`.
|
| 77 |
|
| 78 |
*Complexity:* Constant time.
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
+
constexpr void resize(size_type sz);
|
| 82 |
```
|
| 83 |
|
| 84 |
+
*Preconditions:* `T` is *Cpp17MoveInsertable* and
|
| 85 |
+
*Cpp17DefaultInsertable* into `*this`.
|
| 86 |
+
|
| 87 |
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 88 |
the sequence. Otherwise, appends `sz - size()` default-inserted elements
|
| 89 |
to the sequence.
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
*Remarks:* If an exception is thrown other than by the move constructor
|
| 92 |
+
of a non-*Cpp17CopyInsertable* `T` there are no effects.
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
+
constexpr void resize(size_type sz, const T& c);
|
| 96 |
```
|
| 97 |
|
| 98 |
+
*Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
|
| 99 |
+
|
| 100 |
*Effects:* If `sz < size()`, erases the last `size() - sz` elements from
|
| 101 |
the sequence. Otherwise, appends `sz - size()` copies of `c` to the
|
| 102 |
sequence.
|
| 103 |
|
|
|
|
|
|
|
| 104 |
*Remarks:* If an exception is thrown there are no effects.
|
| 105 |
|