tmp/tmp5fxtvho4/{from.md → to.md}
RENAMED
|
@@ -1,108 +1,93 @@
|
|
| 1 |
-
####
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
-
size_type size() const noexcept;
|
|
|
|
| 5 |
```
|
| 6 |
|
| 7 |
*Returns:* A count of the number of char-like objects currently in the
|
| 8 |
string.
|
| 9 |
|
| 10 |
*Complexity:* Constant time.
|
| 11 |
|
| 12 |
``` cpp
|
| 13 |
-
size_type
|
| 14 |
-
```
|
| 15 |
-
|
| 16 |
-
*Returns:* `size()`.
|
| 17 |
-
|
| 18 |
-
``` cpp
|
| 19 |
-
size_type max_size() const noexcept;
|
| 20 |
```
|
| 21 |
|
| 22 |
*Returns:* The largest possible number of char-like objects that can be
|
| 23 |
stored in a `basic_string`.
|
| 24 |
|
| 25 |
*Complexity:* Constant time.
|
| 26 |
|
| 27 |
``` cpp
|
| 28 |
-
void resize(size_type n, charT c);
|
| 29 |
```
|
| 30 |
|
| 31 |
-
*
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
- If `n <= size()`, the function replaces the string designated by
|
| 37 |
-
`*this` with a string of length `n` whose elements are a copy of the
|
| 38 |
-
initial elements of the original string designated by `*this`.
|
| 39 |
-
- If `n > size()`, the function replaces the string designated by
|
| 40 |
-
`*this` with a string of length `n` whose first `size()` elements are
|
| 41 |
-
a copy of the original string designated by `*this`, and whose
|
| 42 |
-
remaining elements are all initialized to `c`.
|
| 43 |
|
| 44 |
``` cpp
|
| 45 |
-
void resize(size_type n);
|
| 46 |
```
|
| 47 |
|
| 48 |
-
*Effects:*
|
| 49 |
|
| 50 |
``` cpp
|
| 51 |
-
size_type capacity() const noexcept;
|
| 52 |
```
|
| 53 |
|
| 54 |
*Returns:* The size of the allocated storage in the string.
|
| 55 |
|
|
|
|
|
|
|
| 56 |
``` cpp
|
| 57 |
-
void reserve(size_type res_arg
|
| 58 |
```
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
*
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
[*Note 1*: Calling `reserve()` with a `res_arg` argument less than
|
| 68 |
-
`capacity()` is in effect a non-binding shrink request. A call with
|
| 69 |
-
`res_arg <= size()` is in effect a non-binding shrink-to-fit
|
| 70 |
-
request. — *end note*]
|
| 71 |
-
|
| 72 |
-
*Throws:* `length_error` if `res_arg > max_size()`.[^4]
|
| 73 |
|
| 74 |
``` cpp
|
| 75 |
-
void shrink_to_fit();
|
| 76 |
```
|
| 77 |
|
| 78 |
*Effects:* `shrink_to_fit` is a non-binding request to reduce
|
| 79 |
`capacity()` to `size()`.
|
| 80 |
|
| 81 |
-
[*Note
|
| 82 |
implementation-specific optimizations. — *end note*]
|
| 83 |
|
| 84 |
It does not increase `capacity()`, but may reduce `capacity()` by
|
| 85 |
causing reallocation.
|
| 86 |
|
| 87 |
-
*Complexity:*
|
|
|
|
| 88 |
|
| 89 |
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 90 |
-
iterators referring to the elements in the sequence as well as the
|
| 91 |
-
past-the-end iterator.
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
```
|
| 96 |
-
|
| 97 |
-
*Effects:* Behaves as if the function calls:
|
| 98 |
|
| 99 |
``` cpp
|
| 100 |
-
|
| 101 |
```
|
| 102 |
|
|
|
|
|
|
|
| 103 |
``` cpp
|
| 104 |
-
bool empty() const noexcept;
|
| 105 |
```
|
| 106 |
|
| 107 |
-
*
|
| 108 |
|
|
|
|
| 1 |
+
#### Capacity <a id="string.capacity">[[string.capacity]]</a>
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
+
constexpr size_type size() const noexcept;
|
| 5 |
+
constexpr size_type length() const noexcept;
|
| 6 |
```
|
| 7 |
|
| 8 |
*Returns:* A count of the number of char-like objects currently in the
|
| 9 |
string.
|
| 10 |
|
| 11 |
*Complexity:* Constant time.
|
| 12 |
|
| 13 |
``` cpp
|
| 14 |
+
constexpr size_type max_size() const noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
```
|
| 16 |
|
| 17 |
*Returns:* The largest possible number of char-like objects that can be
|
| 18 |
stored in a `basic_string`.
|
| 19 |
|
| 20 |
*Complexity:* Constant time.
|
| 21 |
|
| 22 |
``` cpp
|
| 23 |
+
constexpr void resize(size_type n, charT c);
|
| 24 |
```
|
| 25 |
|
| 26 |
+
*Effects:* Alters the value of `*this` as follows:
|
| 27 |
|
| 28 |
+
- If `n <= size()`, erases the last `size() - n` elements.
|
| 29 |
+
- If `n > size()`, appends `n - size()` copies of `c`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
``` cpp
|
| 32 |
+
constexpr void resize(size_type n);
|
| 33 |
```
|
| 34 |
|
| 35 |
+
*Effects:* Equivalent to `resize(n, charT())`.
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
+
constexpr size_type capacity() const noexcept;
|
| 39 |
```
|
| 40 |
|
| 41 |
*Returns:* The size of the allocated storage in the string.
|
| 42 |
|
| 43 |
+
*Complexity:* Constant time.
|
| 44 |
+
|
| 45 |
``` cpp
|
| 46 |
+
constexpr void reserve(size_type res_arg);
|
| 47 |
```
|
| 48 |
|
| 49 |
+
*Effects:* A directive that informs a `basic_string` of a planned change
|
| 50 |
+
in size, so that the storage allocation can be managed accordingly.
|
| 51 |
+
After `reserve()`, `capacity()` is greater or equal to the argument of
|
| 52 |
+
`reserve` if reallocation happens; and equal to the previous value of
|
| 53 |
+
`capacity()` otherwise. Reallocation happens at this point if and only
|
| 54 |
+
if the current capacity is less than the argument of `reserve()`.
|
| 55 |
|
| 56 |
+
*Throws:* `length_error` if `res_arg > max_size()` or any exceptions
|
| 57 |
+
thrown by `allocator_traits` `<Allocator>::allocate`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
``` cpp
|
| 60 |
+
constexpr void shrink_to_fit();
|
| 61 |
```
|
| 62 |
|
| 63 |
*Effects:* `shrink_to_fit` is a non-binding request to reduce
|
| 64 |
`capacity()` to `size()`.
|
| 65 |
|
| 66 |
+
[*Note 1*: The request is non-binding to allow latitude for
|
| 67 |
implementation-specific optimizations. — *end note*]
|
| 68 |
|
| 69 |
It does not increase `capacity()`, but may reduce `capacity()` by
|
| 70 |
causing reallocation.
|
| 71 |
|
| 72 |
+
*Complexity:* If the size is not equal to the old capacity, linear in
|
| 73 |
+
the size of the sequence; otherwise constant.
|
| 74 |
|
| 75 |
*Remarks:* Reallocation invalidates all the references, pointers, and
|
| 76 |
+
iterators referring to the elements in the sequence, as well as the
|
| 77 |
+
past-the-end iterator.
|
| 78 |
|
| 79 |
+
[*Note 2*: If no reallocation happens, they remain
|
| 80 |
+
valid. — *end note*]
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
``` cpp
|
| 83 |
+
constexpr void clear() noexcept;
|
| 84 |
```
|
| 85 |
|
| 86 |
+
*Effects:* Equivalent to: `erase(begin(), end());`
|
| 87 |
+
|
| 88 |
``` cpp
|
| 89 |
+
[[nodiscard]] constexpr bool empty() const noexcept;
|
| 90 |
```
|
| 91 |
|
| 92 |
+
*Effects:* Equivalent to: `return size() == 0;`
|
| 93 |
|