From Jason Turner

[string.cons]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp5x731417/{from.md → to.md} +70 -28
tmp/tmp5x731417/{from.md → to.md} RENAMED
@@ -1,9 +1,9 @@
1
- ### `basic_string` constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
2
 
3
  ``` cpp
4
- explicit basic_string(const Allocator& a);
5
  ```
6
 
7
  *Effects:* Constructs an object of class `basic_string`. The
8
  postconditions of this function are indicated in
9
  Table  [[tab:strings.ctr.1]].
@@ -32,32 +32,65 @@ valid state with an unspecified value.
32
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
33
  | `size()` | `str.size()` |
34
  | `capacity()` | a value at least as large as `size()` |
35
 
36
  ``` cpp
37
- basic_string(const basic_string& str,
38
- size_type pos, size_type n = npos,
39
  const Allocator& a = Allocator());
40
  ```
41
 
42
- *Requires:* `pos <= str.size()`
 
 
 
 
 
 
 
 
 
43
 
44
  *Throws:* `out_of_range` if `pos > str.size()`.
45
 
46
  *Effects:* Constructs an object of class `basic_string` and determines
47
  the effective length `rlen` of the initial string value as the smaller
48
  of `n` and `str.size() - pos`, as indicated in
49
  Table  [[tab:strings.ctr.2]].
50
 
51
- **Table: `basic_string(const basic_string&, size_type, size_type, const Allocator&)` effects** <a id="tab:strings.ctr.2">[tab:strings.ctr.2]</a>
 
52
 
53
  | Element | Value |
54
  | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
55
  | `data()` | points at the first element of an allocated copy of `rlen` consecutive elements of the string controlled by `str` beginning at position `pos` |
56
  | `size()` | `rlen` |
57
  | `capacity()` | a value at least as large as `size()` |
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  ``` cpp
60
  basic_string(const charT* s, size_type n,
61
  const Allocator& a = Allocator());
62
  ```
63
 
@@ -94,18 +127,15 @@ indicated in Table  [[tab:strings.ctr.4]].
94
  | ------------ | ------------------------------------------------------------------------------------------------------ |
95
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `s` |
96
  | `size()` | `traits::length(s)` |
97
  | `capacity()` | a value at least as large as `size()` |
98
 
99
-
100
- *Remarks:* Uses `traits::length()`.
101
-
102
  ``` cpp
103
  basic_string(size_type n, charT c, const Allocator& a = Allocator());
104
  ```
105
 
106
- *Requires:* `n < npos`
107
 
108
  *Effects:* Constructs an object of class `basic_string` and determines
109
  its initial string value by repeating the char-like object `c` for all
110
  `n` elements, as indicated in Table  [[tab:strings.ctr.5]].
111
 
@@ -121,14 +151,14 @@ its initial string value by repeating the char-like object `c` for all
121
  template<class InputIterator>
122
  basic_string(InputIterator begin, InputIterator end,
123
  const Allocator& a = Allocator());
124
  ```
125
 
126
- *Effects:* If `InputIterator` is an integral type, equivalent to
127
 
128
  ``` cpp
129
- basic_string(static_cast<size_type>(begin), static_cast<value_type>(end), a)
130
  ```
131
 
132
  Otherwise constructs a string from the values in the range \[`begin`,
133
  `end`), as indicated in the Sequence Requirements table
134
  (see  [[sequence.reqmts]]).
@@ -147,11 +177,11 @@ basic_string(basic_string&& str, const Allocator& alloc);
147
  *Effects:* Constructs an object of class `basic_string` as indicated in
148
  Table  [[tab:strings.ctr.6]]. The stored allocator is constructed from
149
  `alloc`. In the second form, `str` is left in a valid state with an
150
  unspecified value.
151
 
152
- **Table: `basic_string(const basic_string&, const Allocator&)` and
153
  `basic_string(basic_string&&, const Allocator&)` effects** <a id="tab:strings.ctr.6">[tab:strings.ctr.6]</a>
154
 
155
  | Element | Value |
156
  | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
157
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by the original value of `str.data()`. |
@@ -161,48 +191,60 @@ unspecified value.
161
 
162
 
163
  *Throws:* The second form throws nothing if
164
  `alloc == str.get_allocator()`.
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  ``` cpp
167
  basic_string& operator=(const basic_string& str);
168
  ```
169
 
170
  *Effects:* If `*this` and `str` are not the same object, modifies
171
  `*this` as shown in Table  [[tab:strings.op=]].
172
 
173
  If `*this` and `str` are the same object, the member has no effect.
174
 
175
- *Returns:* `*this`
176
 
177
  **Table: `operator=(const basic_string&)` effects** <a id="tab:strings.op=">[tab:strings.op=]</a>
178
 
179
  | Element | Value |
180
  | ------------ | --------------------------------------------------------------------------------------------------------------- |
181
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
182
  | `size()` | `str.size()` |
183
  | `capacity()` | a value at least as large as `size()` |
184
 
185
  ``` cpp
186
- basic_string& operator=(basic_string&& str) noexcept;
 
 
187
  ```
188
 
189
- *Effects:* If `*this` and `str` are not the same object, modifies
190
- `*this` as shown in Table  [[tab:strings.op=rv]]. A valid implementation
191
- is `swap(str)`.
192
 
193
- If `*this` and `str` are the same object, the member has no effect.
194
 
195
- *Returns:* `*this`
196
-
197
- **Table: `operator=(basic_string&&)` effects** <a id="tab:strings.op=rv">[tab:strings.op=rv]</a>
198
 
199
- | Element | Value |
200
- | ------------ | ---------------------------------------------------------------------- |
201
- | `data()` | points at the array whose first element was pointed at by `str.data()` |
202
- | `size()` | previous value of `str.size()` |
203
- | `capacity()` | a value at least as large as `size()` |
204
 
205
  ``` cpp
206
  basic_string& operator=(const charT* s);
207
  ```
208
 
@@ -218,9 +260,9 @@ basic_string& operator=(charT c);
218
 
219
  ``` cpp
220
  basic_string& operator=(initializer_list<charT> il);
221
  ```
222
 
223
- *Effects:* `*this = basic_string(il)`.
224
 
225
  *Returns:* `*this`.
226
 
 
1
+ #### `basic_string` constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
2
 
3
  ``` cpp
4
+ explicit basic_string(const Allocator& a) noexcept;
5
  ```
6
 
7
  *Effects:* Constructs an object of class `basic_string`. The
8
  postconditions of this function are indicated in
9
  Table  [[tab:strings.ctr.1]].
 
32
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
33
  | `size()` | `str.size()` |
34
  | `capacity()` | a value at least as large as `size()` |
35
 
36
  ``` cpp
37
+ basic_string(const basic_string& str, size_type pos,
 
38
  const Allocator& a = Allocator());
39
  ```
40
 
41
+ *Throws:* `out_of_range` if `pos > str.size()`.
42
+
43
+ *Effects:* Constructs an object of class `basic_string` and determines
44
+ the effective length `rlen` of the initial string value as
45
+ `str.size() - pos`, as indicated in Table  [[tab:strings.ctr.2]].
46
+
47
+ ``` cpp
48
+ basic_string(const basic_string& str, size_type pos, size_type n,
49
+ const Allocator& a = Allocator());
50
+ ```
51
 
52
  *Throws:* `out_of_range` if `pos > str.size()`.
53
 
54
  *Effects:* Constructs an object of class `basic_string` and determines
55
  the effective length `rlen` of the initial string value as the smaller
56
  of `n` and `str.size() - pos`, as indicated in
57
  Table  [[tab:strings.ctr.2]].
58
 
59
+ **Table: `basic_string(const basic_string&, size_type, const Allocator&)`\protect\mbox{ }and\protect
60
+ `basic_string(const basic_string&, size_type, size_type, const Allocator&)` effects** <a id="tab:strings.ctr.2">[tab:strings.ctr.2]</a>
61
 
62
  | Element | Value |
63
  | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
64
  | `data()` | points at the first element of an allocated copy of `rlen` consecutive elements of the string controlled by `str` beginning at position `pos` |
65
  | `size()` | `rlen` |
66
  | `capacity()` | a value at least as large as `size()` |
67
 
68
+ ``` cpp
69
+ template<class T>
70
+ basic_string(const T& t, size_type pos, size_type n,
71
+ const Allocator& a = Allocator());
72
+ ```
73
+
74
+ *Effects:* Creates a variable, `sv`, as if by
75
+ `basic_string_view<charT, traits> sv = t;` and then behaves the same as:
76
+
77
+ ``` cpp
78
+ basic_string(sv.substr(pos, n), a);
79
+ ```
80
+
81
+ *Remarks:* This constructor shall not participate in overload resolution
82
+ unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
83
+ `true`.
84
+
85
+ ``` cpp
86
+ explicit basic_string(basic_string_view<charT, traits> sv,
87
+ const Allocator& a = Allocator());
88
+ ```
89
+
90
+ *Effects:* Same as `basic_string(sv.data(), sv.size(), a)`.
91
+
92
  ``` cpp
93
  basic_string(const charT* s, size_type n,
94
  const Allocator& a = Allocator());
95
  ```
96
 
 
127
  | ------------ | ------------------------------------------------------------------------------------------------------ |
128
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `s` |
129
  | `size()` | `traits::length(s)` |
130
  | `capacity()` | a value at least as large as `size()` |
131
 
 
 
 
132
  ``` cpp
133
  basic_string(size_type n, charT c, const Allocator& a = Allocator());
134
  ```
135
 
136
+ *Requires:* `n < npos`.
137
 
138
  *Effects:* Constructs an object of class `basic_string` and determines
139
  its initial string value by repeating the char-like object `c` for all
140
  `n` elements, as indicated in Table  [[tab:strings.ctr.5]].
141
 
 
151
  template<class InputIterator>
152
  basic_string(InputIterator begin, InputIterator end,
153
  const Allocator& a = Allocator());
154
  ```
155
 
156
+ *Effects:* If `InputIterator` is an integral type, equivalent to:
157
 
158
  ``` cpp
159
+ basic_string(static_cast<size_type>(begin), static_cast<value_type>(end), a);
160
  ```
161
 
162
  Otherwise constructs a string from the values in the range \[`begin`,
163
  `end`), as indicated in the Sequence Requirements table
164
  (see  [[sequence.reqmts]]).
 
177
  *Effects:* Constructs an object of class `basic_string` as indicated in
178
  Table  [[tab:strings.ctr.6]]. The stored allocator is constructed from
179
  `alloc`. In the second form, `str` is left in a valid state with an
180
  unspecified value.
181
 
182
+ **Table: `basic_string(const basic_string&, const Allocator&)`\protect and
183
  `basic_string(basic_string&&, const Allocator&)` effects** <a id="tab:strings.ctr.6">[tab:strings.ctr.6]</a>
184
 
185
  | Element | Value |
186
  | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
187
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by the original value of `str.data()`. |
 
191
 
192
 
193
  *Throws:* The second form throws nothing if
194
  `alloc == str.get_allocator()`.
195
 
196
+ ``` cpp
197
+ template<class InputIterator,
198
+ class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
199
+ basic_string(InputIterator, InputIterator, Allocator = Allocator())
200
+ -> basic_string<typename iterator_traits<InputIterator>::value_type,
201
+ char_traits<typename iterator_traits<InputIterator>::value_type>,
202
+ Allocator>;
203
+ ```
204
+
205
+ *Remarks:* Shall not participate in overload resolution if
206
+ `InputIterator` is a type that does not qualify as an input iterator, or
207
+ if `Allocator` is a type that does not qualify as an
208
+ allocator ([[container.requirements.general]]).
209
+
210
  ``` cpp
211
  basic_string& operator=(const basic_string& str);
212
  ```
213
 
214
  *Effects:* If `*this` and `str` are not the same object, modifies
215
  `*this` as shown in Table  [[tab:strings.op=]].
216
 
217
  If `*this` and `str` are the same object, the member has no effect.
218
 
219
+ *Returns:* `*this`.
220
 
221
  **Table: `operator=(const basic_string&)` effects** <a id="tab:strings.op=">[tab:strings.op=]</a>
222
 
223
  | Element | Value |
224
  | ------------ | --------------------------------------------------------------------------------------------------------------- |
225
  | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
226
  | `size()` | `str.size()` |
227
  | `capacity()` | a value at least as large as `size()` |
228
 
229
  ``` cpp
230
+ basic_string& operator=(basic_string&& str)
231
+ noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
232
+ allocator_traits<Allocator>::is_always_equal::value);
233
  ```
234
 
235
+ *Effects:* Move assigns as a sequence
236
+ container ([[container.requirements]]), except that iterators, pointers
237
+ and references may be invalidated.
238
 
239
+ *Returns:* `*this`.
240
 
241
+ ``` cpp
242
+ basic_string& operator=(basic_string_view<charT, traits> sv);
243
+ ```
244
 
245
+ *Effects:* Equivalent to: `return assign(sv);`
 
 
 
 
246
 
247
  ``` cpp
248
  basic_string& operator=(const charT* s);
249
  ```
250
 
 
260
 
261
  ``` cpp
262
  basic_string& operator=(initializer_list<charT> il);
263
  ```
264
 
265
+ *Effects:* As if by: `*this = basic_string(il);`
266
 
267
  *Returns:* `*this`.
268