From Jason Turner

[string.capacity]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp5fxtvho4/{from.md → to.md} +35 -50
tmp/tmp5fxtvho4/{from.md → to.md} RENAMED
@@ -1,108 +1,93 @@
1
- #### `basic_string` capacity <a id="string.capacity">[[string.capacity]]</a>
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 length() const noexcept;
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
- *Throws:* `length_error` if `n > max_size()`.
32
 
33
- *Effects:* Alters the length of the string designated by `*this` as
34
- follows:
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:* As if by `resize(n, charT())`.
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=0);
58
  ```
59
 
60
- The member function `reserve()` is a directive that informs a
61
- `basic_string` object of a planned change in size, so that it can manage
62
- the storage allocation accordingly.
 
 
 
63
 
64
- *Effects:* After `reserve()`, `capacity()` is greater or equal to the
65
- argument of `reserve`.
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 2*: The request is non-binding to allow latitude for
82
  implementation-specific optimizations. — *end note*]
83
 
84
  It does not increase `capacity()`, but may reduce `capacity()` by
85
  causing reallocation.
86
 
87
- *Complexity:* Linear in the size of the sequence.
 
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. If no reallocation happens, they remain valid.
92
 
93
- ``` cpp
94
- void clear() noexcept;
95
- ```
96
-
97
- *Effects:* Behaves as if the function calls:
98
 
99
  ``` cpp
100
- erase(begin(), end());
101
  ```
102
 
 
 
103
  ``` cpp
104
- bool empty() const noexcept;
105
  ```
106
 
107
- *Returns:* `size() == 0`.
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