From Jason Turner

[basic.string]

Large diff (101.0 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpwiz1y7ow/{from.md → to.md} +814 -1051
tmp/tmpwiz1y7ow/{from.md → to.md} RENAMED
@@ -6,34 +6,24 @@ with the first element of the sequence at position zero. Such a sequence
6
  is also called a “string” if the type of the char-like objects that it
7
  holds is clear from context. In the rest of this Clause, the type of the
8
  char-like objects held in a `basic_string` object is designated by
9
  `charT`.
10
 
11
- The member functions of `basic_string` use an object of the `Allocator`
12
- class passed as a template parameter to allocate and free storage for
13
- the contained char-like objects.[^2]
14
 
15
- A `basic_string` is a contiguous container (
16
- [[container.requirements.general]]).
17
-
18
- In all cases, `size() <= capacity()`.
19
-
20
- The functions described in this Clause can report two kinds of errors,
21
- each associated with an exception type:
22
-
23
- - a *length* error is associated with exceptions of type
24
- `length_error` ([[length.error]]);
25
- - an *out-of-range* error is associated with exceptions of type
26
- `out_of_range` ([[out.of.range]]).
27
 
28
  ``` cpp
29
  namespace std {
30
  template<class charT, class traits = char_traits<charT>,
31
  class Allocator = allocator<charT>>
32
  class basic_string {
33
  public:
34
- // types:
35
  using traits_type = traits;
36
  using value_type = charT;
37
  using allocator_type = Allocator;
38
  using size_type = typename allocator_traits<Allocator>::size_type;
39
  using difference_type = typename allocator_traits<Allocator>::difference_type;
@@ -47,479 +37,434 @@ namespace std {
47
  using reverse_iterator = std::reverse_iterator<iterator>;
48
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
49
  static const size_type npos = -1;
50
 
51
  // [string.cons], construct/copy/destroy
52
- basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }
53
- explicit basic_string(const Allocator& a) noexcept;
54
- basic_string(const basic_string& str);
55
- basic_string(basic_string&& str) noexcept;
56
- basic_string(const basic_string& str, size_type pos,
57
  const Allocator& a = Allocator());
58
- basic_string(const basic_string& str, size_type pos, size_type n,
59
  const Allocator& a = Allocator());
60
  template<class T>
61
- basic_string(const T& t, size_type pos, size_type n,
62
  const Allocator& a = Allocator());
63
- explicit basic_string(basic_string_view<charT, traits> sv,
64
- const Allocator& a = Allocator());
65
- basic_string(const charT* s,
66
- size_type n, const Allocator& a = Allocator());
67
- basic_string(const charT* s, const Allocator& a = Allocator());
68
- basic_string(size_type n, charT c, const Allocator& a = Allocator());
69
  template<class InputIterator>
70
- basic_string(InputIterator begin, InputIterator end,
71
  const Allocator& a = Allocator());
72
- basic_string(initializer_list<charT>, const Allocator& = Allocator());
73
- basic_string(const basic_string&, const Allocator&);
74
- basic_string(basic_string&&, const Allocator&);
 
75
 
76
- ~basic_string();
77
- basic_string& operator=(const basic_string& str);
78
- basic_string& operator=(basic_string&& str)
79
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
80
  allocator_traits<Allocator>::is_always_equal::value);
81
- basic_string& operator=(basic_string_view<charT, traits> sv);
82
- basic_string& operator=(const charT* s);
83
- basic_string& operator=(charT c);
84
- basic_string& operator=(initializer_list<charT>);
 
85
 
86
  // [string.iterators], iterators
87
- iterator begin() noexcept;
88
- const_iterator begin() const noexcept;
89
- iterator end() noexcept;
90
- const_iterator end() const noexcept;
91
 
92
- reverse_iterator rbegin() noexcept;
93
- const_reverse_iterator rbegin() const noexcept;
94
- reverse_iterator rend() noexcept;
95
- const_reverse_iterator rend() const noexcept;
96
 
97
- const_iterator cbegin() const noexcept;
98
- const_iterator cend() const noexcept;
99
- const_reverse_iterator crbegin() const noexcept;
100
- const_reverse_iterator crend() const noexcept;
101
 
102
  // [string.capacity], capacity
103
- size_type size() const noexcept;
104
- size_type length() const noexcept;
105
- size_type max_size() const noexcept;
106
- void resize(size_type n, charT c);
107
- void resize(size_type n);
108
- size_type capacity() const noexcept;
109
- void reserve(size_type res_arg = 0);
110
- void shrink_to_fit();
111
- void clear() noexcept;
112
- bool empty() const noexcept;
113
 
114
  // [string.access], element access
115
- const_reference operator[](size_type pos) const;
116
- reference operator[](size_type pos);
117
- const_reference at(size_type n) const;
118
- reference at(size_type n);
119
 
120
- const charT& front() const;
121
- charT& front();
122
- const charT& back() const;
123
- charT& back();
124
 
125
  // [string.modifiers], modifiers
126
- basic_string& operator+=(const basic_string& str);
127
- basic_string& operator+=(basic_string_view<charT, traits> sv);
128
- basic_string& operator+=(const charT* s);
129
- basic_string& operator+=(charT c);
130
- basic_string& operator+=(initializer_list<charT>);
131
- basic_string& append(const basic_string& str);
132
- basic_string& append(const basic_string& str, size_type pos,
133
- size_type n = npos);
134
- basic_string& append(basic_string_view<charT, traits> sv);
135
  template<class T>
136
- basic_string& append(const T& t, size_type pos, size_type n = npos);
137
- basic_string& append(const charT* s, size_type n);
138
- basic_string& append(const charT* s);
139
- basic_string& append(size_type n, charT c);
 
 
 
 
 
 
 
 
 
140
  template<class InputIterator>
141
- basic_string& append(InputIterator first, InputIterator last);
142
- basic_string& append(initializer_list<charT>);
143
- void push_back(charT c);
144
 
145
- basic_string& assign(const basic_string& str);
146
- basic_string& assign(basic_string&& str)
 
 
147
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
148
  allocator_traits<Allocator>::is_always_equal::value);
149
- basic_string& assign(const basic_string& str, size_type pos,
150
- size_type n = npos);
151
- basic_string& assign(basic_string_view<charT, traits> sv);
152
  template<class T>
153
- basic_string& assign(const T& t, size_type pos, size_type n = npos);
154
- basic_string& assign(const charT* s, size_type n);
155
- basic_string& assign(const charT* s);
156
- basic_string& assign(size_type n, charT c);
 
 
157
  template<class InputIterator>
158
- basic_string& assign(InputIterator first, InputIterator last);
159
- basic_string& assign(initializer_list<charT>);
160
 
161
- basic_string& insert(size_type pos, const basic_string& str);
162
- basic_string& insert(size_type pos1, const basic_string& str,
163
  size_type pos2, size_type n = npos);
164
- basic_string& insert(size_type pos, basic_string_view<charT, traits> sv);
165
  template<class T>
166
- basic_string& insert(size_type pos1, const T& t,
 
 
167
  size_type pos2, size_type n = npos);
168
- basic_string& insert(size_type pos, const charT* s, size_type n);
169
- basic_string& insert(size_type pos, const charT* s);
170
- basic_string& insert(size_type pos, size_type n, charT c);
171
- iterator insert(const_iterator p, charT c);
172
- iterator insert(const_iterator p, size_type n, charT c);
173
  template<class InputIterator>
174
- iterator insert(const_iterator p, InputIterator first, InputIterator last);
175
- iterator insert(const_iterator p, initializer_list<charT>);
176
 
177
- basic_string& erase(size_type pos = 0, size_type n = npos);
178
- iterator erase(const_iterator p);
179
- iterator erase(const_iterator first, const_iterator last);
180
 
181
- void pop_back();
182
 
183
- basic_string& replace(size_type pos1, size_type n1,
184
- const basic_string& str);
185
- basic_string& replace(size_type pos1, size_type n1,
186
- const basic_string& str,
187
  size_type pos2, size_type n2 = npos);
188
- basic_string& replace(size_type pos1, size_type n1,
189
- basic_string_view<charT, traits> sv);
190
  template<class T>
191
- basic_string& replace(size_type pos1, size_type n1, const T& t,
 
 
192
  size_type pos2, size_type n2 = npos);
193
- basic_string& replace(size_type pos, size_type n1, const charT* s,
194
- size_type n2);
195
- basic_string& replace(size_type pos, size_type n1, const charT* s);
196
- basic_string& replace(size_type pos, size_type n1, size_type n2,
197
- charT c);
198
-
199
- basic_string& replace(const_iterator i1, const_iterator i2,
200
  const basic_string& str);
201
- basic_string& replace(const_iterator i1, const_iterator i2,
202
- basic_string_view<charT, traits> sv);
203
- basic_string& replace(const_iterator i1, const_iterator i2, const charT* s,
204
  size_type n);
205
- basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
206
- basic_string& replace(const_iterator i1, const_iterator i2,
207
- size_type n, charT c);
208
  template<class InputIterator>
209
- basic_string& replace(const_iterator i1, const_iterator i2,
210
  InputIterator j1, InputIterator j2);
211
- basic_string& replace(const_iterator, const_iterator, initializer_list<charT>);
212
 
213
- size_type copy(charT* s, size_type n, size_type pos = 0) const;
214
- void swap(basic_string& str)
 
215
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
216
  allocator_traits<Allocator>::is_always_equal::value);
217
 
218
  // [string.ops], string operations
219
- const charT* c_str() const noexcept;
220
- const charT* data() const noexcept;
221
- charT* data() noexcept;
222
- operator basic_string_view<charT, traits>() const noexcept;
223
- allocator_type get_allocator() const noexcept;
224
 
225
- size_type find (basic_string_view<charT, traits> sv,
226
- size_type pos = 0) const noexcept;
227
- size_type find (const basic_string& str, size_type pos = 0) const noexcept;
228
- size_type find (const charT* s, size_type pos, size_type n) const;
229
- size_type find (const charT* s, size_type pos = 0) const;
230
- size_type find (charT c, size_type pos = 0) const;
231
- size_type rfind(basic_string_view<charT, traits> sv,
232
- size_type pos = npos) const noexcept;
233
- size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
234
- size_type rfind(const charT* s, size_type pos, size_type n) const;
235
- size_type rfind(const charT* s, size_type pos = npos) const;
236
- size_type rfind(charT c, size_type pos = npos) const;
237
 
238
- size_type find_first_of(basic_string_view<charT, traits> sv,
239
- size_type pos = 0) const noexcept;
240
- size_type find_first_of(const basic_string& str,
241
- size_type pos = 0) const noexcept;
242
- size_type find_first_of(const charT* s,
243
- size_type pos, size_type n) const;
244
- size_type find_first_of(const charT* s, size_type pos = 0) const;
245
- size_type find_first_of(charT c, size_type pos = 0) const;
246
- size_type find_last_of (basic_string_view<charT, traits> sv,
247
- size_type pos = npos) const noexcept;
248
- size_type find_last_of (const basic_string& str,
249
  size_type pos = npos) const noexcept;
250
- size_type find_last_of (const charT* s,
251
- size_type pos, size_type n) const;
252
- size_type find_last_of (const charT* s, size_type pos = npos) const;
253
- size_type find_last_of (charT c, size_type pos = npos) const;
254
 
255
- size_type find_first_not_of(basic_string_view<charT, traits> sv,
256
- size_type pos = 0) const noexcept;
257
- size_type find_first_not_of(const basic_string& str,
 
258
  size_type pos = 0) const noexcept;
259
- size_type find_first_not_of(const charT* s, size_type pos,
260
- size_type n) const;
261
- size_type find_first_not_of(const charT* s, size_type pos = 0) const;
262
- size_type find_first_not_of(charT c, size_type pos = 0) const;
263
- size_type find_last_not_of (basic_string_view<charT, traits> sv,
264
- size_type pos = npos) const noexcept;
265
- size_type find_last_not_of (const basic_string& str,
266
  size_type pos = npos) const noexcept;
267
- size_type find_last_not_of (const charT* s, size_type pos,
268
- size_type n) const;
269
- size_type find_last_not_of (const charT* s,
270
- size_type pos = npos) const;
271
- size_type find_last_not_of (charT c, size_type pos = npos) const;
272
 
273
- basic_string substr(size_type pos = 0, size_type n = npos) const;
274
- int compare(basic_string_view<charT, traits> sv) const noexcept;
275
- int compare(size_type pos1, size_type n1,
276
- basic_string_view<charT, traits> sv) const;
277
  template<class T>
278
- int compare(size_type pos1, size_type n1, const T& t,
 
 
279
  size_type pos2, size_type n2 = npos) const;
280
- int compare(const basic_string& str) const noexcept;
281
- int compare(size_type pos1, size_type n1,
282
- const basic_string& str) const;
283
- int compare(size_type pos1, size_type n1,
284
- const basic_string& str,
285
  size_type pos2, size_type n2 = npos) const;
286
- int compare(const charT* s) const;
287
- int compare(size_type pos1, size_type n1,
288
- const charT* s) const;
289
- int compare(size_type pos1, size_type n1,
290
- const charT* s, size_type n2) const;
 
 
 
 
 
291
  };
292
 
293
  template<class InputIterator,
294
  class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
295
  basic_string(InputIterator, InputIterator, Allocator = Allocator())
296
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
297
  char_traits<typename iterator_traits<InputIterator>::value_type>,
298
  Allocator>;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }
300
  ```
301
 
302
- #### `basic_string` general requirements <a id="string.require">[[string.require]]</a>
 
 
 
 
303
 
304
  If any operation would cause `size()` to exceed `max_size()`, that
305
- operation shall throw an exception object of type `length_error`.
306
 
307
  If any member function or operator of `basic_string` throws an
308
- exception, that function or operator shall have no other effect.
 
309
 
310
  In every specialization `basic_string<charT, traits, Allocator>`, the
311
  type `allocator_traits<Allocator>::value_type` shall name the same type
312
  as `charT`. Every object of type
313
- `basic_string<charT, traits, Allocator>` shall use an object of type
314
  `Allocator` to allocate and free storage for the contained `charT`
315
- objects as needed. The `Allocator` object used shall be obtained as
316
- described in [[container.requirements.general]]. In every specialization
317
- `basic_string<charT, traits, Allocator>`, the type `traits` shall
318
- satisfy the character traits requirements ([[char.traits]]), and the
319
- type `traits::char_type` shall name the same type as `charT`.
 
 
320
 
321
  References, pointers, and iterators referring to the elements of a
322
  `basic_string` sequence may be invalidated by the following uses of that
323
  `basic_string` object:
324
 
325
- - as an argument to any standard library function taking a reference to
326
- non-const `basic_string` as an argument.[^3]
327
  - Calling non-const member functions, except `operator[]`, `at`, `data`,
328
  `front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
329
 
330
- #### `basic_string` constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
331
 
332
  ``` cpp
333
- explicit basic_string(const Allocator& a) noexcept;
334
  ```
335
 
336
- *Effects:* Constructs an object of class `basic_string`. The
337
- postconditions of this function are indicated in
338
- Table  [[tab:strings.ctr.1]].
339
-
340
- **Table: `basic_string(const Allocator&)` effects** <a id="tab:strings.ctr.1">[tab:strings.ctr.1]</a>
341
-
342
- | Element | Value |
343
- | ------------ | -------------------------------------------------------------- |
344
- | `data()` | a non-null pointer that is copyable and can have 0 added to it |
345
- | `size()` | 0 |
346
- | `capacity()` | an unspecified value |
347
 
348
  ``` cpp
349
- basic_string(const basic_string& str);
350
- basic_string(basic_string&& str) noexcept;
351
  ```
352
 
353
- *Effects:* Constructs an object of class `basic_string` as indicated in
354
- Table  [[tab:strings.ctr.cpy]]. In the second form, `str` is left in a
355
- valid state with an unspecified value.
356
-
357
- **Table: `basic_string(const basic_string&)` effects** <a id="tab:strings.ctr.cpy">[tab:strings.ctr.cpy]</a>
358
 
359
- | Element | Value |
360
- | ------------ | --------------------------------------------------------------------------------------------------------------- |
361
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
362
- | `size()` | `str.size()` |
363
- | `capacity()` | a value at least as large as `size()` |
364
 
365
  ``` cpp
366
- basic_string(const basic_string& str, size_type pos,
 
 
367
  const Allocator& a = Allocator());
368
  ```
369
 
370
- *Throws:* `out_of_range` if `pos > str.size()`.
371
-
372
- *Effects:* Constructs an object of class `basic_string` and determines
373
- the effective length `rlen` of the initial string value as
374
- `str.size() - pos`, as indicated in Table  [[tab:strings.ctr.2]].
375
 
376
  ``` cpp
377
- basic_string(const basic_string& str, size_type pos, size_type n,
378
- const Allocator& a = Allocator());
379
  ```
380
 
381
- *Throws:* `out_of_range` if `pos > str.size()`.
382
-
383
- *Effects:* Constructs an object of class `basic_string` and determines
384
- the effective length `rlen` of the initial string value as the smaller
385
- of `n` and `str.size() - pos`, as indicated in
386
- Table  [[tab:strings.ctr.2]].
387
-
388
- **Table: `basic_string(const basic_string&, size_type, const Allocator&)`\protect\mbox{ }and\protect
389
- `basic_string(const basic_string&, size_type, size_type, const Allocator&)` effects** <a id="tab:strings.ctr.2">[tab:strings.ctr.2]</a>
390
-
391
- | Element | Value |
392
- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
393
- | `data()` | points at the first element of an allocated copy of `rlen` consecutive elements of the string controlled by `str` beginning at position `pos` |
394
- | `size()` | `rlen` |
395
- | `capacity()` | a value at least as large as `size()` |
396
-
397
  ``` cpp
398
  template<class T>
399
- basic_string(const T& t, size_type pos, size_type n,
400
- const Allocator& a = Allocator());
401
  ```
402
 
 
 
 
 
403
  *Effects:* Creates a variable, `sv`, as if by
404
  `basic_string_view<charT, traits> sv = t;` and then behaves the same as:
405
 
406
  ``` cpp
407
  basic_string(sv.substr(pos, n), a);
408
  ```
409
 
410
- *Remarks:* This constructor shall not participate in overload resolution
411
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
412
- `true`.
413
-
414
  ``` cpp
415
- explicit basic_string(basic_string_view<charT, traits> sv,
416
- const Allocator& a = Allocator());
417
  ```
418
 
419
- *Effects:* Same as `basic_string(sv.data(), sv.size(), a)`.
 
 
 
 
 
 
 
 
420
 
421
  ``` cpp
422
- basic_string(const charT* s, size_type n,
423
- const Allocator& a = Allocator());
424
  ```
425
 
426
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
427
 
428
- *Effects:* Constructs an object of class `basic_string` and determines
429
- its initial string value from the array of `charT` of length `n` whose
430
- first element is designated by `s`, as indicated in
431
- Table  [[tab:strings.ctr.3]].
432
 
433
- **Table: `basic_string(const charT*, size_type, const Allocator&)` effects** <a id="tab:strings.ctr.3">[tab:strings.ctr.3]</a>
434
-
435
- | Element | Value |
436
- | ------------ | ------------------------------------------------------------------------------------------------------ |
437
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `s` |
438
- | `size()` | `n` |
439
- | `capacity()` | a value at least as large as `size()` |
440
 
441
  ``` cpp
442
- basic_string(const charT* s, const Allocator& a = Allocator());
443
  ```
444
 
445
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
446
- elements of `charT`.
447
-
448
- *Effects:* Constructs an object of class `basic_string` and determines
449
- its initial string value from the array of `charT` of length
450
- `traits::length(s)` whose first element is designated by `s`, as
451
- indicated in Table  [[tab:strings.ctr.4]].
452
 
453
- **Table: `basic_string(const charT*, const Allocator&)` effects** <a id="tab:strings.ctr.4">[tab:strings.ctr.4]</a>
 
454
 
455
- | Element | Value |
456
- | ------------ | ------------------------------------------------------------------------------------------------------ |
457
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `s` |
458
- | `size()` | `traits::length(s)` |
459
- | `capacity()` | a value at least as large as `size()` |
460
 
461
  ``` cpp
462
- basic_string(size_type n, charT c, const Allocator& a = Allocator());
463
  ```
464
 
465
- *Requires:* `n < npos`.
466
-
467
- *Effects:* Constructs an object of class `basic_string` and determines
468
- its initial string value by repeating the char-like object `c` for all
469
- `n` elements, as indicated in Table  [[tab:strings.ctr.5]].
470
 
471
- **Table: `basic_string(size_t, charT, const Allocator&)` effects** <a id="tab:strings.ctr.5">[tab:strings.ctr.5]</a>
 
472
 
473
- | Element | Value |
474
- | ------------ | ----------------------------------------------------------------------------------------------------- |
475
- | `data()` | points at the first element of an allocated array of `n` elements, each storing the initial value `c` |
476
- | `size()` | `n` |
477
- | `capacity()` | a value at least as large as `size()` |
478
 
479
  ``` cpp
480
  template<class InputIterator>
481
- basic_string(InputIterator begin, InputIterator end,
482
- const Allocator& a = Allocator());
483
  ```
484
 
485
- *Effects:* If `InputIterator` is an integral type, equivalent to:
 
486
 
487
- ``` cpp
488
- basic_string(static_cast<size_type>(begin), static_cast<value_type>(end), a);
489
- ```
490
-
491
- Otherwise constructs a string from the values in the range \[`begin`,
492
- `end`), as indicated in the Sequence Requirements table
493
- (see  [[sequence.reqmts]]).
494
 
495
  ``` cpp
496
- basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
497
  ```
498
 
499
- *Effects:* Same as `basic_string(il.begin(), il.end(), a)`.
500
 
501
  ``` cpp
502
- basic_string(const basic_string& str, const Allocator& alloc);
503
- basic_string(basic_string&& str, const Allocator& alloc);
504
  ```
505
 
506
- *Effects:* Constructs an object of class `basic_string` as indicated in
507
- Table  [[tab:strings.ctr.6]]. The stored allocator is constructed from
508
- `alloc`. In the second form, `str` is left in a valid state with an
509
- unspecified value.
510
-
511
- **Table: `basic_string(const basic_string&, const Allocator&)`\protect and
512
- `basic_string(basic_string&&, const Allocator&)` effects** <a id="tab:strings.ctr.6">[tab:strings.ctr.6]</a>
513
-
514
- | Element | Value |
515
- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
516
- | `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()`. |
517
- | `size()` | the original value of `str.size()` |
518
- | `capacity()` | a value at least as large as `size()` |
519
- | `get_allocator()` | `alloc` |
520
-
521
 
522
  *Throws:* The second form throws nothing if
523
  `alloc == str.get_allocator()`.
524
 
525
  ``` cpp
@@ -529,226 +474,236 @@ template<class InputIterator,
529
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
530
  char_traits<typename iterator_traits<InputIterator>::value_type>,
531
  Allocator>;
532
  ```
533
 
534
- *Remarks:* Shall not participate in overload resolution if
535
- `InputIterator` is a type that does not qualify as an input iterator, or
536
- if `Allocator` is a type that does not qualify as an
537
- allocator ([[container.requirements.general]]).
538
 
539
  ``` cpp
540
- basic_string& operator=(const basic_string& str);
 
 
 
 
 
 
 
 
 
 
 
 
541
  ```
542
 
543
- *Effects:* If `*this` and `str` are not the same object, modifies
544
- `*this` as shown in Table  [[tab:strings.op=]].
 
 
 
 
545
 
546
- If `*this` and `str` are the same object, the member has no effect.
 
547
 
548
  *Returns:* `*this`.
549
 
550
- **Table: `operator=(const basic_string&)` effects** <a id="tab:strings.op=">[tab:strings.op=]</a>
551
-
552
- | Element | Value |
553
- | ------------ | --------------------------------------------------------------------------------------------------------------- |
554
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
555
- | `size()` | `str.size()` |
556
- | `capacity()` | a value at least as large as `size()` |
557
-
558
  ``` cpp
559
- basic_string& operator=(basic_string&& str)
560
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
561
  allocator_traits<Allocator>::is_always_equal::value);
562
  ```
563
 
564
  *Effects:* Move assigns as a sequence
565
- container ([[container.requirements]]), except that iterators, pointers
566
  and references may be invalidated.
567
 
568
  *Returns:* `*this`.
569
 
570
  ``` cpp
571
- basic_string& operator=(basic_string_view<charT, traits> sv);
 
572
  ```
573
 
574
- *Effects:* Equivalent to: `return assign(sv);`
 
 
 
 
 
 
575
 
576
  ``` cpp
577
- basic_string& operator=(const charT* s);
 
578
  ```
579
 
580
- *Returns:* `*this = basic_string(s)`.
 
 
581
 
582
- *Remarks:* Uses `traits::length()`.
 
583
 
584
  ``` cpp
585
- basic_string& operator=(charT c);
586
  ```
587
 
588
- *Returns:* `*this = basic_string(1, c)`.
589
 
590
  ``` cpp
591
- basic_string& operator=(initializer_list<charT> il);
592
  ```
593
 
594
- *Effects:* As if by: `*this = basic_string(il);`
 
 
 
 
595
 
596
- *Returns:* `*this`.
 
 
597
 
598
- #### `basic_string` iterator support <a id="string.iterators">[[string.iterators]]</a>
599
 
600
  ``` cpp
601
- iterator begin() noexcept;
602
- const_iterator begin() const noexcept;
603
- const_iterator cbegin() const noexcept;
604
  ```
605
 
606
  *Returns:* An iterator referring to the first character in the string.
607
 
608
  ``` cpp
609
- iterator end() noexcept;
610
- const_iterator end() const noexcept;
611
- const_iterator cend() const noexcept;
612
  ```
613
 
614
  *Returns:* An iterator which is the past-the-end value.
615
 
616
  ``` cpp
617
- reverse_iterator rbegin() noexcept;
618
- const_reverse_iterator rbegin() const noexcept;
619
- const_reverse_iterator crbegin() const noexcept;
620
  ```
621
 
622
  *Returns:* An iterator which is semantically equivalent to
623
  `reverse_iterator(end())`.
624
 
625
  ``` cpp
626
- reverse_iterator rend() noexcept;
627
- const_reverse_iterator rend() const noexcept;
628
- const_reverse_iterator crend() const noexcept;
629
  ```
630
 
631
  *Returns:* An iterator which is semantically equivalent to
632
  `reverse_iterator(begin())`.
633
 
634
- #### `basic_string` capacity <a id="string.capacity">[[string.capacity]]</a>
635
 
636
  ``` cpp
637
- size_type size() const noexcept;
 
638
  ```
639
 
640
  *Returns:* A count of the number of char-like objects currently in the
641
  string.
642
 
643
  *Complexity:* Constant time.
644
 
645
  ``` cpp
646
- size_type length() const noexcept;
647
- ```
648
-
649
- *Returns:* `size()`.
650
-
651
- ``` cpp
652
- size_type max_size() const noexcept;
653
  ```
654
 
655
  *Returns:* The largest possible number of char-like objects that can be
656
  stored in a `basic_string`.
657
 
658
  *Complexity:* Constant time.
659
 
660
  ``` cpp
661
- void resize(size_type n, charT c);
662
  ```
663
 
664
- *Throws:* `length_error` if `n > max_size()`.
665
 
666
- *Effects:* Alters the length of the string designated by `*this` as
667
- follows:
668
-
669
- - If `n <= size()`, the function replaces the string designated by
670
- `*this` with a string of length `n` whose elements are a copy of the
671
- initial elements of the original string designated by `*this`.
672
- - If `n > size()`, the function replaces the string designated by
673
- `*this` with a string of length `n` whose first `size()` elements are
674
- a copy of the original string designated by `*this`, and whose
675
- remaining elements are all initialized to `c`.
676
 
677
  ``` cpp
678
- void resize(size_type n);
679
  ```
680
 
681
- *Effects:* As if by `resize(n, charT())`.
682
 
683
  ``` cpp
684
- size_type capacity() const noexcept;
685
  ```
686
 
687
  *Returns:* The size of the allocated storage in the string.
688
 
 
 
689
  ``` cpp
690
- void reserve(size_type res_arg=0);
691
  ```
692
 
693
- The member function `reserve()` is a directive that informs a
694
- `basic_string` object of a planned change in size, so that it can manage
695
- the storage allocation accordingly.
 
 
 
696
 
697
- *Effects:* After `reserve()`, `capacity()` is greater or equal to the
698
- argument of `reserve`.
699
-
700
- [*Note 1*: Calling `reserve()` with a `res_arg` argument less than
701
- `capacity()` is in effect a non-binding shrink request. A call with
702
- `res_arg <= size()` is in effect a non-binding shrink-to-fit
703
- request. — *end note*]
704
-
705
- *Throws:* `length_error` if `res_arg > max_size()`.[^4]
706
 
707
  ``` cpp
708
- void shrink_to_fit();
709
  ```
710
 
711
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
712
  `capacity()` to `size()`.
713
 
714
- [*Note 2*: The request is non-binding to allow latitude for
715
  implementation-specific optimizations. — *end note*]
716
 
717
  It does not increase `capacity()`, but may reduce `capacity()` by
718
  causing reallocation.
719
 
720
- *Complexity:* Linear in the size of the sequence.
 
721
 
722
  *Remarks:* Reallocation invalidates all the references, pointers, and
723
- iterators referring to the elements in the sequence as well as the
724
- past-the-end iterator. If no reallocation happens, they remain valid.
725
 
726
- ``` cpp
727
- void clear() noexcept;
728
- ```
729
-
730
- *Effects:* Behaves as if the function calls:
731
 
732
  ``` cpp
733
- erase(begin(), end());
734
  ```
735
 
 
 
736
  ``` cpp
737
- bool empty() const noexcept;
738
  ```
739
 
740
- *Returns:* `size() == 0`.
741
 
742
- #### `basic_string` element access <a id="string.access">[[string.access]]</a>
743
 
744
  ``` cpp
745
- const_reference operator[](size_type pos) const;
746
- reference operator[](size_type pos);
747
  ```
748
 
749
- *Requires:* `pos <= size()`.
750
 
751
  *Returns:* `*(begin() + pos)` if `pos < size()`. Otherwise, returns a
752
  reference to an object of type `charT` with value `charT()`, where
753
  modifying the object to any value other than `charT()` leads to
754
  undefined behavior.
@@ -756,1026 +711,800 @@ undefined behavior.
756
  *Throws:* Nothing.
757
 
758
  *Complexity:* Constant time.
759
 
760
  ``` cpp
761
- const_reference at(size_type pos) const;
762
- reference at(size_type pos);
763
  ```
764
 
765
  *Throws:* `out_of_range` if `pos >= size()`.
766
 
767
  *Returns:* `operator[](pos)`.
768
 
769
  ``` cpp
770
- const charT& front() const;
771
- charT& front();
772
  ```
773
 
774
- *Requires:* `!empty()`.
775
 
776
  *Effects:* Equivalent to: `return operator[](0);`
777
 
778
  ``` cpp
779
- const charT& back() const;
780
- charT& back();
781
  ```
782
 
783
- *Requires:* `!empty()`.
784
 
785
  *Effects:* Equivalent to: `return operator[](size() - 1);`
786
 
787
- #### `basic_string` modifiers <a id="string.modifiers">[[string.modifiers]]</a>
788
 
789
- ##### `basic_string::operator+=` <a id="string.op+=">[[string.op+=]]</a>
790
 
791
  ``` cpp
792
- basic_string&
793
- operator+=(const basic_string& str);
794
  ```
795
 
796
- *Effects:* Calls `append(str)`.
797
-
798
- *Returns:* `*this`.
799
 
800
  ``` cpp
801
- basic_string& operator+=(basic_string_view<charT, traits> sv);
 
802
  ```
803
 
804
- *Effects:* Calls `append(sv)`.
 
 
 
 
805
 
806
- *Returns:* `*this`.
807
 
808
  ``` cpp
809
- basic_string& operator+=(const charT* s);
 
810
  ```
811
 
812
- *Effects:* Calls `append(s)`.
 
 
813
 
814
- *Returns:* `*this`.
815
 
816
  ``` cpp
817
- basic_string& operator+=(charT c);
818
  ```
819
 
820
- *Effects:* Calls `push_back(c)`;
821
-
822
- *Returns:* `*this`.
823
 
824
  ``` cpp
825
- basic_string& operator+=(initializer_list<charT> il);
826
  ```
827
 
828
- *Effects:* Calls `append(il)`.
829
-
830
- *Returns:* `*this`.
831
 
832
  ##### `basic_string::append` <a id="string.append">[[string.append]]</a>
833
 
834
  ``` cpp
835
- basic_string&
836
- append(const basic_string& str);
837
  ```
838
 
839
- *Effects:* Calls `append(str.data(), str.size())`.
840
-
841
- *Returns:* `*this`.
842
 
843
  ``` cpp
844
- basic_string&
845
- append(const basic_string& str, size_type pos, size_type n = npos);
846
  ```
847
 
848
- *Throws:* `out_of_range` if `pos > str.size()`.
849
-
850
- *Effects:* Determines the effective length `rlen` of the string to
851
- append as the smaller of `n` and `str``.size() - ``pos` and calls
852
- `append(str.data() + pos, rlen)`.
853
-
854
- *Returns:* `*this`.
855
 
856
  ``` cpp
857
- basic_string& append(basic_string_view<charT, traits> sv);
858
  ```
859
 
860
- *Effects:* Equivalent to: `return append(sv.data(), sv.size());`
861
-
862
  ``` cpp
863
  template<class T>
864
- basic_string& append(const T& t, size_type pos, size_type n = npos);
865
  ```
866
 
867
- *Throws:* `out_of_range` if `pos > sv.size()`.
868
 
869
- *Effects:* Creates a variable, `sv`, as if by
870
- `basic_string_view<charT, traits> sv = t`. Determines the effective
871
- length `rlen` of the string to append as the smaller of `n` and
872
- `sv.size() - pos` and calls `append(sv.data() + pos, rlen)`.
873
 
874
- *Remarks:* This function shall not participate in overload resolution
875
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
876
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
877
 
878
- *Returns:* `*this`.
 
 
 
879
 
880
  ``` cpp
881
- basic_string&
882
- append(const charT* s, size_type n);
883
  ```
884
 
885
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
886
 
887
- *Throws:* `length_error` if `size() + n > max_size()`.
 
 
888
 
889
- *Effects:* The function replaces the string controlled by `*this` with a
890
- string of length `size() + n` whose first `size()` elements are a copy
891
- of the original string controlled by `*this` and whose remaining
892
- elements are a copy of the initial `n` elements of `s`.
893
 
894
- *Returns:* `*this`.
 
 
 
895
 
896
  ``` cpp
897
- basic_string& append(const charT* s);
898
  ```
899
 
900
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
901
- elements of `charT`.
902
 
903
- *Effects:* Calls `append(s, traits::length(s))`.
904
 
905
  *Returns:* `*this`.
906
 
907
  ``` cpp
908
- basic_string& append(size_type n, charT c);
 
 
 
 
 
 
909
  ```
910
 
911
- *Effects:* Equivalent to `append(basic_string(n, c))`.
912
 
913
  *Returns:* `*this`.
914
 
915
  ``` cpp
916
  template<class InputIterator>
917
- basic_string& append(InputIterator first, InputIterator last);
918
  ```
919
 
920
- *Requires:* \[`first`, `last`) is a valid range.
 
921
 
922
- *Effects:* Equivalent to
923
- `append(basic_string(first, last, get_allocator()))`.
924
-
925
- *Returns:* `*this`.
926
 
927
  ``` cpp
928
- basic_string& append(initializer_list<charT> il);
929
  ```
930
 
931
- *Effects:* Calls `append(il.begin(), il.size())`.
932
-
933
- *Returns:* `*this`.
934
 
935
  ``` cpp
936
- void push_back(charT c);
937
  ```
938
 
939
- *Effects:* Equivalent to `append(static_cast<size_type>(1), c)`.
940
 
941
  ##### `basic_string::assign` <a id="string.assign">[[string.assign]]</a>
942
 
943
  ``` cpp
944
- basic_string& assign(const basic_string& str);
945
  ```
946
 
947
- *Effects:* Equivalent to `*this = str`.
948
-
949
- *Returns:* `*this`.
950
 
951
  ``` cpp
952
- basic_string& assign(basic_string&& str)
953
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
954
  allocator_traits<Allocator>::is_always_equal::value);
955
  ```
956
 
957
- *Effects:* Equivalent to `*this = std::move(str)`.
958
-
959
- *Returns:* `*this`.
960
 
961
  ``` cpp
962
- basic_string&
963
- assign(const basic_string& str, size_type pos,
964
- size_type n = npos);
965
  ```
966
 
967
- *Throws:* `out_of_range` if `pos > str.size()`.
968
-
969
- *Effects:* Determines the effective length `rlen` of the string to
970
- assign as the smaller of `n` and `str``.size() - ``pos` and calls
971
- `assign(str.data() + pos, rlen)`.
972
-
973
- *Returns:* `*this`.
974
 
975
  ``` cpp
976
- basic_string& assign(basic_string_view<charT, traits> sv);
977
  ```
978
 
979
- *Effects:* Equivalent to: `return assign(sv.data(), sv.size());`
980
-
981
  ``` cpp
982
  template<class T>
983
- basic_string& assign(const T& t, size_type pos, size_type n = npos);
984
  ```
985
 
986
- *Throws:* `out_of_range` if `pos > sv.size()`.
987
 
988
- *Effects:* Creates a variable, `sv`, as if by
989
- `basic_string_view<charT, traits> sv = t`. Determines the effective
990
- length `rlen` of the string to assign as the smaller of `n` and
991
- `sv.size() - pos` and calls `assign(sv.data() + pos, rlen)`.
992
 
993
- *Remarks:* This function shall not participate in overload resolution
994
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
995
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
996
 
997
- *Returns:* `*this`.
 
 
 
998
 
999
  ``` cpp
1000
- basic_string& assign(const charT* s, size_type n);
 
1001
  ```
1002
 
1003
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
1004
 
1005
- *Throws:* `length_error` if `n > max_size()`.
 
 
1006
 
1007
- *Effects:* Replaces the string controlled by `*this` with a string of
1008
- length `n` whose elements are a copy of those pointed to by `s`.
1009
 
1010
- *Returns:* `*this`.
 
 
 
1011
 
1012
  ``` cpp
1013
- basic_string& assign(const charT* s);
1014
  ```
1015
 
1016
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1017
- elements of `charT`.
1018
 
1019
- *Effects:* Calls `assign(s, traits::length(s))`.
 
1020
 
1021
  *Returns:* `*this`.
1022
 
1023
  ``` cpp
1024
- basic_string& assign(initializer_list<charT> il);
1025
  ```
1026
 
1027
- *Effects:* Calls `assign(il.begin(), il.size())`.
1028
 
1029
- `*this`.
 
 
 
 
1030
 
1031
  ``` cpp
1032
- basic_string& assign(size_type n, charT c);
1033
  ```
1034
 
1035
- *Effects:* Equivalent to `assign(basic_string(n, c))`.
1036
 
1037
- *Returns:* `*this`.
 
 
 
 
1038
 
1039
  ``` cpp
1040
  template<class InputIterator>
1041
- basic_string& assign(InputIterator first, InputIterator last);
1042
  ```
1043
 
1044
- *Effects:* Equivalent to
1045
- `assign(basic_string(first, last, get_allocator()))`.
1046
 
1047
- *Returns:* `*this`.
 
1048
 
1049
  ##### `basic_string::insert` <a id="string.insert">[[string.insert]]</a>
1050
 
1051
  ``` cpp
1052
- basic_string&
1053
- insert(size_type pos,
1054
- const basic_string& str);
1055
  ```
1056
 
1057
  *Effects:* Equivalent to: `return insert(pos, str.data(), str.size());`
1058
 
1059
  ``` cpp
1060
- basic_string&
1061
- insert(size_type pos1,
1062
- const basic_string& str,
1063
  size_type pos2, size_type n = npos);
1064
  ```
1065
 
1066
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
1067
 
1068
- *Effects:* Determines the effective length `rlen` of the string to
1069
- insert as the smaller of `n` and `str.size() - pos2` and calls
1070
- `insert(pos1, str.data() + pos2, rlen)`.
1071
-
1072
- *Returns:* `*this`.
1073
 
1074
  ``` cpp
1075
- basic_string& insert(size_type pos, basic_string_view<charT, traits> sv);
 
1076
  ```
1077
 
1078
- *Effects:* Equivalent to: `return insert(pos, sv.data(), sv.size());`
 
 
 
 
 
 
 
 
 
 
 
1079
 
1080
  ``` cpp
1081
  template<class T>
1082
- basic_string& insert(size_type pos1, const T& t,
1083
  size_type pos2, size_type n = npos);
1084
  ```
1085
 
1086
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > sv.size()`.
1087
 
1088
- *Effects:* Creates a variable, `sv`, as if by
1089
- `basic_string_view<charT, traits> sv = t`. Determines the effective
1090
- length `rlen` of the string to assign as the smaller of `n` and
1091
- `sv.size() - pos2` and calls `insert(pos1, sv.data() + pos2, rlen)`.
1092
 
1093
- *Remarks:* This function shall not participate in overload resolution
1094
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1095
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
1096
 
1097
- *Returns:* `*this`.
 
 
 
1098
 
1099
  ``` cpp
1100
- basic_string&
1101
- insert(size_type pos, const charT* s, size_type n);
1102
  ```
1103
 
1104
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
 
 
1105
 
1106
- *Throws:* `out_of_range` if `pos > size()` or `length_error` if
1107
- `size() + n > max_size()`.
 
1108
 
1109
- *Effects:* Replaces the string controlled by `*this` with a string of
1110
- length `size() + n` whose first `pos` elements are a copy of the initial
1111
- elements of the original string controlled by `*this` and whose next `n`
1112
- elements are a copy of the elements in `s` and whose remaining elements
1113
- are a copy of the remaining elements of the original string controlled
1114
- by `*this`.
1115
 
1116
  *Returns:* `*this`.
1117
 
1118
  ``` cpp
1119
- basic_string&
1120
- insert(size_type pos, const charT* s);
1121
  ```
1122
 
1123
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1124
- elements of `charT`.
1125
-
1126
  *Effects:* Equivalent to: `return insert(pos, s, traits::length(s));`
1127
 
1128
  ``` cpp
1129
- basic_string&
1130
- insert(size_type pos, size_type n, charT c);
1131
  ```
1132
 
1133
- *Effects:* Equivalent to `insert(pos, basic_string(n, c))`.
 
1134
 
1135
- *Returns:* `*this`.
 
 
 
 
 
 
1136
 
1137
  ``` cpp
1138
- iterator insert(const_iterator p, charT c);
1139
  ```
1140
 
1141
- *Requires:* `p` is a valid iterator on `*this`.
1142
 
1143
- *Effects:* Inserts a copy of `c` before the character referred to by
1144
- `p`.
1145
 
1146
- *Returns:* An iterator which refers to the copy of the inserted
1147
- character.
1148
 
1149
  ``` cpp
1150
- iterator insert(const_iterator p, size_type n, charT c);
1151
  ```
1152
 
1153
- *Requires:* `p` is a valid iterator on `*this`.
1154
 
1155
- *Effects:* Inserts `n` copies of `c` before the character referred to by
1156
- `p`.
1157
 
1158
- *Returns:* An iterator which refers to the copy of the first inserted
1159
- character, or `p` if `n == 0`.
1160
 
1161
  ``` cpp
1162
  template<class InputIterator>
1163
- iterator insert(const_iterator p, InputIterator first, InputIterator last);
1164
  ```
1165
 
1166
- *Requires:* `p` is a valid iterator on `*this`. `[first, last)` is a
1167
- valid range.
 
 
1168
 
1169
  *Effects:* Equivalent to
1170
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
1171
 
1172
- *Returns:* An iterator which refers to the copy of the first inserted
1173
- character, or `p` if `first == last`.
1174
 
1175
  ``` cpp
1176
- iterator insert(const_iterator p, initializer_list<charT> il);
1177
  ```
1178
 
1179
- *Effects:* As if by `insert(p, il.begin(), il.end())`.
1180
-
1181
- *Returns:* An iterator which refers to the copy of the first inserted
1182
- character, or `p` if `i1` is empty.
1183
 
1184
  ##### `basic_string::erase` <a id="string.erase">[[string.erase]]</a>
1185
 
1186
  ``` cpp
1187
- basic_string& erase(size_type pos = 0, size_type n = npos);
1188
  ```
1189
 
1190
  *Throws:* `out_of_range` if `pos` `> size()`.
1191
 
1192
  *Effects:* Determines the effective length `xlen` of the string to be
1193
- removed as the smaller of `n` and `size() - pos`.
1194
-
1195
- The function then replaces the string controlled by `*this` with a
1196
- string of length `size() - xlen` whose first `pos` elements are a copy
1197
- of the initial elements of the original string controlled by `*this`,
1198
- and whose remaining elements are a copy of the elements of the original
1199
- string controlled by `*this` beginning at position `pos + xlen`.
1200
 
1201
  *Returns:* `*this`.
1202
 
1203
  ``` cpp
1204
- iterator erase(const_iterator p);
1205
  ```
1206
 
 
 
1207
  *Throws:* Nothing.
1208
 
1209
  *Effects:* Removes the character referred to by `p`.
1210
 
1211
  *Returns:* An iterator which points to the element immediately following
1212
  `p` prior to the element being erased. If no such element exists,
1213
  `end()` is returned.
1214
 
1215
  ``` cpp
1216
- iterator erase(const_iterator first, const_iterator last);
1217
  ```
1218
 
1219
- *Requires:* `first` and `last` are valid iterators on `*this`, defining
1220
- a range `[first, last)`.
1221
 
1222
  *Throws:* Nothing.
1223
 
1224
  *Effects:* Removes the characters in the range `[first, last)`.
1225
 
1226
  *Returns:* An iterator which points to the element pointed to by `last`
1227
  prior to the other elements being erased. If no such element exists,
1228
  `end()` is returned.
1229
 
1230
  ``` cpp
1231
- void pop_back();
1232
  ```
1233
 
1234
- *Requires:* `!empty()`.
1235
 
1236
  *Throws:* Nothing.
1237
 
1238
- *Effects:* Equivalent to `erase(size() - 1, 1)`.
1239
 
1240
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
1241
 
1242
  ``` cpp
1243
- basic_string&
1244
- replace(size_type pos1, size_type n1,
1245
- const basic_string& str);
1246
  ```
1247
 
1248
  *Effects:* Equivalent to:
1249
  `return replace(pos1, n1, str.data(), str.size());`
1250
 
1251
  ``` cpp
1252
- basic_string&
1253
- replace(size_type pos1, size_type n1,
1254
- const basic_string& str,
1255
  size_type pos2, size_type n2 = npos);
1256
  ```
1257
 
1258
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
1259
-
1260
- *Effects:* Determines the effective length `rlen` of the string to be
1261
- inserted as the smaller of `n2` and `str.size() - pos2` and calls
1262
- `replace(pos1, n1, str.data() + pos2, rlen)`.
1263
 
1264
- *Returns:* `*this`.
 
 
1265
 
1266
  ``` cpp
1267
- basic_string& replace(size_type pos1, size_type n1,
1268
- basic_string_view<charT, traits> sv);
1269
  ```
1270
 
 
 
 
 
 
 
1271
  *Effects:* Equivalent to:
1272
- `return replace(pos1, n1, sv.data(), sv.size());`
 
 
 
 
1273
 
1274
  ``` cpp
1275
  template<class T>
1276
- basic_string& replace(size_type pos1, size_type n1, const T& t,
1277
  size_type pos2, size_type n2 = npos);
1278
  ```
1279
 
1280
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > sv.size()`.
1281
 
1282
- *Effects:* Creates a variable, `sv`, as if by
1283
- `basic_string_view<charT, traits> sv = t`. Determines the effective
1284
- length `rlen` of the string to be inserted as the smaller of `n2` and
1285
- `sv.size() - pos2` and calls
1286
- `replace(pos1, n1, sv.data() + pos2, rlen)`.
1287
 
1288
- *Remarks:* This function shall not participate in overload resolution
1289
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1290
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
1291
 
1292
- *Returns:* `*this`.
 
 
 
1293
 
1294
  ``` cpp
1295
- basic_string&
1296
- replace(size_type pos1, size_type n1, const charT* s, size_type n2);
1297
  ```
1298
 
1299
- *Requires:* `s` points to an array of at least `n2` elements of `charT`.
 
 
1300
 
1301
- *Throws:* `out_of_range` if `pos1 > size()` or `length_error` if the
1302
- length of the resulting string would exceed `max_size()` (see below).
 
 
1303
 
1304
  *Effects:* Determines the effective length `xlen` of the string to be
1305
  removed as the smaller of `n1` and `size() - pos1`. If
1306
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
1307
- function replaces the string controlled by \*`this` with a string of
1308
- length `size() - xlen + n2` whose first `pos1` elements are a copy of
1309
- the initial elements of the original string controlled by `*this`, whose
1310
- next `n2` elements are a copy of the initial `n2` elements of `s`, and
1311
- whose remaining elements are a copy of the elements of the original
1312
- string controlled by `*this` beginning at position `pos + xlen`.
1313
 
1314
  *Returns:* `*this`.
1315
 
1316
  ``` cpp
1317
- basic_string&
1318
- replace(size_type pos, size_type n, const charT* s);
1319
  ```
1320
 
1321
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1322
- elements of `charT`.
1323
-
1324
  *Effects:* Equivalent to:
1325
  `return replace(pos, n, s, traits::length(s));`
1326
 
1327
  ``` cpp
1328
- basic_string&
1329
- replace(size_type pos1, size_type n1,
1330
- size_type n2, charT c);
1331
  ```
1332
 
1333
- *Effects:* Equivalent to `replace(pos1, n1, basic_string(n2, c))`.
 
 
 
 
 
 
 
 
 
 
 
1334
 
1335
  *Returns:* `*this`.
1336
 
1337
  ``` cpp
1338
- basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
1339
  ```
1340
 
1341
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1342
-
1343
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, str)`.
1344
-
1345
- *Returns:* `*this`.
1346
 
1347
  ``` cpp
1348
- basic_string& replace(const_iterator i1, const_iterator i2,
1349
- basic_string_view<charT, traits> sv);
1350
  ```
1351
 
1352
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1353
 
1354
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, sv)`.
 
 
1355
 
1356
- *Returns:* `*this`.
 
 
1357
 
1358
  ``` cpp
1359
- basic_string&
1360
- replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
1361
  ```
1362
 
1363
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges and
1364
- `s` points to an array of at least `n` elements of `charT`.
1365
-
1366
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, s, n)`.
1367
-
1368
- *Returns:* `*this`.
1369
-
1370
  ``` cpp
1371
- basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
1372
  ```
1373
 
1374
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges and
1375
- `s` points to an array of at least `traits::length(s) + 1` elements of
1376
- `charT`.
1377
 
1378
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, s, traits::length(s))`.
 
 
1379
 
1380
- *Returns:* `*this`.
 
1381
 
1382
  ``` cpp
1383
- basic_string& replace(const_iterator i1, const_iterator i2, size_type n,
1384
- charT c);
1385
  ```
1386
 
1387
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1388
 
1389
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, basic_string(n, c))`.
1390
-
1391
- *Returns:* `*this`.
1392
 
1393
  ``` cpp
1394
  template<class InputIterator>
1395
- basic_string& replace(const_iterator i1, const_iterator i2,
1396
  InputIterator j1, InputIterator j2);
1397
  ```
1398
 
1399
- *Requires:* \[`begin()`, `i1`), \[`i1`, `i2`) and \[`j1`, `j2`) are
1400
- valid ranges.
1401
 
1402
- *Effects:* Calls
1403
- `replace(i1 - begin(), i2 - i1, basic_string(j1, j2, get_allocator()))`.
1404
-
1405
- *Returns:* `*this`.
1406
 
1407
  ``` cpp
1408
- basic_string& replace(const_iterator i1, const_iterator i2,
1409
- initializer_list<charT> il);
1410
  ```
1411
 
1412
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1413
-
1414
- *Effects:* Calls
1415
- `replace(i1 - begin(), i2 - i1, il.begin(), il.size())`.
1416
-
1417
- *Returns:* `*this`.
1418
 
1419
  ##### `basic_string::copy` <a id="string.copy">[[string.copy]]</a>
1420
 
1421
  ``` cpp
1422
- size_type copy(charT* s, size_type n, size_type pos = 0) const;
1423
  ```
1424
 
1425
- Let `rlen` be the smaller of `n` and `size() - pos`.
1426
-
1427
- *Throws:* `out_of_range` if `pos > size()`.
1428
-
1429
- *Requires:* \[`s`, `s + rlen`) is a valid range.
1430
-
1431
- *Effects:* Equivalent to: `traits::copy(s, data() + pos, rlen)`.
1432
 
1433
  [*Note 1*: This does not terminate `s` with a null
1434
  object. — *end note*]
1435
 
1436
- *Returns:* `rlen`.
1437
-
1438
  ##### `basic_string::swap` <a id="string.swap">[[string.swap]]</a>
1439
 
1440
  ``` cpp
1441
- void swap(basic_string& s)
1442
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1443
  allocator_traits<Allocator>::is_always_equal::value);
1444
  ```
1445
 
1446
- *Postconditions:* `*this` contains the same sequence of characters that
1447
- was in `s`, `s` contains the same sequence of characters that was in
1448
- `*this`.
 
 
 
1449
 
1450
  *Throws:* Nothing.
1451
 
1452
  *Complexity:* Constant time.
1453
 
1454
- #### `basic_string` string operations <a id="string.ops">[[string.ops]]</a>
1455
 
1456
- ##### `basic_string` accessors <a id="string.accessors">[[string.accessors]]</a>
1457
 
1458
  ``` cpp
1459
- const charT* c_str() const noexcept;
1460
- const charT* data() const noexcept;
1461
  ```
1462
 
1463
- *Returns:* A pointer `p` such that `p + i == &operator[](i)` for each
1464
- `i` in \[`0`, `size()`\].
1465
 
1466
  *Complexity:* Constant time.
1467
 
1468
- *Requires:* The program shall not alter any of the values stored in the
1469
- character array.
1470
 
1471
  ``` cpp
1472
- charT* data() noexcept;
1473
  ```
1474
 
1475
- *Returns:* A pointer `p` such that `p + i == &operator[](i)` for each
1476
- `i` in \[`0`, `size()`\].
1477
 
1478
  *Complexity:* Constant time.
1479
 
1480
- *Requires:* The program shall not alter the value stored at
1481
- `p + size()`.
1482
 
1483
  ``` cpp
1484
- operator basic_string_view<charT, traits>() const noexcept;
1485
  ```
1486
 
1487
  *Effects:* Equivalent to:
1488
  `return basic_string_view<charT, traits>(data(), size());`
1489
 
1490
  ``` cpp
1491
- allocator_type get_allocator() const noexcept;
1492
  ```
1493
 
1494
  *Returns:* A copy of the `Allocator` object used to construct the string
1495
  or, if that allocator has been replaced, a copy of the most recent
1496
  replacement.
1497
 
1498
- ##### `basic_string::find` <a id="string.find">[[string.find]]</a>
1499
 
1500
- ``` cpp
1501
- size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
1502
- ```
1503
-
1504
- *Effects:* Determines the lowest position `xpos`, if possible, such that
1505
- both of the following conditions hold:
1506
-
1507
- - `pos <= xpos` and `xpos + sv.size() <= size()`;
1508
- - `traits::eq(at(xpos + I), sv.at(I))` for all elements `I` of the data
1509
- referenced by `sv`.
1510
-
1511
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1512
- Otherwise, returns `npos`.
1513
-
1514
- ``` cpp
1515
- size_type find(const basic_string& str, size_type pos = 0) const noexcept;
1516
- ```
1517
-
1518
- *Effects:* Equivalent to:
1519
- `return find(basic_string_view<charT, traits>(str), pos);`
1520
-
1521
- ``` cpp
1522
- size_type find(const charT* s, size_type pos, size_type n) const;
1523
- ```
1524
-
1525
- *Returns:* `find(basic_string_view<charT, traits>(s, n), pos)`.
1526
-
1527
- ``` cpp
1528
- size_type find(const charT* s, size_type pos = 0) const;
1529
- ```
1530
-
1531
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1532
- elements of `charT`.
1533
-
1534
- *Returns:* `find(basic_string_view<charT, traits>(s), pos)`.
1535
-
1536
- ``` cpp
1537
- size_type find(charT c, size_type pos = 0) const;
1538
- ```
1539
-
1540
- *Returns:* `find(basic_string(1, c), pos)`.
1541
-
1542
- ##### `basic_string::rfind` <a id="string.rfind">[[string.rfind]]</a>
1543
-
1544
- ``` cpp
1545
- size_type rfind(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
1546
- ```
1547
-
1548
- *Effects:* Determines the highest position `xpos`, if possible, such
1549
- that both of the following conditions hold:
1550
-
1551
- - `xpos <= pos` and `xpos + sv.size() <= size()`;
1552
- - `traits::eq(at(xpos + I), sv.at(I))` for all elements `I` of the data
1553
- referenced by `sv`.
1554
-
1555
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1556
- Otherwise, returns `npos`.
1557
-
1558
- ``` cpp
1559
- size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
1560
- ```
1561
-
1562
- *Effects:* Equivalent to:
1563
- `return rfind(basic_string_view<charT, traits>(str), pos);`
1564
-
1565
- ``` cpp
1566
- size_type rfind(const charT* s, size_type pos, size_type n) const;
1567
- ```
1568
-
1569
- *Returns:* `rfind(basic_string_view<charT, traits>(s, n), pos)`.
1570
 
 
1571
  ``` cpp
1572
- size_type rfind(const charT* s, size_type pos = npos) const;
1573
  ```
1574
 
1575
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1576
- elements of `charT`.
1577
-
1578
- *Returns:* `rfind(basic_string_view<charT, traits>(s), pos)`.
1579
-
1580
  ``` cpp
1581
- size_type rfind(charT c, size_type pos = npos) const;
1582
  ```
1583
 
1584
- *Returns:* `rfind(basic_string(1, c), pos)`.
1585
-
1586
- ##### `basic_string::find_first_of` <a id="string.find.first.of">[[string.find.first.of]]</a>
1587
-
1588
  ``` cpp
1589
- size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
1590
  ```
1591
 
1592
- *Effects:* Determines the lowest position `xpos`, if possible, such that
1593
- both of the following conditions hold:
1594
-
1595
- - `pos <= xpos` and `xpos < size()`;
1596
- - `traits::eq(at(xpos), sv.at(I))` for some element `I` of the data
1597
- referenced by `sv`.
1598
-
1599
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1600
- Otherwise, returns `npos`.
1601
-
1602
  ``` cpp
1603
- size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
1604
  ```
1605
 
1606
- *Effects:* Equivalent to:
1607
- `return find_first_of(basic_string_view<charT, traits>(str), pos);`
1608
-
1609
  ``` cpp
1610
- size_type find_first_of(const charT* s, size_type pos, size_type n) const;
1611
  ```
1612
 
1613
- *Returns:* `find_first_of(basic_string_view<charT, traits>(s, n), pos)`.
1614
-
1615
- ``` cpp
1616
- size_type find_first_of(const charT* s, size_type pos = 0) const;
1617
- ```
1618
-
1619
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1620
- elements of `charT`.
1621
-
1622
- *Returns:* `find_first_of(basic_string_view<charT, traits>(s), pos)`.
1623
-
1624
- ``` cpp
1625
- size_type find_first_of(charT c, size_type pos = 0) const;
1626
- ```
1627
-
1628
- *Returns:* `find_first_of(basic_string(1, c), pos)`.
1629
-
1630
- ##### `basic_string::find_last_of` <a id="string.find.last.of">[[string.find.last.of]]</a>
1631
-
1632
- ``` cpp
1633
- size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
1634
- ```
1635
-
1636
- *Effects:* Determines the highest position `xpos`, if possible, such
1637
- that both of the following conditions hold:
1638
-
1639
- - `xpos <= pos` and `xpos < size()`;
1640
- - `traits::eq(at(xpos), sv.at(I))` for some element `I` of the data
1641
- referenced by `sv`.
1642
-
1643
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1644
- Otherwise, returns `npos`.
1645
-
1646
  ``` cpp
1647
- size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
 
 
 
 
 
 
 
 
 
 
 
1648
  ```
1649
 
1650
- *Effects:* Equivalent to:
1651
- `return find_last_of(basic_string_view<charT, traits>(str), pos);`
1652
-
1653
- ``` cpp
1654
- size_type find_last_of(const charT* s, size_type pos, size_type n) const;
1655
- ```
1656
-
1657
- *Returns:* `find_last_of(basic_string_view<charT, traits>(s, n), pos)`.
1658
-
1659
- ``` cpp
1660
- size_type find_last_of(const charT* s, size_type pos = npos) const;
1661
- ```
1662
-
1663
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1664
- elements of `charT`.
1665
-
1666
- *Returns:* `find_last_of(basic_string_view<charT, traits>(s), pos)`.
1667
-
1668
- ``` cpp
1669
- size_type find_last_of(charT c, size_type pos = npos) const;
1670
- ```
1671
-
1672
- *Returns:* `find_last_of(basic_string(1, c), pos)`.
1673
-
1674
- ##### `basic_string::find_first_not_of` <a id="string.find.first.not.of">[[string.find.first.not.of]]</a>
1675
-
1676
- ``` cpp
1677
- size_type find_first_not_of(basic_string_view<charT, traits> sv,
1678
- size_type pos = 0) const noexcept;
1679
- ```
1680
-
1681
- *Effects:* Determines the lowest position `xpos`, if possible, such that
1682
- both of the following conditions hold:
1683
-
1684
- - `pos <= xpos` and `xpos < size()`;
1685
- - `traits::eq(at(xpos), sv.at(I))` for no element `I` of the data
1686
- referenced by `sv`.
1687
-
1688
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1689
- Otherwise, returns `npos`.
1690
-
1691
- ``` cpp
1692
- size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
1693
- ```
1694
-
1695
- *Effects:* Equivalent to:
1696
-
1697
- ``` cpp
1698
- return find_first_not_of(basic_string_view<charT, traits>(str), pos);
1699
- ```
1700
-
1701
- ``` cpp
1702
- size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
1703
- ```
1704
-
1705
- *Returns:*
1706
- `find_first_not_of(basic_string_view<charT, traits>(s, n), pos)`.
1707
-
1708
- ``` cpp
1709
- size_type find_first_not_of(const charT* s, size_type pos = 0) const;
1710
- ```
1711
-
1712
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1713
- elements of `charT`.
1714
-
1715
- *Returns:*
1716
- `find_first_not_of(basic_string_view<charT, traits>(s), pos)`.
1717
-
1718
- ``` cpp
1719
- size_type find_first_not_of(charT c, size_type pos = 0) const;
1720
- ```
1721
-
1722
- *Returns:* `find_first_not_of(basic_string(1, c), pos)`.
1723
-
1724
- ##### `basic_string::find_last_not_of` <a id="string.find.last.not.of">[[string.find.last.not.of]]</a>
1725
-
1726
- ``` cpp
1727
- size_type find_last_not_of(basic_string_view<charT, traits> sv,
1728
- size_type pos = npos) const noexcept;
1729
- ```
1730
-
1731
- *Effects:* Determines the highest position `xpos`, if possible, such
1732
- that both of the following conditions hold:
1733
-
1734
- - `xpos <= pos` and `xpos < size()`;
1735
- - `traits::eq(at(xpos), sv.at(I))` for no element `I` of the data
1736
- referenced by `sv`.
1737
-
1738
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1739
- Otherwise, returns `npos`.
1740
-
1741
- ``` cpp
1742
- size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
1743
- ```
1744
-
1745
- *Effects:* Equivalent to:
1746
-
1747
- ``` cpp
1748
- return find_last_not_of(basic_string_view<charT, traits>(str), pos);
1749
- ```
1750
-
1751
- ``` cpp
1752
- size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
1753
- ```
1754
-
1755
- *Returns:*
1756
- `find_last_not_of(basic_string_view<charT, traits>(s, n), pos)`.
1757
-
1758
- ``` cpp
1759
- size_type find_last_not_of(const charT* s, size_type pos = npos) const;
1760
- ```
1761
 
1762
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1763
- elements of `charT`.
 
1764
 
1765
- *Returns:* `find_last_not_of(basic_string_view<charT, traits>(s), pos)`.
1766
 
1767
  ``` cpp
1768
- size_type find_last_not_of(charT c, size_type pos = npos) const;
 
1769
  ```
1770
 
1771
- *Returns:* `find_last_not_of(basic_string(1, c), pos)`.
 
1772
 
1773
  ##### `basic_string::substr` <a id="string.substr">[[string.substr]]</a>
1774
 
1775
  ``` cpp
1776
- basic_string substr(size_type pos = 0, size_type n = npos) const;
1777
  ```
1778
 
1779
  *Throws:* `out_of_range` if `pos > size()`.
1780
 
1781
  *Effects:* Determines the effective length `rlen` of the string to copy
@@ -1784,97 +1513,131 @@ as the smaller of `n` and `size() - pos`.
1784
  *Returns:* `basic_string(data()+pos, rlen)`.
1785
 
1786
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
1787
 
1788
  ``` cpp
1789
- int compare(basic_string_view<charT, traits> sv) const noexcept;
 
1790
  ```
1791
 
1792
- *Effects:* Determines the effective length `rlen` of the strings to
1793
- compare as the smaller of `size()` and `sv.size()`. The function then
1794
- compares the two strings by calling
1795
- `traits::compare(data(), sv.data(), rlen)`.
1796
 
1797
- *Returns:* The nonzero result if the result of the comparison is
1798
- nonzero. Otherwise, returns a value as indicated in
1799
- Table  [[tab:strings.compare]].
1800
 
1801
- **Table: `compare()` results** <a id="tab:strings.compare">[tab:strings.compare]</a>
 
1802
 
1803
- | Condition | Return Value |
1804
- | --------------------- | ------------ |
1805
- | `size() < sv.size()` | `< 0` |
1806
- | `size() == sv.size()` | ` 0` |
1807
- | `size() > sv.size()` | `> 0` |
1808
 
1809
  ``` cpp
1810
- int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
 
1811
  ```
1812
 
 
 
 
 
 
 
1813
  *Effects:* Equivalent to:
1814
 
1815
  ``` cpp
1816
- return basic_string_view<charT, traits>(data(), size()).substr(pos1, n1).compare(sv);
1817
  ```
1818
 
1819
  ``` cpp
1820
  template<class T>
1821
- int compare(size_type pos1, size_type n1, const T& t,
1822
  size_type pos2, size_type n2 = npos) const;
1823
  ```
1824
 
 
 
 
 
 
 
1825
  *Effects:* Equivalent to:
1826
 
1827
  ``` cpp
1828
- basic_string_view<charT, traits> sv = t;
1829
- return basic_string_view<charT, traits>(
1830
- data(), size()).substr(pos1, n1).compare(sv.substr(pos2, n2));
1831
  ```
1832
 
1833
- *Remarks:* This function shall not participate in overload resolution
1834
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1835
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
1836
-
1837
  ``` cpp
1838
- int compare(const basic_string& str) const noexcept;
1839
  ```
1840
 
1841
  *Effects:* Equivalent to:
1842
  `return compare(basic_string_view<charT, traits>(str));`
1843
 
1844
  ``` cpp
1845
- int compare(size_type pos1, size_type n1, const basic_string& str) const;
1846
  ```
1847
 
1848
  *Effects:* Equivalent to:
1849
  `return compare(pos1, n1, basic_string_view<charT, traits>(str));`
1850
 
1851
  ``` cpp
1852
- int compare(size_type pos1, size_type n1,
1853
- const basic_string& str,
1854
  size_type pos2, size_type n2 = npos) const;
1855
  ```
1856
 
1857
  *Effects:* Equivalent to:
1858
 
1859
  ``` cpp
1860
  return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);
1861
  ```
1862
 
1863
  ``` cpp
1864
- int compare(const charT* s) const;
1865
  ```
1866
 
1867
- *Returns:* `compare(basic_string(s))`.
 
1868
 
1869
  ``` cpp
1870
- int compare(size_type pos, size_type n1, const charT* s) const;
1871
  ```
1872
 
1873
- *Returns:* `basic_string(*this, pos, n1).compare(basic_string(s))`.
 
1874
 
1875
  ``` cpp
1876
- int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
1877
  ```
1878
 
1879
- *Returns:* `basic_string(*this, pos, n1).compare(basic_string(s, n2))`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1880
 
 
6
  is also called a “string” if the type of the char-like objects that it
7
  holds is clear from context. In the rest of this Clause, the type of the
8
  char-like objects held in a `basic_string` object is designated by
9
  `charT`.
10
 
11
+ A specialization of `basic_string` is a contiguous container
12
+ [[container.requirements.general]].
 
13
 
14
+ In all cases, \[`data()`, `data() + size()`\] is a valid range,
15
+ `data() + size()` points at an object with value `charT()` (a “null
16
+ terminator”), and `size() <= capacity()` is `true`.
 
 
 
 
 
 
 
 
 
17
 
18
  ``` cpp
19
  namespace std {
20
  template<class charT, class traits = char_traits<charT>,
21
  class Allocator = allocator<charT>>
22
  class basic_string {
23
  public:
24
+ // types
25
  using traits_type = traits;
26
  using value_type = charT;
27
  using allocator_type = Allocator;
28
  using size_type = typename allocator_traits<Allocator>::size_type;
29
  using difference_type = typename allocator_traits<Allocator>::difference_type;
 
37
  using reverse_iterator = std::reverse_iterator<iterator>;
38
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
39
  static const size_type npos = -1;
40
 
41
  // [string.cons], construct/copy/destroy
42
+ constexpr basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }
43
+ constexpr explicit basic_string(const Allocator& a) noexcept;
44
+ constexpr basic_string(const basic_string& str);
45
+ constexpr basic_string(basic_string&& str) noexcept;
46
+ constexpr basic_string(const basic_string& str, size_type pos,
47
  const Allocator& a = Allocator());
48
+ constexpr basic_string(const basic_string& str, size_type pos, size_type n,
49
  const Allocator& a = Allocator());
50
  template<class T>
51
+ constexpr basic_string(const T& t, size_type pos, size_type n,
52
  const Allocator& a = Allocator());
53
+ template<class T>
54
+ constexpr explicit basic_string(const T& t, const Allocator& a = Allocator());
55
+ constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
56
+ constexpr basic_string(const charT* s, const Allocator& a = Allocator());
57
+ constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
 
58
  template<class InputIterator>
59
+ constexpr basic_string(InputIterator begin, InputIterator end,
60
  const Allocator& a = Allocator());
61
+ constexpr basic_string(initializer_list<charT>, const Allocator& = Allocator());
62
+ constexpr basic_string(const basic_string&, const Allocator&);
63
+ constexpr basic_string(basic_string&&, const Allocator&);
64
+ constexpr ~basic_string();
65
 
66
+ constexpr basic_string& operator=(const basic_string& str);
67
+ constexpr basic_string& operator=(basic_string&& str)
 
68
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
69
  allocator_traits<Allocator>::is_always_equal::value);
70
+ template<class T>
71
+ constexpr basic_string& operator=(const T& t);
72
+ constexpr basic_string& operator=(const charT* s);
73
+ constexpr basic_string& operator=(charT c);
74
+ constexpr basic_string& operator=(initializer_list<charT>);
75
 
76
  // [string.iterators], iterators
77
+ constexpr iterator begin() noexcept;
78
+ constexpr const_iterator begin() const noexcept;
79
+ constexpr iterator end() noexcept;
80
+ constexpr const_iterator end() const noexcept;
81
 
82
+ constexpr reverse_iterator rbegin() noexcept;
83
+ constexpr const_reverse_iterator rbegin() const noexcept;
84
+ constexpr reverse_iterator rend() noexcept;
85
+ constexpr const_reverse_iterator rend() const noexcept;
86
 
87
+ constexpr const_iterator cbegin() const noexcept;
88
+ constexpr const_iterator cend() const noexcept;
89
+ constexpr const_reverse_iterator crbegin() const noexcept;
90
+ constexpr const_reverse_iterator crend() const noexcept;
91
 
92
  // [string.capacity], capacity
93
+ constexpr size_type size() const noexcept;
94
+ constexpr size_type length() const noexcept;
95
+ constexpr size_type max_size() const noexcept;
96
+ constexpr void resize(size_type n, charT c);
97
+ constexpr void resize(size_type n);
98
+ constexpr size_type capacity() const noexcept;
99
+ constexpr void reserve(size_type res_arg);
100
+ constexpr void shrink_to_fit();
101
+ constexpr void clear() noexcept;
102
+ [[nodiscard]] constexpr bool empty() const noexcept;
103
 
104
  // [string.access], element access
105
+ constexpr const_reference operator[](size_type pos) const;
106
+ constexpr reference operator[](size_type pos);
107
+ constexpr const_reference at(size_type n) const;
108
+ constexpr reference at(size_type n);
109
 
110
+ constexpr const charT& front() const;
111
+ constexpr charT& front();
112
+ constexpr const charT& back() const;
113
+ constexpr charT& back();
114
 
115
  // [string.modifiers], modifiers
116
+ constexpr basic_string& operator+=(const basic_string& str);
 
 
 
 
 
 
 
 
117
  template<class T>
118
+ constexpr basic_string& operator+=(const T& t);
119
+ constexpr basic_string& operator+=(const charT* s);
120
+ constexpr basic_string& operator+=(charT c);
121
+ constexpr basic_string& operator+=(initializer_list<charT>);
122
+ constexpr basic_string& append(const basic_string& str);
123
+ constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
124
+ template<class T>
125
+ constexpr basic_string& append(const T& t);
126
+ template<class T>
127
+ constexpr basic_string& append(const T& t, size_type pos, size_type n = npos);
128
+ constexpr basic_string& append(const charT* s, size_type n);
129
+ constexpr basic_string& append(const charT* s);
130
+ constexpr basic_string& append(size_type n, charT c);
131
  template<class InputIterator>
132
+ constexpr basic_string& append(InputIterator first, InputIterator last);
133
+ constexpr basic_string& append(initializer_list<charT>);
 
134
 
135
+ constexpr void push_back(charT c);
136
+
137
+ constexpr basic_string& assign(const basic_string& str);
138
+ constexpr basic_string& assign(basic_string&& str)
139
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
140
  allocator_traits<Allocator>::is_always_equal::value);
141
+ constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
 
 
142
  template<class T>
143
+ constexpr basic_string& assign(const T& t);
144
+ template<class T>
145
+ constexpr basic_string& assign(const T& t, size_type pos, size_type n = npos);
146
+ constexpr basic_string& assign(const charT* s, size_type n);
147
+ constexpr basic_string& assign(const charT* s);
148
+ constexpr basic_string& assign(size_type n, charT c);
149
  template<class InputIterator>
150
+ constexpr basic_string& assign(InputIterator first, InputIterator last);
151
+ constexpr basic_string& assign(initializer_list<charT>);
152
 
153
+ constexpr basic_string& insert(size_type pos, const basic_string& str);
154
+ constexpr basic_string& insert(size_type pos1, const basic_string& str,
155
  size_type pos2, size_type n = npos);
 
156
  template<class T>
157
+ constexpr basic_string& insert(size_type pos, const T& t);
158
+ template<class T>
159
+ constexpr basic_string& insert(size_type pos1, const T& t,
160
  size_type pos2, size_type n = npos);
161
+ constexpr basic_string& insert(size_type pos, const charT* s, size_type n);
162
+ constexpr basic_string& insert(size_type pos, const charT* s);
163
+ constexpr basic_string& insert(size_type pos, size_type n, charT c);
164
+ constexpr iterator insert(const_iterator p, charT c);
165
+ constexpr iterator insert(const_iterator p, size_type n, charT c);
166
  template<class InputIterator>
167
+ constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
168
+ constexpr iterator insert(const_iterator p, initializer_list<charT>);
169
 
170
+ constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
171
+ constexpr iterator erase(const_iterator p);
172
+ constexpr iterator erase(const_iterator first, const_iterator last);
173
 
174
+ constexpr void pop_back();
175
 
176
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
177
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
 
 
178
  size_type pos2, size_type n2 = npos);
 
 
179
  template<class T>
180
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t);
181
+ template<class T>
182
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t,
183
  size_type pos2, size_type n2 = npos);
184
+ constexpr basic_string& replace(size_type pos, size_type n1, const charT* s, size_type n2);
185
+ constexpr basic_string& replace(size_type pos, size_type n1, const charT* s);
186
+ constexpr basic_string& replace(size_type pos, size_type n1, size_type n2, charT c);
187
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2,
 
 
 
188
  const basic_string& str);
189
+ template<class T>
190
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t);
191
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s,
192
  size_type n);
193
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
194
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
 
195
  template<class InputIterator>
196
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2,
197
  InputIterator j1, InputIterator j2);
198
+ constexpr basic_string& replace(const_iterator, const_iterator, initializer_list<charT>);
199
 
200
+ constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
201
+
202
+ constexpr void swap(basic_string& str)
203
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
204
  allocator_traits<Allocator>::is_always_equal::value);
205
 
206
  // [string.ops], string operations
207
+ constexpr const charT* c_str() const noexcept;
208
+ constexpr const charT* data() const noexcept;
209
+ constexpr charT* data() noexcept;
210
+ constexpr operator basic_string_view<charT, traits>() const noexcept;
211
+ constexpr allocator_type get_allocator() const noexcept;
212
 
213
+ template<class T>
214
+ constexpr size_type find(const T& t, size_type pos = 0) const noexcept(see below);
215
+ constexpr size_type find(const basic_string& str, size_type pos = 0) const noexcept;
216
+ constexpr size_type find(const charT* s, size_type pos, size_type n) const;
217
+ constexpr size_type find(const charT* s, size_type pos = 0) const;
218
+ constexpr size_type find(charT c, size_type pos = 0) const noexcept;
219
+ template<class T>
220
+ constexpr size_type rfind(const T& t, size_type pos = npos) const noexcept(see below);
221
+ constexpr size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
222
+ constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
223
+ constexpr size_type rfind(const charT* s, size_type pos = npos) const;
224
+ constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
225
 
226
+ template<class T>
227
+ constexpr size_type find_first_of(const T& t, size_type pos = 0) const noexcept(see below);
228
+ constexpr size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
229
+ constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
230
+ constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
231
+ constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
232
+ template<class T>
233
+ constexpr size_type find_last_of(const T& t,
234
+ size_type pos = npos) const noexcept(see below);
235
+ constexpr size_type find_last_of(const basic_string& str,
 
236
  size_type pos = npos) const noexcept;
237
+ constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
238
+ constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
239
+ constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
 
240
 
241
+ template<class T>
242
+ constexpr size_type find_first_not_of(const T& t,
243
+ size_type pos = 0) const noexcept(see below);
244
+ constexpr size_type find_first_not_of(const basic_string& str,
245
  size_type pos = 0) const noexcept;
246
+ constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
247
+ constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
248
+ constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
249
+ template<class T>
250
+ constexpr size_type find_last_not_of(const T& t,
251
+ size_type pos = npos) const noexcept(see below);
252
+ constexpr size_type find_last_not_of(const basic_string& str,
253
  size_type pos = npos) const noexcept;
254
+ constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
255
+ constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
256
+ constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
 
 
257
 
258
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) const;
259
+
260
+ template<class T>
261
+ constexpr int compare(const T& t) const noexcept(see below);
262
  template<class T>
263
+ constexpr int compare(size_type pos1, size_type n1, const T& t) const;
264
+ template<class T>
265
+ constexpr int compare(size_type pos1, size_type n1, const T& t,
266
  size_type pos2, size_type n2 = npos) const;
267
+ constexpr int compare(const basic_string& str) const noexcept;
268
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const;
269
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str,
 
 
270
  size_type pos2, size_type n2 = npos) const;
271
+ constexpr int compare(const charT* s) const;
272
+ constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
273
+ constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
274
+
275
+ constexpr bool starts_with(basic_string_view<charT, traits> x) const noexcept;
276
+ constexpr bool starts_with(charT x) const noexcept;
277
+ constexpr bool starts_with(const charT* x) const;
278
+ constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept;
279
+ constexpr bool ends_with(charT x) const noexcept;
280
+ constexpr bool ends_with(const charT* x) const;
281
  };
282
 
283
  template<class InputIterator,
284
  class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
285
  basic_string(InputIterator, InputIterator, Allocator = Allocator())
286
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
287
  char_traits<typename iterator_traits<InputIterator>::value_type>,
288
  Allocator>;
289
+
290
+ template<class charT,
291
+ class traits,
292
+ class Allocator = allocator<charT>>
293
+ explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
294
+ -> basic_string<charT, traits, Allocator>;
295
+
296
+ template<class charT,
297
+ class traits,
298
+ class Allocator = allocator<charT>>
299
+ basic_string(basic_string_view<charT, traits>,
300
+ typename see below::size_type, typename see below::size_type,
301
+ const Allocator& = Allocator())
302
+ -> basic_string<charT, traits, Allocator>;
303
  }
304
  ```
305
 
306
+ A `size_type` parameter type in a `basic_string` deduction guide refers
307
+ to the `size_type` member type of the type deduced by the deduction
308
+ guide.
309
+
310
+ #### General requirements <a id="string.require">[[string.require]]</a>
311
 
312
  If any operation would cause `size()` to exceed `max_size()`, that
313
+ operation throws an exception object of type `length_error`.
314
 
315
  If any member function or operator of `basic_string` throws an
316
+ exception, that function or operator has no other effect on the
317
+ `basic_string` object.
318
 
319
  In every specialization `basic_string<charT, traits, Allocator>`, the
320
  type `allocator_traits<Allocator>::value_type` shall name the same type
321
  as `charT`. Every object of type
322
+ `basic_string<charT, traits, Allocator>` uses an object of type
323
  `Allocator` to allocate and free storage for the contained `charT`
324
+ objects as needed. The `Allocator` object used is obtained as described
325
+ in [[container.requirements.general]]. In every specialization
326
+ `basic_string<charT, traits, Allocator>`, the type `traits` shall meet
327
+ the character traits requirements [[char.traits]].
328
+
329
+ [*Note 1*: The program is ill-formed if `traits::char_type` is not the
330
+ same type as `charT`. — *end note*]
331
 
332
  References, pointers, and iterators referring to the elements of a
333
  `basic_string` sequence may be invalidated by the following uses of that
334
  `basic_string` object:
335
 
336
+ - Passing as an argument to any standard library function taking a
337
+ reference to non-const `basic_string` as an argument.[^2]
338
  - Calling non-const member functions, except `operator[]`, `at`, `data`,
339
  `front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
340
 
341
+ #### Constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
342
 
343
  ``` cpp
344
+ constexpr explicit basic_string(const Allocator& a) noexcept;
345
  ```
346
 
347
+ *Ensures:* `size()` is equal to `0`.
 
 
 
 
 
 
 
 
 
 
348
 
349
  ``` cpp
350
+ constexpr basic_string(const basic_string& str);
351
+ constexpr basic_string(basic_string&& str) noexcept;
352
  ```
353
 
354
+ *Effects:* Constructs an object whose value is that of `str` prior to
355
+ this call.
 
 
 
356
 
357
+ *Remarks:* In the second form, `str` is left in a valid but unspecified
358
+ state.
 
 
 
359
 
360
  ``` cpp
361
+ constexpr basic_string(const basic_string& str, size_type pos,
362
+ const Allocator& a = Allocator());
363
+ constexpr basic_string(const basic_string& str, size_type pos, size_type n,
364
  const Allocator& a = Allocator());
365
  ```
366
 
367
+ *Effects:* Let `n` be `npos` for the first overload. Equivalent to:
 
 
 
 
368
 
369
  ``` cpp
370
+ basic_string(basic_string_view<charT, traits>(str).substr(pos, n), a)
 
371
  ```
372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  ``` cpp
374
  template<class T>
375
+ constexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
 
376
  ```
377
 
378
+ *Constraints:*
379
+ `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
380
+ `true`.
381
+
382
  *Effects:* Creates a variable, `sv`, as if by
383
  `basic_string_view<charT, traits> sv = t;` and then behaves the same as:
384
 
385
  ``` cpp
386
  basic_string(sv.substr(pos, n), a);
387
  ```
388
 
 
 
 
 
389
  ``` cpp
390
+ template<class T>
391
+ constexpr explicit basic_string(const T& t, const Allocator& a = Allocator());
392
  ```
393
 
394
+ *Constraints:*
395
+
396
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
397
+ `true` and
398
+ - `is_convertible_v<const T&, const charT*>` is `false`.
399
+
400
+ *Effects:* Creates a variable, `sv`, as if by
401
+ `basic_string_view<charT, traits> sv = t;` and then behaves the same as
402
+ `basic_string(sv.data(), sv.size(), a)`.
403
 
404
  ``` cpp
405
+ constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
 
406
  ```
407
 
408
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
409
 
410
+ *Effects:* Constructs an object whose initial value is the range \[`s`,
411
+ `s + n`).
 
 
412
 
413
+ *Ensures:* `size()` is equal to `n`, and `traits::compare(data(), s, n)`
414
+ is equal to `0`.
 
 
 
 
 
415
 
416
  ``` cpp
417
+ constexpr basic_string(const charT* s, const Allocator& a = Allocator());
418
  ```
419
 
420
+ *Constraints:* `Allocator` is a type that qualifies as an
421
+ allocator [[container.requirements.general]].
 
 
 
 
 
422
 
423
+ [*Note 1*: This affects class template argument
424
+ deduction. — *end note*]
425
 
426
+ *Effects:* Equivalent to: `basic_string(s, traits::length(s), a)`.
 
 
 
 
427
 
428
  ``` cpp
429
+ constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
430
  ```
431
 
432
+ *Constraints:* `Allocator` is a type that qualifies as an
433
+ allocator [[container.requirements.general]].
 
 
 
434
 
435
+ [*Note 2*: This affects class template argument
436
+ deduction. — *end note*]
437
 
438
+ *Effects:* Constructs an object whose value consists of `n` copies of
439
+ `c`.
 
 
 
440
 
441
  ``` cpp
442
  template<class InputIterator>
443
+ constexpr basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());
 
444
  ```
445
 
446
+ *Constraints:* `InputIterator` is a type that qualifies as an input
447
+ iterator [[container.requirements.general]].
448
 
449
+ *Effects:* Constructs a string from the values in the range \[`begin`,
450
+ `end`), as indicated in [[container.seq.req]].
 
 
 
 
 
451
 
452
  ``` cpp
453
+ constexpr basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
454
  ```
455
 
456
+ *Effects:* Equivalent to `basic_string(il.begin(), il.end(), a)`.
457
 
458
  ``` cpp
459
+ constexpr basic_string(const basic_string& str, const Allocator& alloc);
460
+ constexpr basic_string(basic_string&& str, const Allocator& alloc);
461
  ```
462
 
463
+ *Effects:* Constructs an object whose value is that of `str` prior to
464
+ this call. The stored allocator is constructed from `alloc`. In the
465
+ second form, `str` is left in a valid but unspecified state.
 
 
 
 
 
 
 
 
 
 
 
 
466
 
467
  *Throws:* The second form throws nothing if
468
  `alloc == str.get_allocator()`.
469
 
470
  ``` cpp
 
474
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
475
  char_traits<typename iterator_traits<InputIterator>::value_type>,
476
  Allocator>;
477
  ```
478
 
479
+ *Constraints:* `InputIterator` is a type that qualifies as an input
480
+ iterator, and `Allocator` is a type that qualifies as an
481
+ allocator [[container.requirements.general]].
 
482
 
483
  ``` cpp
484
+ template<class charT,
485
+ class traits,
486
+ class Allocator = allocator<charT>>
487
+ explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
488
+ -> basic_string<charT, traits, Allocator>;
489
+
490
+ template<class charT,
491
+ class traits,
492
+ class Allocator = allocator<charT>>
493
+ basic_string(basic_string_view<charT, traits>,
494
+ typename see below::size_type, typename see below::size_type,
495
+ const Allocator& = Allocator())
496
+ -> basic_string<charT, traits, Allocator>;
497
  ```
498
 
499
+ *Constraints:* `Allocator` is a type that qualifies as an
500
+ allocator [[container.requirements.general]].
501
+
502
+ ``` cpp
503
+ constexpr basic_string& operator=(const basic_string& str);
504
+ ```
505
 
506
+ *Effects:* If `*this` and `str` are the same object, has no effect.
507
+ Otherwise, replaces the value of `*this` with a copy of `str`.
508
 
509
  *Returns:* `*this`.
510
 
 
 
 
 
 
 
 
 
511
  ``` cpp
512
+ constexpr basic_string& operator=(basic_string&& str)
513
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
514
  allocator_traits<Allocator>::is_always_equal::value);
515
  ```
516
 
517
  *Effects:* Move assigns as a sequence
518
+ container [[container.requirements]], except that iterators, pointers
519
  and references may be invalidated.
520
 
521
  *Returns:* `*this`.
522
 
523
  ``` cpp
524
+ template<class T>
525
+ constexpr basic_string& operator=(const T& t);
526
  ```
527
 
528
+ *Constraints:*
529
+
530
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
531
+ `true` and
532
+ - `is_convertible_v<const T&, const charT*>` is `false`.
533
+
534
+ *Effects:* Equivalent to:
535
 
536
  ``` cpp
537
+ basic_string_view<charT, traits> sv = t;
538
+ return assign(sv);
539
  ```
540
 
541
+ ``` cpp
542
+ constexpr basic_string& operator=(const charT* s);
543
+ ```
544
 
545
+ *Effects:* Equivalent to:
546
+ `return *this = basic_string_view<charT, traits>(s);`
547
 
548
  ``` cpp
549
+ constexpr basic_string& operator=(charT c);
550
  ```
551
 
552
+ *Effects:* Equivalent to:
553
 
554
  ``` cpp
555
+ return *this = basic_string_view<charT, traits>(addressof(c), 1);
556
  ```
557
 
558
+ ``` cpp
559
+ constexpr basic_string& operator=(initializer_list<charT> il);
560
+ ```
561
+
562
+ *Effects:* Equivalent to:
563
 
564
+ ``` cpp
565
+ return *this = basic_string_view<charT, traits>(il.begin(), il.size());
566
+ ```
567
 
568
+ #### Iterator support <a id="string.iterators">[[string.iterators]]</a>
569
 
570
  ``` cpp
571
+ constexpr iterator begin() noexcept;
572
+ constexpr const_iterator begin() const noexcept;
573
+ constexpr const_iterator cbegin() const noexcept;
574
  ```
575
 
576
  *Returns:* An iterator referring to the first character in the string.
577
 
578
  ``` cpp
579
+ constexpr iterator end() noexcept;
580
+ constexpr const_iterator end() const noexcept;
581
+ constexpr const_iterator cend() const noexcept;
582
  ```
583
 
584
  *Returns:* An iterator which is the past-the-end value.
585
 
586
  ``` cpp
587
+ constexpr reverse_iterator rbegin() noexcept;
588
+ constexpr const_reverse_iterator rbegin() const noexcept;
589
+ constexpr const_reverse_iterator crbegin() const noexcept;
590
  ```
591
 
592
  *Returns:* An iterator which is semantically equivalent to
593
  `reverse_iterator(end())`.
594
 
595
  ``` cpp
596
+ constexpr reverse_iterator rend() noexcept;
597
+ constexpr const_reverse_iterator rend() const noexcept;
598
+ constexpr const_reverse_iterator crend() const noexcept;
599
  ```
600
 
601
  *Returns:* An iterator which is semantically equivalent to
602
  `reverse_iterator(begin())`.
603
 
604
+ #### Capacity <a id="string.capacity">[[string.capacity]]</a>
605
 
606
  ``` cpp
607
+ constexpr size_type size() const noexcept;
608
+ constexpr size_type length() const noexcept;
609
  ```
610
 
611
  *Returns:* A count of the number of char-like objects currently in the
612
  string.
613
 
614
  *Complexity:* Constant time.
615
 
616
  ``` cpp
617
+ constexpr size_type max_size() const noexcept;
 
 
 
 
 
 
618
  ```
619
 
620
  *Returns:* The largest possible number of char-like objects that can be
621
  stored in a `basic_string`.
622
 
623
  *Complexity:* Constant time.
624
 
625
  ``` cpp
626
+ constexpr void resize(size_type n, charT c);
627
  ```
628
 
629
+ *Effects:* Alters the value of `*this` as follows:
630
 
631
+ - If `n <= size()`, erases the last `size() - n` elements.
632
+ - If `n > size()`, appends `n - size()` copies of `c`.
 
 
 
 
 
 
 
 
633
 
634
  ``` cpp
635
+ constexpr void resize(size_type n);
636
  ```
637
 
638
+ *Effects:* Equivalent to `resize(n, charT())`.
639
 
640
  ``` cpp
641
+ constexpr size_type capacity() const noexcept;
642
  ```
643
 
644
  *Returns:* The size of the allocated storage in the string.
645
 
646
+ *Complexity:* Constant time.
647
+
648
  ``` cpp
649
+ constexpr void reserve(size_type res_arg);
650
  ```
651
 
652
+ *Effects:* A directive that informs a `basic_string` of a planned change
653
+ in size, so that the storage allocation can be managed accordingly.
654
+ After `reserve()`, `capacity()` is greater or equal to the argument of
655
+ `reserve` if reallocation happens; and equal to the previous value of
656
+ `capacity()` otherwise. Reallocation happens at this point if and only
657
+ if the current capacity is less than the argument of `reserve()`.
658
 
659
+ *Throws:* `length_error` if `res_arg > max_size()` or any exceptions
660
+ thrown by `allocator_traits` `<Allocator>::allocate`.
 
 
 
 
 
 
 
661
 
662
  ``` cpp
663
+ constexpr void shrink_to_fit();
664
  ```
665
 
666
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
667
  `capacity()` to `size()`.
668
 
669
+ [*Note 1*: The request is non-binding to allow latitude for
670
  implementation-specific optimizations. — *end note*]
671
 
672
  It does not increase `capacity()`, but may reduce `capacity()` by
673
  causing reallocation.
674
 
675
+ *Complexity:* If the size is not equal to the old capacity, linear in
676
+ the size of the sequence; otherwise constant.
677
 
678
  *Remarks:* Reallocation invalidates all the references, pointers, and
679
+ iterators referring to the elements in the sequence, as well as the
680
+ past-the-end iterator.
681
 
682
+ [*Note 2*: If no reallocation happens, they remain
683
+ valid. *end note*]
 
 
 
684
 
685
  ``` cpp
686
+ constexpr void clear() noexcept;
687
  ```
688
 
689
+ *Effects:* Equivalent to: `erase(begin(), end());`
690
+
691
  ``` cpp
692
+ [[nodiscard]] constexpr bool empty() const noexcept;
693
  ```
694
 
695
+ *Effects:* Equivalent to: `return size() == 0;`
696
 
697
+ #### Element access <a id="string.access">[[string.access]]</a>
698
 
699
  ``` cpp
700
+ constexpr const_reference operator[](size_type pos) const;
701
+ constexpr reference operator[](size_type pos);
702
  ```
703
 
704
+ *Preconditions:* `pos <= size()`.
705
 
706
  *Returns:* `*(begin() + pos)` if `pos < size()`. Otherwise, returns a
707
  reference to an object of type `charT` with value `charT()`, where
708
  modifying the object to any value other than `charT()` leads to
709
  undefined behavior.
 
711
  *Throws:* Nothing.
712
 
713
  *Complexity:* Constant time.
714
 
715
  ``` cpp
716
+ constexpr const_reference at(size_type pos) const;
717
+ constexpr reference at(size_type pos);
718
  ```
719
 
720
  *Throws:* `out_of_range` if `pos >= size()`.
721
 
722
  *Returns:* `operator[](pos)`.
723
 
724
  ``` cpp
725
+ constexpr const charT& front() const;
726
+ constexpr charT& front();
727
  ```
728
 
729
+ *Preconditions:* `!empty()`.
730
 
731
  *Effects:* Equivalent to: `return operator[](0);`
732
 
733
  ``` cpp
734
+ constexpr const charT& back() const;
735
+ constexpr charT& back();
736
  ```
737
 
738
+ *Preconditions:* `!empty()`.
739
 
740
  *Effects:* Equivalent to: `return operator[](size() - 1);`
741
 
742
+ #### Modifiers <a id="string.modifiers">[[string.modifiers]]</a>
743
 
744
+ ##### `basic_string::operator+=` <a id="string.op.append">[[string.op.append]]</a>
745
 
746
  ``` cpp
747
+ constexpr basic_string& operator+=(const basic_string& str);
 
748
  ```
749
 
750
+ *Effects:* Equivalent to: `return append(str);`
 
 
751
 
752
  ``` cpp
753
+ template<class T>
754
+ constexpr basic_string& operator+=(const T& t);
755
  ```
756
 
757
+ *Constraints:*
758
+
759
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
760
+ `true` and
761
+ - `is_convertible_v<const T&, const charT*>` is `false`.
762
 
763
+ *Effects:* Equivalent to:
764
 
765
  ``` cpp
766
+ basic_string_view<charT, traits> sv = t;
767
+ return append(sv);
768
  ```
769
 
770
+ ``` cpp
771
+ constexpr basic_string& operator+=(const charT* s);
772
+ ```
773
 
774
+ *Effects:* Equivalent to: `return append(s);`
775
 
776
  ``` cpp
777
+ constexpr basic_string& operator+=(charT c);
778
  ```
779
 
780
+ *Effects:* Equivalent to: `return append(size_type{1}, c);`
 
 
781
 
782
  ``` cpp
783
+ constexpr basic_string& operator+=(initializer_list<charT> il);
784
  ```
785
 
786
+ *Effects:* Equivalent to: `return append(il);`
 
 
787
 
788
  ##### `basic_string::append` <a id="string.append">[[string.append]]</a>
789
 
790
  ``` cpp
791
+ constexpr basic_string& append(const basic_string& str);
 
792
  ```
793
 
794
+ *Effects:* Equivalent to: `return append(str.data(), str.size());`
 
 
795
 
796
  ``` cpp
797
+ constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
 
798
  ```
799
 
800
+ *Effects:* Equivalent to:
 
 
 
 
 
 
801
 
802
  ``` cpp
803
+ return append(basic_string_view<charT, traits>(str).substr(pos, n));
804
  ```
805
 
 
 
806
  ``` cpp
807
  template<class T>
808
+ constexpr basic_string& append(const T& t);
809
  ```
810
 
811
+ *Constraints:*
812
 
813
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
814
+ `true` and
815
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
816
 
817
+ *Effects:* Equivalent to:
 
 
818
 
819
+ ``` cpp
820
+ basic_string_view<charT, traits> sv = t;
821
+ return append(sv.data(), sv.size());
822
+ ```
823
 
824
  ``` cpp
825
+ template<class T>
826
+ constexpr basic_string& append(const T& t, size_type pos, size_type n = npos);
827
  ```
828
 
829
+ *Constraints:*
830
 
831
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
832
+ `true` and
833
+ - `is_convertible_v<const T&, const charT*>` is `false`.
834
 
835
+ *Effects:* Equivalent to:
 
 
 
836
 
837
+ ``` cpp
838
+ basic_string_view<charT, traits> sv = t;
839
+ return append(sv.substr(pos, n));
840
+ ```
841
 
842
  ``` cpp
843
+ constexpr basic_string& append(const charT* s, size_type n);
844
  ```
845
 
846
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
 
847
 
848
+ *Effects:* Appends a copy of the range \[`s`, `s + n`) to the string.
849
 
850
  *Returns:* `*this`.
851
 
852
  ``` cpp
853
+ constexpr basic_string& append(const charT* s);
854
+ ```
855
+
856
+ *Effects:* Equivalent to: `return append(s, traits::length(s));`
857
+
858
+ ``` cpp
859
+ constexpr basic_string& append(size_type n, charT c);
860
  ```
861
 
862
+ *Effects:* Appends `n` copies of `c` to the string.
863
 
864
  *Returns:* `*this`.
865
 
866
  ``` cpp
867
  template<class InputIterator>
868
+ constexpr basic_string& append(InputIterator first, InputIterator last);
869
  ```
870
 
871
+ *Constraints:* `InputIterator` is a type that qualifies as an input
872
+ iterator [[container.requirements.general]].
873
 
874
+ *Effects:* Equivalent to:
875
+ `return append(basic_string(first, last, get_allocator()));`
 
 
876
 
877
  ``` cpp
878
+ constexpr basic_string& append(initializer_list<charT> il);
879
  ```
880
 
881
+ *Effects:* Equivalent to: `return append(il.begin(), il.size());`
 
 
882
 
883
  ``` cpp
884
+ constexpr void push_back(charT c);
885
  ```
886
 
887
+ *Effects:* Equivalent to `append(size_type{1}, c)`.
888
 
889
  ##### `basic_string::assign` <a id="string.assign">[[string.assign]]</a>
890
 
891
  ``` cpp
892
+ constexpr basic_string& assign(const basic_string& str);
893
  ```
894
 
895
+ *Effects:* Equivalent to: `return *this = str;`
 
 
896
 
897
  ``` cpp
898
+ constexpr basic_string& assign(basic_string&& str)
899
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
900
  allocator_traits<Allocator>::is_always_equal::value);
901
  ```
902
 
903
+ *Effects:* Equivalent to: `return *this = std::move(str);`
 
 
904
 
905
  ``` cpp
906
+ constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
 
 
907
  ```
908
 
909
+ *Effects:* Equivalent to:
 
 
 
 
 
 
910
 
911
  ``` cpp
912
+ return assign(basic_string_view<charT, traits>(str).substr(pos, n));
913
  ```
914
 
 
 
915
  ``` cpp
916
  template<class T>
917
+ constexpr basic_string& assign(const T& t);
918
  ```
919
 
920
+ *Constraints:*
921
 
922
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
923
+ `true` and
924
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
925
 
926
+ *Effects:* Equivalent to:
 
 
927
 
928
+ ``` cpp
929
+ basic_string_view<charT, traits> sv = t;
930
+ return assign(sv.data(), sv.size());
931
+ ```
932
 
933
  ``` cpp
934
+ template<class T>
935
+ constexpr basic_string& assign(const T& t, size_type pos, size_type n = npos);
936
  ```
937
 
938
+ *Constraints:*
939
 
940
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
941
+ `true` and
942
+ - `is_convertible_v<const T&, const charT*>` is `false`.
943
 
944
+ *Effects:* Equivalent to:
 
945
 
946
+ ``` cpp
947
+ basic_string_view<charT, traits> sv = t;
948
+ return assign(sv.substr(pos, n));
949
+ ```
950
 
951
  ``` cpp
952
+ constexpr basic_string& assign(const charT* s, size_type n);
953
  ```
954
 
955
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
 
956
 
957
+ *Effects:* Replaces the string controlled by `*this` with a copy of the
958
+ range \[`s`, `s + n`).
959
 
960
  *Returns:* `*this`.
961
 
962
  ``` cpp
963
+ constexpr basic_string& assign(const charT* s);
964
  ```
965
 
966
+ *Effects:* Equivalent to: `return assign(s, traits::length(s));`
967
 
968
+ ``` cpp
969
+ constexpr basic_string& assign(initializer_list<charT> il);
970
+ ```
971
+
972
+ *Effects:* Equivalent to: `return assign(il.begin(), il.size());`
973
 
974
  ``` cpp
975
+ constexpr basic_string& assign(size_type n, charT c);
976
  ```
977
 
978
+ *Effects:* Equivalent to:
979
 
980
+ ``` cpp
981
+ clear();
982
+ resize(n, c);
983
+ return *this;
984
+ ```
985
 
986
  ``` cpp
987
  template<class InputIterator>
988
+ constexpr basic_string& assign(InputIterator first, InputIterator last);
989
  ```
990
 
991
+ *Constraints:* `InputIterator` is a type that qualifies as an input
992
+ iterator [[container.requirements.general]].
993
 
994
+ *Effects:* Equivalent to:
995
+ `return assign(basic_string(first, last, get_allocator()));`
996
 
997
  ##### `basic_string::insert` <a id="string.insert">[[string.insert]]</a>
998
 
999
  ``` cpp
1000
+ constexpr basic_string& insert(size_type pos, const basic_string& str);
 
 
1001
  ```
1002
 
1003
  *Effects:* Equivalent to: `return insert(pos, str.data(), str.size());`
1004
 
1005
  ``` cpp
1006
+ constexpr basic_string& insert(size_type pos1, const basic_string& str,
 
 
1007
  size_type pos2, size_type n = npos);
1008
  ```
1009
 
1010
+ *Effects:* Equivalent to:
1011
 
1012
+ ``` cpp
1013
+ return insert(pos1, basic_string_view<charT, traits>(str), pos2, n);
1014
+ ```
 
 
1015
 
1016
  ``` cpp
1017
+ template<class T>
1018
+ constexpr basic_string& insert(size_type pos, const T& t);
1019
  ```
1020
 
1021
+ *Constraints:*
1022
+
1023
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1024
+ `true` and
1025
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1026
+
1027
+ *Effects:* Equivalent to:
1028
+
1029
+ ``` cpp
1030
+ basic_string_view<charT, traits> sv = t;
1031
+ return insert(pos, sv.data(), sv.size());
1032
+ ```
1033
 
1034
  ``` cpp
1035
  template<class T>
1036
+ constexpr basic_string& insert(size_type pos1, const T& t,
1037
  size_type pos2, size_type n = npos);
1038
  ```
1039
 
1040
+ *Constraints:*
1041
 
1042
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1043
+ `true` and
1044
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
1045
 
1046
+ *Effects:* Equivalent to:
 
 
1047
 
1048
+ ``` cpp
1049
+ basic_string_view<charT, traits> sv = t;
1050
+ return insert(pos1, sv.substr(pos2, n));
1051
+ ```
1052
 
1053
  ``` cpp
1054
+ constexpr basic_string& insert(size_type pos, const charT* s, size_type n);
 
1055
  ```
1056
 
1057
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
1058
+
1059
+ *Throws:*
1060
 
1061
+ - `out_of_range` if `pos > size()`,
1062
+ - `length_error` if `n > max_size() - size()`, or
1063
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1064
 
1065
+ *Effects:* Inserts a copy of the range \[`s`, `s + n`) immediately
1066
+ before the character at position `pos` if `pos < size()`, or otherwise
1067
+ at the end of the string.
 
 
 
1068
 
1069
  *Returns:* `*this`.
1070
 
1071
  ``` cpp
1072
+ constexpr basic_string& insert(size_type pos, const charT* s);
 
1073
  ```
1074
 
 
 
 
1075
  *Effects:* Equivalent to: `return insert(pos, s, traits::length(s));`
1076
 
1077
  ``` cpp
1078
+ constexpr basic_string& insert(size_type pos, size_type n, charT c);
 
1079
  ```
1080
 
1081
+ *Effects:* Inserts `n` copies of `c` before the character at position
1082
+ `pos` if `pos < size()`, or otherwise at the end of the string.
1083
 
1084
+ *Returns:* `*this`
1085
+
1086
+ *Throws:*
1087
+
1088
+ - `out_of_range` if `pos > size()`,
1089
+ - `length_error` if `n > max_size() - size()`, or
1090
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1091
 
1092
  ``` cpp
1093
+ constexpr iterator insert(const_iterator p, charT c);
1094
  ```
1095
 
1096
+ *Preconditions:* `p` is a valid iterator on `*this`.
1097
 
1098
+ *Effects:* Inserts a copy of `c` at the position `p`.
 
1099
 
1100
+ *Returns:* An iterator which refers to the inserted character.
 
1101
 
1102
  ``` cpp
1103
+ constexpr iterator insert(const_iterator p, size_type n, charT c);
1104
  ```
1105
 
1106
+ *Preconditions:* `p` is a valid iterator on `*this`.
1107
 
1108
+ *Effects:* Inserts `n` copies of `c` at the position `p`.
 
1109
 
1110
+ *Returns:* An iterator which refers to the first inserted character, or
1111
+ `p` if `n == 0`.
1112
 
1113
  ``` cpp
1114
  template<class InputIterator>
1115
+ constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
1116
  ```
1117
 
1118
+ *Constraints:* `InputIterator` is a type that qualifies as an input
1119
+ iterator [[container.requirements.general]].
1120
+
1121
+ *Preconditions:* `p` is a valid iterator on `*this`.
1122
 
1123
  *Effects:* Equivalent to
1124
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
1125
 
1126
+ *Returns:* An iterator which refers to the first inserted character, or
1127
+ `p` if `first == last`.
1128
 
1129
  ``` cpp
1130
+ constexpr iterator insert(const_iterator p, initializer_list<charT> il);
1131
  ```
1132
 
1133
+ *Effects:* Equivalent to: `return insert(p, il.begin(), il.end());`
 
 
 
1134
 
1135
  ##### `basic_string::erase` <a id="string.erase">[[string.erase]]</a>
1136
 
1137
  ``` cpp
1138
+ constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
1139
  ```
1140
 
1141
  *Throws:* `out_of_range` if `pos` `> size()`.
1142
 
1143
  *Effects:* Determines the effective length `xlen` of the string to be
1144
+ removed as the smaller of `n` and `size() - pos`. Removes the characters
1145
+ in the range \[`begin() + pos`, `begin() + pos + xlen`).
 
 
 
 
 
1146
 
1147
  *Returns:* `*this`.
1148
 
1149
  ``` cpp
1150
+ constexpr iterator erase(const_iterator p);
1151
  ```
1152
 
1153
+ *Preconditions:* `p` is a valid dereferenceable iterator on `*this`.
1154
+
1155
  *Throws:* Nothing.
1156
 
1157
  *Effects:* Removes the character referred to by `p`.
1158
 
1159
  *Returns:* An iterator which points to the element immediately following
1160
  `p` prior to the element being erased. If no such element exists,
1161
  `end()` is returned.
1162
 
1163
  ``` cpp
1164
+ constexpr iterator erase(const_iterator first, const_iterator last);
1165
  ```
1166
 
1167
+ *Preconditions:* `first` and `last` are valid iterators on `*this`.
1168
+ \[`first`, `last`) is a valid range.
1169
 
1170
  *Throws:* Nothing.
1171
 
1172
  *Effects:* Removes the characters in the range `[first, last)`.
1173
 
1174
  *Returns:* An iterator which points to the element pointed to by `last`
1175
  prior to the other elements being erased. If no such element exists,
1176
  `end()` is returned.
1177
 
1178
  ``` cpp
1179
+ constexpr void pop_back();
1180
  ```
1181
 
1182
+ *Preconditions:* `!empty()`.
1183
 
1184
  *Throws:* Nothing.
1185
 
1186
+ *Effects:* Equivalent to `erase(end() - 1)`.
1187
 
1188
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
1189
 
1190
  ``` cpp
1191
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
 
 
1192
  ```
1193
 
1194
  *Effects:* Equivalent to:
1195
  `return replace(pos1, n1, str.data(), str.size());`
1196
 
1197
  ``` cpp
1198
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
 
 
1199
  size_type pos2, size_type n2 = npos);
1200
  ```
1201
 
1202
+ *Effects:* Equivalent to:
 
 
 
 
1203
 
1204
+ ``` cpp
1205
+ return replace(pos1, n1, basic_string_view<charT, traits>(str).substr(pos2, n2));
1206
+ ```
1207
 
1208
  ``` cpp
1209
+ template<class T>
1210
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t);
1211
  ```
1212
 
1213
+ *Constraints:*
1214
+
1215
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1216
+ `true` and
1217
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1218
+
1219
  *Effects:* Equivalent to:
1220
+
1221
+ ``` cpp
1222
+ basic_string_view<charT, traits> sv = t;
1223
+ return replace(pos1, n1, sv.data(), sv.size());
1224
+ ```
1225
 
1226
  ``` cpp
1227
  template<class T>
1228
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t,
1229
  size_type pos2, size_type n2 = npos);
1230
  ```
1231
 
1232
+ *Constraints:*
1233
 
1234
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1235
+ `true` and
1236
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
 
1237
 
1238
+ *Effects:* Equivalent to:
 
 
1239
 
1240
+ ``` cpp
1241
+ basic_string_view<charT, traits> sv = t;
1242
+ return replace(pos1, n1, sv.substr(pos2, n2));
1243
+ ```
1244
 
1245
  ``` cpp
1246
+ constexpr basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);
 
1247
  ```
1248
 
1249
+ *Preconditions:* \[`s`, `s + n2`) is a valid range.
1250
+
1251
+ *Throws:*
1252
 
1253
+ - `out_of_range` if `pos1 > size()`,
1254
+ - `length_error` if the length of the resulting string would exceed
1255
+ `max_size()` (see below), or
1256
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1257
 
1258
  *Effects:* Determines the effective length `xlen` of the string to be
1259
  removed as the smaller of `n1` and `size() - pos1`. If
1260
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
1261
+ function replaces the characters in the range \[`begin() + pos1`,
1262
+ `begin() + pos1 + xlen`) with a copy of the range \[`s`, `s + n2`).
 
 
 
 
1263
 
1264
  *Returns:* `*this`.
1265
 
1266
  ``` cpp
1267
+ constexpr basic_string& replace(size_type pos, size_type n, const charT* s);
 
1268
  ```
1269
 
 
 
 
1270
  *Effects:* Equivalent to:
1271
  `return replace(pos, n, s, traits::length(s));`
1272
 
1273
  ``` cpp
1274
+ constexpr basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);
 
 
1275
  ```
1276
 
1277
+ *Throws:*
1278
+
1279
+ - `out_of_range` if `pos1 > size()`,
1280
+ - `length_error` if the length of the resulting string would exceed
1281
+ `max_size()` (see below), or
1282
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate.`
1283
+
1284
+ *Effects:* Determines the effective length `xlen` of the string to be
1285
+ removed as the smaller of `n1` and `size() - pos1`. If
1286
+ `size() - xlen >=` `max_size() - n2` throws `length_error`. Otherwise,
1287
+ the function replaces the characters in the range \[`begin() + pos1`,
1288
+ `begin() + pos1 + xlen`) with `n2` copies of `c`.
1289
 
1290
  *Returns:* `*this`.
1291
 
1292
  ``` cpp
1293
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
1294
  ```
1295
 
1296
+ *Effects:* Equivalent to:
1297
+ `return replace(i1, i2, basic_string_view<charT, traits>(str));`
 
 
 
1298
 
1299
  ``` cpp
1300
+ template<class T>
1301
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t);
1302
  ```
1303
 
1304
+ *Constraints:*
1305
 
1306
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1307
+ `true` and
1308
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1309
 
1310
+ *Preconditions:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1311
+
1312
+ *Effects:* Equivalent to:
1313
 
1314
  ``` cpp
1315
+ basic_string_view<charT, traits> sv = t;
1316
+ return replace(i1 - begin(), i2 - i1, sv.data(), sv.size());
1317
  ```
1318
 
 
 
 
 
 
 
 
1319
  ``` cpp
1320
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
1321
  ```
1322
 
1323
+ *Effects:* Equivalent to:
1324
+ `return replace(i1, i2, basic_string_view<charT, traits>(s, n));`
 
1325
 
1326
+ ``` cpp
1327
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
1328
+ ```
1329
 
1330
+ *Effects:* Equivalent to:
1331
+ `return replace(i1, i2, basic_string_view<charT, traits>(s));`
1332
 
1333
  ``` cpp
1334
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
 
1335
  ```
1336
 
1337
+ *Preconditions:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1338
 
1339
+ *Effects:* Equivalent to: `return replace(i1 - begin(), i2 - i1, n, c);`
 
 
1340
 
1341
  ``` cpp
1342
  template<class InputIterator>
1343
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2,
1344
  InputIterator j1, InputIterator j2);
1345
  ```
1346
 
1347
+ *Constraints:* `InputIterator` is a type that qualifies as an input
1348
+ iterator [[container.requirements.general]].
1349
 
1350
+ *Effects:* Equivalent to:
1351
+ `return replace(i1, i2, basic_string(j1, j2, get_allocator()));`
 
 
1352
 
1353
  ``` cpp
1354
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
 
1355
  ```
1356
 
1357
+ *Effects:* Equivalent to:
1358
+ `return replace(i1, i2, il.begin(), il.size());`
 
 
 
 
1359
 
1360
  ##### `basic_string::copy` <a id="string.copy">[[string.copy]]</a>
1361
 
1362
  ``` cpp
1363
+ constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
1364
  ```
1365
 
1366
+ *Effects:* Equivalent to:
1367
+ `return basic_string_view<charT, traits>(*this).copy(s, n, pos);`
 
 
 
 
 
1368
 
1369
  [*Note 1*: This does not terminate `s` with a null
1370
  object. — *end note*]
1371
 
 
 
1372
  ##### `basic_string::swap` <a id="string.swap">[[string.swap]]</a>
1373
 
1374
  ``` cpp
1375
+ constexpr void swap(basic_string& s)
1376
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1377
  allocator_traits<Allocator>::is_always_equal::value);
1378
  ```
1379
 
1380
+ *Preconditions:*
1381
+ `allocator_traits<Allocator>::propagate_on_container_swap::value` is
1382
+ `true` or `get_allocator() == s.get_allocator()`.
1383
+
1384
+ *Ensures:* `*this` contains the same sequence of characters that was in
1385
+ `s`, `s` contains the same sequence of characters that was in `*this`.
1386
 
1387
  *Throws:* Nothing.
1388
 
1389
  *Complexity:* Constant time.
1390
 
1391
+ #### String operations <a id="string.ops">[[string.ops]]</a>
1392
 
1393
+ ##### Accessors <a id="string.accessors">[[string.accessors]]</a>
1394
 
1395
  ``` cpp
1396
+ constexpr const charT* c_str() const noexcept;
1397
+ constexpr const charT* data() const noexcept;
1398
  ```
1399
 
1400
+ *Returns:* A pointer `p` such that `p + i == addressof(operator[](i))`
1401
+ for each `i` in \[`0`, `size()`\].
1402
 
1403
  *Complexity:* Constant time.
1404
 
1405
+ *Remarks:* The program shall not modify any of the values stored in the
1406
+ character array; otherwise, the behavior is undefined.
1407
 
1408
  ``` cpp
1409
+ constexpr charT* data() noexcept;
1410
  ```
1411
 
1412
+ *Returns:* A pointer `p` such that `p + i == addressof(operator[](i))`
1413
+ for each `i` in \[`0`, `size()`\].
1414
 
1415
  *Complexity:* Constant time.
1416
 
1417
+ *Remarks:* The program shall not modify the value stored at `p + size()`
1418
+ to any value other than `charT()`; otherwise, the behavior is undefined.
1419
 
1420
  ``` cpp
1421
+ constexpr operator basic_string_view<charT, traits>() const noexcept;
1422
  ```
1423
 
1424
  *Effects:* Equivalent to:
1425
  `return basic_string_view<charT, traits>(data(), size());`
1426
 
1427
  ``` cpp
1428
+ constexpr allocator_type get_allocator() const noexcept;
1429
  ```
1430
 
1431
  *Returns:* A copy of the `Allocator` object used to construct the string
1432
  or, if that allocator has been replaced, a copy of the most recent
1433
  replacement.
1434
 
1435
+ ##### Searching <a id="string.find">[[string.find]]</a>
1436
 
1437
+ Let *F* be one of `find`, `rfind`, `find_first_of`, `find_last_of`,
1438
+ `find_first_not_of`, and `find_last_not_of`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1439
 
1440
+ - Each member function of the form
1441
  ``` cpp
1442
+ constexpr size_type F(const basic_string& str, size_type pos) const noexcept;
1443
  ```
1444
 
1445
+ has effects equivalent to:
1446
+ `return F(basic_string_view<charT, traits>(str), pos);`
1447
+ - Each member function of the form
 
 
1448
  ``` cpp
1449
+ constexpr size_type F(const charT* s, size_type pos) const;
1450
  ```
1451
 
1452
+ has effects equivalent to:
1453
+ `return F(basic_string_view<charT, traits>(s), pos);`
1454
+ - Each member function of the form
 
1455
  ``` cpp
1456
+ constexpr size_type F(const charT* s, size_type pos, size_type n) const;
1457
  ```
1458
 
1459
+ has effects equivalent to:
1460
+ `return F(basic_string_view<charT, traits>(s, n), pos);`
1461
+ - Each member function of the form
 
 
 
 
 
 
 
1462
  ``` cpp
1463
+ constexpr size_type F(charT c, size_type pos) const noexcept;
1464
  ```
1465
 
1466
+ has effects equivalent to:
 
 
1467
  ``` cpp
1468
+ return F(basic_string_view<charT, traits>(addressof(c), 1), pos);
1469
  ```
1470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1471
  ``` cpp
1472
+ template<class T>
1473
+ constexpr size_type find(const T& t, size_type pos = 0) const noexcept(see below);
1474
+ template<class T>
1475
+ constexpr size_type rfind(const T& t, size_type pos = npos) const noexcept(see below);
1476
+ template<class T>
1477
+ constexpr size_type find_first_of(const T& t, size_type pos = 0) const noexcept(see below);
1478
+ template<class T>
1479
+ constexpr size_type find_last_of(const T& t, size_type pos = npos) const noexcept(see below);
1480
+ template<class T>
1481
+ constexpr size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept(see below);
1482
+ template<class T>
1483
+ constexpr size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept(see below);
1484
  ```
1485
 
1486
+ *Constraints:*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1487
 
1488
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1489
+ `true` and
1490
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1491
 
1492
+ *Effects:* Let *G* be the name of the function. Equivalent to:
1493
 
1494
  ``` cpp
1495
+ basic_string_view<charT, traits> s = *this, sv = t;
1496
+ return s.G(sv, pos);
1497
  ```
1498
 
1499
+ *Remarks:* The expression inside `noexcept` is equivalent to
1500
+ `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
1501
 
1502
  ##### `basic_string::substr` <a id="string.substr">[[string.substr]]</a>
1503
 
1504
  ``` cpp
1505
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) const;
1506
  ```
1507
 
1508
  *Throws:* `out_of_range` if `pos > size()`.
1509
 
1510
  *Effects:* Determines the effective length `rlen` of the string to copy
 
1513
  *Returns:* `basic_string(data()+pos, rlen)`.
1514
 
1515
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
1516
 
1517
  ``` cpp
1518
+ template<class T>
1519
+ constexpr int compare(const T& t) const noexcept(see below);
1520
  ```
1521
 
1522
+ *Constraints:*
 
 
 
1523
 
1524
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1525
+ `true` and
1526
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1527
 
1528
+ *Effects:* Equivalent to:
1529
+ `return basic_string_view<charT, traits>(*this).compare(t);`
1530
 
1531
+ *Remarks:* The expression inside `noexcept` is equivalent to
1532
+ `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
 
 
 
1533
 
1534
  ``` cpp
1535
+ template<class T>
1536
+ constexpr int compare(size_type pos1, size_type n1, const T& t) const;
1537
  ```
1538
 
1539
+ *Constraints:*
1540
+
1541
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1542
+ `true` and
1543
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1544
+
1545
  *Effects:* Equivalent to:
1546
 
1547
  ``` cpp
1548
+ return basic_string_view<charT, traits>(*this).substr(pos1, n1).compare(t);
1549
  ```
1550
 
1551
  ``` cpp
1552
  template<class T>
1553
+ constexpr int compare(size_type pos1, size_type n1, const T& t,
1554
  size_type pos2, size_type n2 = npos) const;
1555
  ```
1556
 
1557
+ *Constraints:*
1558
+
1559
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1560
+ `true` and
1561
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1562
+
1563
  *Effects:* Equivalent to:
1564
 
1565
  ``` cpp
1566
+ basic_string_view<charT, traits> s = *this, sv = t;
1567
+ return s.substr(pos1, n1).compare(sv.substr(pos2, n2));
 
1568
  ```
1569
 
 
 
 
 
1570
  ``` cpp
1571
+ constexpr int compare(const basic_string& str) const noexcept;
1572
  ```
1573
 
1574
  *Effects:* Equivalent to:
1575
  `return compare(basic_string_view<charT, traits>(str));`
1576
 
1577
  ``` cpp
1578
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const;
1579
  ```
1580
 
1581
  *Effects:* Equivalent to:
1582
  `return compare(pos1, n1, basic_string_view<charT, traits>(str));`
1583
 
1584
  ``` cpp
1585
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str,
 
1586
  size_type pos2, size_type n2 = npos) const;
1587
  ```
1588
 
1589
  *Effects:* Equivalent to:
1590
 
1591
  ``` cpp
1592
  return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);
1593
  ```
1594
 
1595
  ``` cpp
1596
+ constexpr int compare(const charT* s) const;
1597
  ```
1598
 
1599
+ *Effects:* Equivalent to:
1600
+ `return compare(basic_string_view<charT, traits>(s));`
1601
 
1602
  ``` cpp
1603
+ constexpr int compare(size_type pos, size_type n1, const charT* s) const;
1604
  ```
1605
 
1606
+ *Effects:* Equivalent to:
1607
+ `return compare(pos, n1, basic_string_view<charT, traits>(s));`
1608
 
1609
  ``` cpp
1610
+ constexpr int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
1611
  ```
1612
 
1613
+ *Effects:* Equivalent to:
1614
+ `return compare(pos, n1, basic_string_view<charT, traits>(s, n2));`
1615
+
1616
+ ##### `basic_string::starts_with` <a id="string.starts.with">[[string.starts.with]]</a>
1617
+
1618
+ ``` cpp
1619
+ constexpr bool starts_with(basic_string_view<charT, traits> x) const noexcept;
1620
+ constexpr bool starts_with(charT x) const noexcept;
1621
+ constexpr bool starts_with(const charT* x) const;
1622
+ ```
1623
+
1624
+ *Effects:* Equivalent to:
1625
+
1626
+ ``` cpp
1627
+ return basic_string_view<charT, traits>(data(), size()).starts_with(x);
1628
+ ```
1629
+
1630
+ ##### `basic_string::ends_with` <a id="string.ends.with">[[string.ends.with]]</a>
1631
+
1632
+ ``` cpp
1633
+ constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept;
1634
+ constexpr bool ends_with(charT x) const noexcept;
1635
+ constexpr bool ends_with(const charT* x) const;
1636
+ ```
1637
+
1638
+ *Effects:* Equivalent to:
1639
+
1640
+ ``` cpp
1641
+ return basic_string_view<charT, traits>(data(), size()).ends_with(x);
1642
+ ```
1643