From Jason Turner

[string.classes]

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

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpbehb9c8q/{from.md → to.md} +1032 -1360
tmp/tmpbehb9c8q/{from.md → to.md} RENAMED
@@ -1,136 +1,101 @@
1
  ## String classes <a id="string.classes">[[string.classes]]</a>
2
 
3
  The header `<string>` defines the `basic_string` class template for
4
- manipulating varying-length sequences of char-like objects and four
5
- *typedef-name*s, `string`, `u16string`, `u32string`, and `wstring`, that
6
- name the specializations `basic_string<char>`, `basic_string<char16_t>`,
 
7
  `basic_string<char32_t>`, and `basic_string<{}wchar_t>`, respectively.
8
 
9
  ### Header `<string>` synopsis <a id="string.syn">[[string.syn]]</a>
10
 
11
  ``` cpp
12
- #include <initializer_list>
 
13
 
14
  namespace std {
15
  // [char.traits], character traits
16
  template<class charT> struct char_traits;
17
  template<> struct char_traits<char>;
 
18
  template<> struct char_traits<char16_t>;
19
  template<> struct char_traits<char32_t>;
20
  template<> struct char_traits<wchar_t>;
21
 
22
  // [basic.string], basic_string
23
- template<class charT, class traits = char_traits<charT>,
24
- class Allocator = allocator<charT>>
25
  class basic_string;
26
 
27
  template<class charT, class traits, class Allocator>
28
- basic_string<charT, traits, Allocator>
29
  operator+(const basic_string<charT, traits, Allocator>& lhs,
30
  const basic_string<charT, traits, Allocator>& rhs);
31
  template<class charT, class traits, class Allocator>
32
- basic_string<charT, traits, Allocator>
33
  operator+(basic_string<charT, traits, Allocator>&& lhs,
34
  const basic_string<charT, traits, Allocator>& rhs);
35
  template<class charT, class traits, class Allocator>
36
- basic_string<charT, traits, Allocator>
37
  operator+(const basic_string<charT, traits, Allocator>& lhs,
38
  basic_string<charT, traits, Allocator>&& rhs);
39
  template<class charT, class traits, class Allocator>
40
- basic_string<charT, traits, Allocator>
41
  operator+(basic_string<charT, traits, Allocator>&& lhs,
42
  basic_string<charT, traits, Allocator>&& rhs);
43
  template<class charT, class traits, class Allocator>
44
- basic_string<charT, traits, Allocator>
45
  operator+(const charT* lhs,
46
  const basic_string<charT, traits, Allocator>& rhs);
47
  template<class charT, class traits, class Allocator>
48
- basic_string<charT, traits, Allocator>
49
  operator+(const charT* lhs,
50
  basic_string<charT, traits, Allocator>&& rhs);
51
  template<class charT, class traits, class Allocator>
52
- basic_string<charT, traits, Allocator>
53
- operator+(charT lhs, const basic_string<charT, traits, Allocator>& rhs);
 
54
  template<class charT, class traits, class Allocator>
55
- basic_string<charT, traits, Allocator>
56
- operator+(charT lhs, basic_string<charT, traits, Allocator>&& rhs);
 
57
  template<class charT, class traits, class Allocator>
58
- basic_string<charT, traits, Allocator>
59
  operator+(const basic_string<charT, traits, Allocator>& lhs,
60
  const charT* rhs);
61
  template<class charT, class traits, class Allocator>
62
- basic_string<charT, traits, Allocator>
63
  operator+(basic_string<charT, traits, Allocator>&& lhs,
64
  const charT* rhs);
65
  template<class charT, class traits, class Allocator>
66
- basic_string<charT, traits, Allocator>
67
- operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
 
68
  template<class charT, class traits, class Allocator>
69
- basic_string<charT, traits, Allocator>
70
- operator+(basic_string<charT, traits, Allocator>&& lhs, charT rhs);
 
71
 
72
  template<class charT, class traits, class Allocator>
73
- bool operator==(const basic_string<charT, traits, Allocator>& lhs,
74
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
75
- template<class charT, class traits, class Allocator>
76
- bool operator==(const charT* lhs,
77
- const basic_string<charT, traits, Allocator>& rhs);
78
- template<class charT, class traits, class Allocator>
79
- bool operator==(const basic_string<charT, traits, Allocator>& lhs,
80
- const charT* rhs);
81
- template<class charT, class traits, class Allocator>
82
- bool operator!=(const basic_string<charT, traits, Allocator>& lhs,
83
  const basic_string<charT, traits, Allocator>& rhs) noexcept;
84
  template<class charT, class traits, class Allocator>
85
- bool operator!=(const charT* lhs,
86
- const basic_string<charT, traits, Allocator>& rhs);
87
- template<class charT, class traits, class Allocator>
88
- bool operator!=(const basic_string<charT, traits, Allocator>& lhs,
89
  const charT* rhs);
90
 
91
  template<class charT, class traits, class Allocator>
92
- bool operator< (const basic_string<charT, traits, Allocator>& lhs,
93
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
94
  template<class charT, class traits, class Allocator>
95
- bool operator< (const basic_string<charT, traits, Allocator>& lhs,
96
- const charT* rhs);
97
- template<class charT, class traits, class Allocator>
98
- bool operator< (const charT* lhs,
99
- const basic_string<charT, traits, Allocator>& rhs);
100
- template<class charT, class traits, class Allocator>
101
- bool operator> (const basic_string<charT, traits, Allocator>& lhs,
102
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
103
- template<class charT, class traits, class Allocator>
104
- bool operator> (const basic_string<charT, traits, Allocator>& lhs,
105
- const charT* rhs);
106
- template<class charT, class traits, class Allocator>
107
- bool operator> (const charT* lhs,
108
- const basic_string<charT, traits, Allocator>& rhs);
109
-
110
- template<class charT, class traits, class Allocator>
111
- bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
112
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
113
- template<class charT, class traits, class Allocator>
114
- bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
115
- const charT* rhs);
116
- template<class charT, class traits, class Allocator>
117
- bool operator<=(const charT* lhs,
118
- const basic_string<charT, traits, Allocator>& rhs);
119
- template<class charT, class traits, class Allocator>
120
- bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
121
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
122
- template<class charT, class traits, class Allocator>
123
- bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
124
- const charT* rhs);
125
- template<class charT, class traits, class Allocator>
126
- bool operator>=(const charT* lhs,
127
- const basic_string<charT, traits, Allocator>& rhs);
128
 
129
  // [string.special], swap
130
  template<class charT, class traits, class Allocator>
131
- void swap(basic_string<charT, traits, Allocator>& lhs,
 
132
  basic_string<charT, traits, Allocator>& rhs)
133
  noexcept(noexcept(lhs.swap(rhs)));
134
 
135
  // [string.io], inserters and extractors
136
  template<class charT, class traits, class Allocator>
@@ -158,78 +123,94 @@ namespace std {
158
  template<class charT, class traits, class Allocator>
159
  basic_istream<charT, traits>&
160
  getline(basic_istream<charT, traits>&& is,
161
  basic_string<charT, traits, Allocator>& str);
162
 
 
 
 
 
 
 
 
 
163
  // basic_string typedef names
164
  using string = basic_string<char>;
 
165
  using u16string = basic_string<char16_t>;
166
  using u32string = basic_string<char32_t>;
167
  using wstring = basic_string<wchar_t>;
168
 
169
  // [string.conversions], numeric conversions
170
- int stoi(const string& str, size_t* idx = 0, int base = 10);
171
- long stol(const string& str, size_t* idx = 0, int base = 10);
172
- unsigned long stoul(const string& str, size_t* idx = 0, int base = 10);
173
- long long stoll(const string& str, size_t* idx = 0, int base = 10);
174
- unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
175
- float stof(const string& str, size_t* idx = 0);
176
- double stod(const string& str, size_t* idx = 0);
177
- long double stold(const string& str, size_t* idx = 0);
178
  string to_string(int val);
179
  string to_string(unsigned val);
180
  string to_string(long val);
181
  string to_string(unsigned long val);
182
  string to_string(long long val);
183
  string to_string(unsigned long long val);
184
  string to_string(float val);
185
  string to_string(double val);
186
  string to_string(long double val);
187
 
188
- int stoi(const wstring& str, size_t* idx = 0, int base = 10);
189
- long stol(const wstring& str, size_t* idx = 0, int base = 10);
190
- unsigned long stoul(const wstring& str, size_t* idx = 0, int base = 10);
191
- long long stoll(const wstring& str, size_t* idx = 0, int base = 10);
192
- unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
193
- float stof(const wstring& str, size_t* idx = 0);
194
- double stod(const wstring& str, size_t* idx = 0);
195
- long double stold(const wstring& str, size_t* idx = 0);
196
  wstring to_wstring(int val);
197
  wstring to_wstring(unsigned val);
198
  wstring to_wstring(long val);
199
  wstring to_wstring(unsigned long val);
200
  wstring to_wstring(long long val);
201
  wstring to_wstring(unsigned long long val);
202
  wstring to_wstring(float val);
203
  wstring to_wstring(double val);
204
  wstring to_wstring(long double val);
205
 
206
- // [basic.string.hash], hash support
207
- template<class T> struct hash;
208
- template<> struct hash<string>;
209
- template<> struct hash<u16string>;
210
- template<> struct hash<u32string>;
211
- template<> struct hash<wstring>;
212
-
213
  namespace pmr {
214
  template<class charT, class traits = char_traits<charT>>
215
- using basic_string =
216
- std::basic_string<charT, traits, polymorphic_allocator<charT>>;
217
 
218
  using string = basic_string<char>;
 
219
  using u16string = basic_string<char16_t>;
220
  using u32string = basic_string<char32_t>;
221
  using wstring = basic_string<wchar_t>;
222
  }
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  inline namespace literals {
225
  inline namespace string_literals {
226
  // [basic.string.literals], suffix for basic_string literals
227
- string operator""s(const char* str, size_t len);
228
- u16string operator""s(const char16_t* str, size_t len);
229
- u32string operator""s(const char32_t* str, size_t len);
230
- wstring operator""s(const wchar_t* str, size_t len);
 
231
  }
232
  }
233
  }
234
  ```
235
 
@@ -241,34 +222,24 @@ with the first element of the sequence at position zero. Such a sequence
241
  is also called a “string” if the type of the char-like objects that it
242
  holds is clear from context. In the rest of this Clause, the type of the
243
  char-like objects held in a `basic_string` object is designated by
244
  `charT`.
245
 
246
- The member functions of `basic_string` use an object of the `Allocator`
247
- class passed as a template parameter to allocate and free storage for
248
- the contained char-like objects.[^2]
249
 
250
- A `basic_string` is a contiguous container (
251
- [[container.requirements.general]]).
252
-
253
- In all cases, `size() <= capacity()`.
254
-
255
- The functions described in this Clause can report two kinds of errors,
256
- each associated with an exception type:
257
-
258
- - a *length* error is associated with exceptions of type
259
- `length_error` ([[length.error]]);
260
- - an *out-of-range* error is associated with exceptions of type
261
- `out_of_range` ([[out.of.range]]).
262
 
263
  ``` cpp
264
  namespace std {
265
  template<class charT, class traits = char_traits<charT>,
266
  class Allocator = allocator<charT>>
267
  class basic_string {
268
  public:
269
- // types:
270
  using traits_type = traits;
271
  using value_type = charT;
272
  using allocator_type = Allocator;
273
  using size_type = typename allocator_traits<Allocator>::size_type;
274
  using difference_type = typename allocator_traits<Allocator>::difference_type;
@@ -282,479 +253,434 @@ namespace std {
282
  using reverse_iterator = std::reverse_iterator<iterator>;
283
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
284
  static const size_type npos = -1;
285
 
286
  // [string.cons], construct/copy/destroy
287
- basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }
288
- explicit basic_string(const Allocator& a) noexcept;
289
- basic_string(const basic_string& str);
290
- basic_string(basic_string&& str) noexcept;
291
- basic_string(const basic_string& str, size_type pos,
292
  const Allocator& a = Allocator());
293
- basic_string(const basic_string& str, size_type pos, size_type n,
294
  const Allocator& a = Allocator());
295
  template<class T>
296
- basic_string(const T& t, size_type pos, size_type n,
297
  const Allocator& a = Allocator());
298
- explicit basic_string(basic_string_view<charT, traits> sv,
299
- const Allocator& a = Allocator());
300
- basic_string(const charT* s,
301
- size_type n, const Allocator& a = Allocator());
302
- basic_string(const charT* s, const Allocator& a = Allocator());
303
- basic_string(size_type n, charT c, const Allocator& a = Allocator());
304
  template<class InputIterator>
305
- basic_string(InputIterator begin, InputIterator end,
306
  const Allocator& a = Allocator());
307
- basic_string(initializer_list<charT>, const Allocator& = Allocator());
308
- basic_string(const basic_string&, const Allocator&);
309
- basic_string(basic_string&&, const Allocator&);
 
310
 
311
- ~basic_string();
312
- basic_string& operator=(const basic_string& str);
313
- basic_string& operator=(basic_string&& str)
314
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
315
  allocator_traits<Allocator>::is_always_equal::value);
316
- basic_string& operator=(basic_string_view<charT, traits> sv);
317
- basic_string& operator=(const charT* s);
318
- basic_string& operator=(charT c);
319
- basic_string& operator=(initializer_list<charT>);
 
320
 
321
  // [string.iterators], iterators
322
- iterator begin() noexcept;
323
- const_iterator begin() const noexcept;
324
- iterator end() noexcept;
325
- const_iterator end() const noexcept;
326
 
327
- reverse_iterator rbegin() noexcept;
328
- const_reverse_iterator rbegin() const noexcept;
329
- reverse_iterator rend() noexcept;
330
- const_reverse_iterator rend() const noexcept;
331
 
332
- const_iterator cbegin() const noexcept;
333
- const_iterator cend() const noexcept;
334
- const_reverse_iterator crbegin() const noexcept;
335
- const_reverse_iterator crend() const noexcept;
336
 
337
  // [string.capacity], capacity
338
- size_type size() const noexcept;
339
- size_type length() const noexcept;
340
- size_type max_size() const noexcept;
341
- void resize(size_type n, charT c);
342
- void resize(size_type n);
343
- size_type capacity() const noexcept;
344
- void reserve(size_type res_arg = 0);
345
- void shrink_to_fit();
346
- void clear() noexcept;
347
- bool empty() const noexcept;
348
 
349
  // [string.access], element access
350
- const_reference operator[](size_type pos) const;
351
- reference operator[](size_type pos);
352
- const_reference at(size_type n) const;
353
- reference at(size_type n);
354
 
355
- const charT& front() const;
356
- charT& front();
357
- const charT& back() const;
358
- charT& back();
359
 
360
  // [string.modifiers], modifiers
361
- basic_string& operator+=(const basic_string& str);
362
- basic_string& operator+=(basic_string_view<charT, traits> sv);
363
- basic_string& operator+=(const charT* s);
364
- basic_string& operator+=(charT c);
365
- basic_string& operator+=(initializer_list<charT>);
366
- basic_string& append(const basic_string& str);
367
- basic_string& append(const basic_string& str, size_type pos,
368
- size_type n = npos);
369
- basic_string& append(basic_string_view<charT, traits> sv);
370
  template<class T>
371
- basic_string& append(const T& t, size_type pos, size_type n = npos);
372
- basic_string& append(const charT* s, size_type n);
373
- basic_string& append(const charT* s);
374
- basic_string& append(size_type n, charT c);
 
 
 
 
 
 
 
 
 
375
  template<class InputIterator>
376
- basic_string& append(InputIterator first, InputIterator last);
377
- basic_string& append(initializer_list<charT>);
378
- void push_back(charT c);
379
 
380
- basic_string& assign(const basic_string& str);
381
- basic_string& assign(basic_string&& str)
 
 
382
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
383
  allocator_traits<Allocator>::is_always_equal::value);
384
- basic_string& assign(const basic_string& str, size_type pos,
385
- size_type n = npos);
386
- basic_string& assign(basic_string_view<charT, traits> sv);
387
  template<class T>
388
- basic_string& assign(const T& t, size_type pos, size_type n = npos);
389
- basic_string& assign(const charT* s, size_type n);
390
- basic_string& assign(const charT* s);
391
- basic_string& assign(size_type n, charT c);
 
 
392
  template<class InputIterator>
393
- basic_string& assign(InputIterator first, InputIterator last);
394
- basic_string& assign(initializer_list<charT>);
395
 
396
- basic_string& insert(size_type pos, const basic_string& str);
397
- basic_string& insert(size_type pos1, const basic_string& str,
398
  size_type pos2, size_type n = npos);
399
- basic_string& insert(size_type pos, basic_string_view<charT, traits> sv);
400
  template<class T>
401
- basic_string& insert(size_type pos1, const T& t,
 
 
402
  size_type pos2, size_type n = npos);
403
- basic_string& insert(size_type pos, const charT* s, size_type n);
404
- basic_string& insert(size_type pos, const charT* s);
405
- basic_string& insert(size_type pos, size_type n, charT c);
406
- iterator insert(const_iterator p, charT c);
407
- iterator insert(const_iterator p, size_type n, charT c);
408
  template<class InputIterator>
409
- iterator insert(const_iterator p, InputIterator first, InputIterator last);
410
- iterator insert(const_iterator p, initializer_list<charT>);
411
 
412
- basic_string& erase(size_type pos = 0, size_type n = npos);
413
- iterator erase(const_iterator p);
414
- iterator erase(const_iterator first, const_iterator last);
415
 
416
- void pop_back();
417
 
418
- basic_string& replace(size_type pos1, size_type n1,
419
- const basic_string& str);
420
- basic_string& replace(size_type pos1, size_type n1,
421
- const basic_string& str,
422
  size_type pos2, size_type n2 = npos);
423
- basic_string& replace(size_type pos1, size_type n1,
424
- basic_string_view<charT, traits> sv);
425
  template<class T>
426
- basic_string& replace(size_type pos1, size_type n1, const T& t,
 
 
427
  size_type pos2, size_type n2 = npos);
428
- basic_string& replace(size_type pos, size_type n1, const charT* s,
429
- size_type n2);
430
- basic_string& replace(size_type pos, size_type n1, const charT* s);
431
- basic_string& replace(size_type pos, size_type n1, size_type n2,
432
- charT c);
433
-
434
- basic_string& replace(const_iterator i1, const_iterator i2,
435
  const basic_string& str);
436
- basic_string& replace(const_iterator i1, const_iterator i2,
437
- basic_string_view<charT, traits> sv);
438
- basic_string& replace(const_iterator i1, const_iterator i2, const charT* s,
439
  size_type n);
440
- basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
441
- basic_string& replace(const_iterator i1, const_iterator i2,
442
- size_type n, charT c);
443
  template<class InputIterator>
444
- basic_string& replace(const_iterator i1, const_iterator i2,
445
  InputIterator j1, InputIterator j2);
446
- basic_string& replace(const_iterator, const_iterator, initializer_list<charT>);
447
 
448
- size_type copy(charT* s, size_type n, size_type pos = 0) const;
449
- void swap(basic_string& str)
 
450
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
451
  allocator_traits<Allocator>::is_always_equal::value);
452
 
453
  // [string.ops], string operations
454
- const charT* c_str() const noexcept;
455
- const charT* data() const noexcept;
456
- charT* data() noexcept;
457
- operator basic_string_view<charT, traits>() const noexcept;
458
- allocator_type get_allocator() const noexcept;
459
 
460
- size_type find (basic_string_view<charT, traits> sv,
461
- size_type pos = 0) const noexcept;
462
- size_type find (const basic_string& str, size_type pos = 0) const noexcept;
463
- size_type find (const charT* s, size_type pos, size_type n) const;
464
- size_type find (const charT* s, size_type pos = 0) const;
465
- size_type find (charT c, size_type pos = 0) const;
466
- size_type rfind(basic_string_view<charT, traits> sv,
467
- size_type pos = npos) const noexcept;
468
- size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
469
- size_type rfind(const charT* s, size_type pos, size_type n) const;
470
- size_type rfind(const charT* s, size_type pos = npos) const;
471
- size_type rfind(charT c, size_type pos = npos) const;
472
 
473
- size_type find_first_of(basic_string_view<charT, traits> sv,
474
- size_type pos = 0) const noexcept;
475
- size_type find_first_of(const basic_string& str,
476
- size_type pos = 0) const noexcept;
477
- size_type find_first_of(const charT* s,
478
- size_type pos, size_type n) const;
479
- size_type find_first_of(const charT* s, size_type pos = 0) const;
480
- size_type find_first_of(charT c, size_type pos = 0) const;
481
- size_type find_last_of (basic_string_view<charT, traits> sv,
482
- size_type pos = npos) const noexcept;
483
- size_type find_last_of (const basic_string& str,
484
  size_type pos = npos) const noexcept;
485
- size_type find_last_of (const charT* s,
486
- size_type pos, size_type n) const;
487
- size_type find_last_of (const charT* s, size_type pos = npos) const;
488
- size_type find_last_of (charT c, size_type pos = npos) const;
489
 
490
- size_type find_first_not_of(basic_string_view<charT, traits> sv,
491
- size_type pos = 0) const noexcept;
492
- size_type find_first_not_of(const basic_string& str,
 
493
  size_type pos = 0) const noexcept;
494
- size_type find_first_not_of(const charT* s, size_type pos,
495
- size_type n) const;
496
- size_type find_first_not_of(const charT* s, size_type pos = 0) const;
497
- size_type find_first_not_of(charT c, size_type pos = 0) const;
498
- size_type find_last_not_of (basic_string_view<charT, traits> sv,
499
- size_type pos = npos) const noexcept;
500
- size_type find_last_not_of (const basic_string& str,
501
  size_type pos = npos) const noexcept;
502
- size_type find_last_not_of (const charT* s, size_type pos,
503
- size_type n) const;
504
- size_type find_last_not_of (const charT* s,
505
- size_type pos = npos) const;
506
- size_type find_last_not_of (charT c, size_type pos = npos) const;
507
 
508
- basic_string substr(size_type pos = 0, size_type n = npos) const;
509
- int compare(basic_string_view<charT, traits> sv) const noexcept;
510
- int compare(size_type pos1, size_type n1,
511
- basic_string_view<charT, traits> sv) const;
512
  template<class T>
513
- int compare(size_type pos1, size_type n1, const T& t,
 
 
514
  size_type pos2, size_type n2 = npos) const;
515
- int compare(const basic_string& str) const noexcept;
516
- int compare(size_type pos1, size_type n1,
517
- const basic_string& str) const;
518
- int compare(size_type pos1, size_type n1,
519
- const basic_string& str,
520
  size_type pos2, size_type n2 = npos) const;
521
- int compare(const charT* s) const;
522
- int compare(size_type pos1, size_type n1,
523
- const charT* s) const;
524
- int compare(size_type pos1, size_type n1,
525
- const charT* s, size_type n2) const;
 
 
 
 
 
526
  };
527
 
528
  template<class InputIterator,
529
  class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
530
  basic_string(InputIterator, InputIterator, Allocator = Allocator())
531
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
532
  char_traits<typename iterator_traits<InputIterator>::value_type>,
533
  Allocator>;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534
  }
535
  ```
536
 
537
- #### `basic_string` general requirements <a id="string.require">[[string.require]]</a>
 
 
 
 
538
 
539
  If any operation would cause `size()` to exceed `max_size()`, that
540
- operation shall throw an exception object of type `length_error`.
541
 
542
  If any member function or operator of `basic_string` throws an
543
- exception, that function or operator shall have no other effect.
 
544
 
545
  In every specialization `basic_string<charT, traits, Allocator>`, the
546
  type `allocator_traits<Allocator>::value_type` shall name the same type
547
  as `charT`. Every object of type
548
- `basic_string<charT, traits, Allocator>` shall use an object of type
549
  `Allocator` to allocate and free storage for the contained `charT`
550
- objects as needed. The `Allocator` object used shall be obtained as
551
- described in [[container.requirements.general]]. In every specialization
552
- `basic_string<charT, traits, Allocator>`, the type `traits` shall
553
- satisfy the character traits requirements ([[char.traits]]), and the
554
- type `traits::char_type` shall name the same type as `charT`.
 
 
555
 
556
  References, pointers, and iterators referring to the elements of a
557
  `basic_string` sequence may be invalidated by the following uses of that
558
  `basic_string` object:
559
 
560
- - as an argument to any standard library function taking a reference to
561
- non-const `basic_string` as an argument.[^3]
562
  - Calling non-const member functions, except `operator[]`, `at`, `data`,
563
  `front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
564
 
565
- #### `basic_string` constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
566
 
567
  ``` cpp
568
- explicit basic_string(const Allocator& a) noexcept;
569
  ```
570
 
571
- *Effects:* Constructs an object of class `basic_string`. The
572
- postconditions of this function are indicated in
573
- Table  [[tab:strings.ctr.1]].
574
-
575
- **Table: `basic_string(const Allocator&)` effects** <a id="tab:strings.ctr.1">[tab:strings.ctr.1]</a>
576
-
577
- | Element | Value |
578
- | ------------ | -------------------------------------------------------------- |
579
- | `data()` | a non-null pointer that is copyable and can have 0 added to it |
580
- | `size()` | 0 |
581
- | `capacity()` | an unspecified value |
582
 
583
  ``` cpp
584
- basic_string(const basic_string& str);
585
- basic_string(basic_string&& str) noexcept;
586
  ```
587
 
588
- *Effects:* Constructs an object of class `basic_string` as indicated in
589
- Table  [[tab:strings.ctr.cpy]]. In the second form, `str` is left in a
590
- valid state with an unspecified value.
591
-
592
- **Table: `basic_string(const basic_string&)` effects** <a id="tab:strings.ctr.cpy">[tab:strings.ctr.cpy]</a>
593
 
594
- | Element | Value |
595
- | ------------ | --------------------------------------------------------------------------------------------------------------- |
596
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
597
- | `size()` | `str.size()` |
598
- | `capacity()` | a value at least as large as `size()` |
599
 
600
  ``` cpp
601
- basic_string(const basic_string& str, size_type pos,
 
 
602
  const Allocator& a = Allocator());
603
  ```
604
 
605
- *Throws:* `out_of_range` if `pos > str.size()`.
606
-
607
- *Effects:* Constructs an object of class `basic_string` and determines
608
- the effective length `rlen` of the initial string value as
609
- `str.size() - pos`, as indicated in Table  [[tab:strings.ctr.2]].
610
 
611
  ``` cpp
612
- basic_string(const basic_string& str, size_type pos, size_type n,
613
- const Allocator& a = Allocator());
614
  ```
615
 
616
- *Throws:* `out_of_range` if `pos > str.size()`.
617
-
618
- *Effects:* Constructs an object of class `basic_string` and determines
619
- the effective length `rlen` of the initial string value as the smaller
620
- of `n` and `str.size() - pos`, as indicated in
621
- Table  [[tab:strings.ctr.2]].
622
-
623
- **Table: `basic_string(const basic_string&, size_type, const Allocator&)`\protect\mbox{ }and\protect
624
- `basic_string(const basic_string&, size_type, size_type, const Allocator&)` effects** <a id="tab:strings.ctr.2">[tab:strings.ctr.2]</a>
625
-
626
- | Element | Value |
627
- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
628
- | `data()` | points at the first element of an allocated copy of `rlen` consecutive elements of the string controlled by `str` beginning at position `pos` |
629
- | `size()` | `rlen` |
630
- | `capacity()` | a value at least as large as `size()` |
631
-
632
  ``` cpp
633
  template<class T>
634
- basic_string(const T& t, size_type pos, size_type n,
635
- const Allocator& a = Allocator());
636
  ```
637
 
 
 
 
 
638
  *Effects:* Creates a variable, `sv`, as if by
639
  `basic_string_view<charT, traits> sv = t;` and then behaves the same as:
640
 
641
  ``` cpp
642
  basic_string(sv.substr(pos, n), a);
643
  ```
644
 
645
- *Remarks:* This constructor shall not participate in overload resolution
646
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
647
- `true`.
648
-
649
  ``` cpp
650
- explicit basic_string(basic_string_view<charT, traits> sv,
651
- const Allocator& a = Allocator());
652
  ```
653
 
654
- *Effects:* Same as `basic_string(sv.data(), sv.size(), a)`.
 
 
 
 
 
 
 
 
655
 
656
  ``` cpp
657
- basic_string(const charT* s, size_type n,
658
- const Allocator& a = Allocator());
659
  ```
660
 
661
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
662
 
663
- *Effects:* Constructs an object of class `basic_string` and determines
664
- its initial string value from the array of `charT` of length `n` whose
665
- first element is designated by `s`, as indicated in
666
- Table  [[tab:strings.ctr.3]].
667
 
668
- **Table: `basic_string(const charT*, size_type, const Allocator&)` effects** <a id="tab:strings.ctr.3">[tab:strings.ctr.3]</a>
669
-
670
- | Element | Value |
671
- | ------------ | ------------------------------------------------------------------------------------------------------ |
672
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `s` |
673
- | `size()` | `n` |
674
- | `capacity()` | a value at least as large as `size()` |
675
 
676
  ``` cpp
677
- basic_string(const charT* s, const Allocator& a = Allocator());
678
  ```
679
 
680
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
681
- elements of `charT`.
682
-
683
- *Effects:* Constructs an object of class `basic_string` and determines
684
- its initial string value from the array of `charT` of length
685
- `traits::length(s)` whose first element is designated by `s`, as
686
- indicated in Table  [[tab:strings.ctr.4]].
687
 
688
- **Table: `basic_string(const charT*, const Allocator&)` effects** <a id="tab:strings.ctr.4">[tab:strings.ctr.4]</a>
 
689
 
690
- | Element | Value |
691
- | ------------ | ------------------------------------------------------------------------------------------------------ |
692
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `s` |
693
- | `size()` | `traits::length(s)` |
694
- | `capacity()` | a value at least as large as `size()` |
695
 
696
  ``` cpp
697
- basic_string(size_type n, charT c, const Allocator& a = Allocator());
698
  ```
699
 
700
- *Requires:* `n < npos`.
701
-
702
- *Effects:* Constructs an object of class `basic_string` and determines
703
- its initial string value by repeating the char-like object `c` for all
704
- `n` elements, as indicated in Table  [[tab:strings.ctr.5]].
705
 
706
- **Table: `basic_string(size_t, charT, const Allocator&)` effects** <a id="tab:strings.ctr.5">[tab:strings.ctr.5]</a>
 
707
 
708
- | Element | Value |
709
- | ------------ | ----------------------------------------------------------------------------------------------------- |
710
- | `data()` | points at the first element of an allocated array of `n` elements, each storing the initial value `c` |
711
- | `size()` | `n` |
712
- | `capacity()` | a value at least as large as `size()` |
713
 
714
  ``` cpp
715
  template<class InputIterator>
716
- basic_string(InputIterator begin, InputIterator end,
717
- const Allocator& a = Allocator());
718
  ```
719
 
720
- *Effects:* If `InputIterator` is an integral type, equivalent to:
 
721
 
722
- ``` cpp
723
- basic_string(static_cast<size_type>(begin), static_cast<value_type>(end), a);
724
- ```
725
-
726
- Otherwise constructs a string from the values in the range \[`begin`,
727
- `end`), as indicated in the Sequence Requirements table
728
- (see  [[sequence.reqmts]]).
729
 
730
  ``` cpp
731
- basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
732
  ```
733
 
734
- *Effects:* Same as `basic_string(il.begin(), il.end(), a)`.
735
 
736
  ``` cpp
737
- basic_string(const basic_string& str, const Allocator& alloc);
738
- basic_string(basic_string&& str, const Allocator& alloc);
739
  ```
740
 
741
- *Effects:* Constructs an object of class `basic_string` as indicated in
742
- Table  [[tab:strings.ctr.6]]. The stored allocator is constructed from
743
- `alloc`. In the second form, `str` is left in a valid state with an
744
- unspecified value.
745
-
746
- **Table: `basic_string(const basic_string&, const Allocator&)`\protect and
747
- `basic_string(basic_string&&, const Allocator&)` effects** <a id="tab:strings.ctr.6">[tab:strings.ctr.6]</a>
748
-
749
- | Element | Value |
750
- | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
751
- | `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()`. |
752
- | `size()` | the original value of `str.size()` |
753
- | `capacity()` | a value at least as large as `size()` |
754
- | `get_allocator()` | `alloc` |
755
-
756
 
757
  *Throws:* The second form throws nothing if
758
  `alloc == str.get_allocator()`.
759
 
760
  ``` cpp
@@ -764,226 +690,236 @@ template<class InputIterator,
764
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
765
  char_traits<typename iterator_traits<InputIterator>::value_type>,
766
  Allocator>;
767
  ```
768
 
769
- *Remarks:* Shall not participate in overload resolution if
770
- `InputIterator` is a type that does not qualify as an input iterator, or
771
- if `Allocator` is a type that does not qualify as an
772
- allocator ([[container.requirements.general]]).
773
 
774
  ``` cpp
775
- basic_string& operator=(const basic_string& str);
 
 
 
 
 
 
 
 
 
 
 
 
776
  ```
777
 
778
- *Effects:* If `*this` and `str` are not the same object, modifies
779
- `*this` as shown in Table  [[tab:strings.op=]].
 
 
 
 
780
 
781
- If `*this` and `str` are the same object, the member has no effect.
 
782
 
783
  *Returns:* `*this`.
784
 
785
- **Table: `operator=(const basic_string&)` effects** <a id="tab:strings.op=">[tab:strings.op=]</a>
786
-
787
- | Element | Value |
788
- | ------------ | --------------------------------------------------------------------------------------------------------------- |
789
- | `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
790
- | `size()` | `str.size()` |
791
- | `capacity()` | a value at least as large as `size()` |
792
-
793
  ``` cpp
794
- basic_string& operator=(basic_string&& str)
795
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
796
  allocator_traits<Allocator>::is_always_equal::value);
797
  ```
798
 
799
  *Effects:* Move assigns as a sequence
800
- container ([[container.requirements]]), except that iterators, pointers
801
  and references may be invalidated.
802
 
803
  *Returns:* `*this`.
804
 
805
  ``` cpp
806
- basic_string& operator=(basic_string_view<charT, traits> sv);
 
807
  ```
808
 
809
- *Effects:* Equivalent to: `return assign(sv);`
 
 
 
 
 
 
810
 
811
  ``` cpp
812
- basic_string& operator=(const charT* s);
 
813
  ```
814
 
815
- *Returns:* `*this = basic_string(s)`.
 
 
816
 
817
- *Remarks:* Uses `traits::length()`.
 
818
 
819
  ``` cpp
820
- basic_string& operator=(charT c);
821
  ```
822
 
823
- *Returns:* `*this = basic_string(1, c)`.
824
 
825
  ``` cpp
826
- basic_string& operator=(initializer_list<charT> il);
827
  ```
828
 
829
- *Effects:* As if by: `*this = basic_string(il);`
 
 
 
 
830
 
831
- *Returns:* `*this`.
 
 
832
 
833
- #### `basic_string` iterator support <a id="string.iterators">[[string.iterators]]</a>
834
 
835
  ``` cpp
836
- iterator begin() noexcept;
837
- const_iterator begin() const noexcept;
838
- const_iterator cbegin() const noexcept;
839
  ```
840
 
841
  *Returns:* An iterator referring to the first character in the string.
842
 
843
  ``` cpp
844
- iterator end() noexcept;
845
- const_iterator end() const noexcept;
846
- const_iterator cend() const noexcept;
847
  ```
848
 
849
  *Returns:* An iterator which is the past-the-end value.
850
 
851
  ``` cpp
852
- reverse_iterator rbegin() noexcept;
853
- const_reverse_iterator rbegin() const noexcept;
854
- const_reverse_iterator crbegin() const noexcept;
855
  ```
856
 
857
  *Returns:* An iterator which is semantically equivalent to
858
  `reverse_iterator(end())`.
859
 
860
  ``` cpp
861
- reverse_iterator rend() noexcept;
862
- const_reverse_iterator rend() const noexcept;
863
- const_reverse_iterator crend() const noexcept;
864
  ```
865
 
866
  *Returns:* An iterator which is semantically equivalent to
867
  `reverse_iterator(begin())`.
868
 
869
- #### `basic_string` capacity <a id="string.capacity">[[string.capacity]]</a>
870
 
871
  ``` cpp
872
- size_type size() const noexcept;
 
873
  ```
874
 
875
  *Returns:* A count of the number of char-like objects currently in the
876
  string.
877
 
878
  *Complexity:* Constant time.
879
 
880
  ``` cpp
881
- size_type length() const noexcept;
882
- ```
883
-
884
- *Returns:* `size()`.
885
-
886
- ``` cpp
887
- size_type max_size() const noexcept;
888
  ```
889
 
890
  *Returns:* The largest possible number of char-like objects that can be
891
  stored in a `basic_string`.
892
 
893
  *Complexity:* Constant time.
894
 
895
  ``` cpp
896
- void resize(size_type n, charT c);
897
  ```
898
 
899
- *Throws:* `length_error` if `n > max_size()`.
900
 
901
- *Effects:* Alters the length of the string designated by `*this` as
902
- follows:
903
-
904
- - If `n <= size()`, the function replaces the string designated by
905
- `*this` with a string of length `n` whose elements are a copy of the
906
- initial elements of the original string designated by `*this`.
907
- - If `n > size()`, the function replaces the string designated by
908
- `*this` with a string of length `n` whose first `size()` elements are
909
- a copy of the original string designated by `*this`, and whose
910
- remaining elements are all initialized to `c`.
911
 
912
  ``` cpp
913
- void resize(size_type n);
914
  ```
915
 
916
- *Effects:* As if by `resize(n, charT())`.
917
 
918
  ``` cpp
919
- size_type capacity() const noexcept;
920
  ```
921
 
922
  *Returns:* The size of the allocated storage in the string.
923
 
 
 
924
  ``` cpp
925
- void reserve(size_type res_arg=0);
926
  ```
927
 
928
- The member function `reserve()` is a directive that informs a
929
- `basic_string` object of a planned change in size, so that it can manage
930
- the storage allocation accordingly.
 
 
 
931
 
932
- *Effects:* After `reserve()`, `capacity()` is greater or equal to the
933
- argument of `reserve`.
934
-
935
- [*Note 1*: Calling `reserve()` with a `res_arg` argument less than
936
- `capacity()` is in effect a non-binding shrink request. A call with
937
- `res_arg <= size()` is in effect a non-binding shrink-to-fit
938
- request. — *end note*]
939
-
940
- *Throws:* `length_error` if `res_arg > max_size()`.[^4]
941
 
942
  ``` cpp
943
- void shrink_to_fit();
944
  ```
945
 
946
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
947
  `capacity()` to `size()`.
948
 
949
- [*Note 2*: The request is non-binding to allow latitude for
950
  implementation-specific optimizations. — *end note*]
951
 
952
  It does not increase `capacity()`, but may reduce `capacity()` by
953
  causing reallocation.
954
 
955
- *Complexity:* Linear in the size of the sequence.
 
956
 
957
  *Remarks:* Reallocation invalidates all the references, pointers, and
958
- iterators referring to the elements in the sequence as well as the
959
- past-the-end iterator. If no reallocation happens, they remain valid.
960
 
961
- ``` cpp
962
- void clear() noexcept;
963
- ```
964
-
965
- *Effects:* Behaves as if the function calls:
966
 
967
  ``` cpp
968
- erase(begin(), end());
969
  ```
970
 
 
 
971
  ``` cpp
972
- bool empty() const noexcept;
973
  ```
974
 
975
- *Returns:* `size() == 0`.
976
 
977
- #### `basic_string` element access <a id="string.access">[[string.access]]</a>
978
 
979
  ``` cpp
980
- const_reference operator[](size_type pos) const;
981
- reference operator[](size_type pos);
982
  ```
983
 
984
- *Requires:* `pos <= size()`.
985
 
986
  *Returns:* `*(begin() + pos)` if `pos < size()`. Otherwise, returns a
987
  reference to an object of type `charT` with value `charT()`, where
988
  modifying the object to any value other than `charT()` leads to
989
  undefined behavior.
@@ -991,1026 +927,800 @@ undefined behavior.
991
  *Throws:* Nothing.
992
 
993
  *Complexity:* Constant time.
994
 
995
  ``` cpp
996
- const_reference at(size_type pos) const;
997
- reference at(size_type pos);
998
  ```
999
 
1000
  *Throws:* `out_of_range` if `pos >= size()`.
1001
 
1002
  *Returns:* `operator[](pos)`.
1003
 
1004
  ``` cpp
1005
- const charT& front() const;
1006
- charT& front();
1007
  ```
1008
 
1009
- *Requires:* `!empty()`.
1010
 
1011
  *Effects:* Equivalent to: `return operator[](0);`
1012
 
1013
  ``` cpp
1014
- const charT& back() const;
1015
- charT& back();
1016
  ```
1017
 
1018
- *Requires:* `!empty()`.
1019
 
1020
  *Effects:* Equivalent to: `return operator[](size() - 1);`
1021
 
1022
- #### `basic_string` modifiers <a id="string.modifiers">[[string.modifiers]]</a>
1023
 
1024
- ##### `basic_string::operator+=` <a id="string.op+=">[[string.op+=]]</a>
1025
 
1026
  ``` cpp
1027
- basic_string&
1028
- operator+=(const basic_string& str);
1029
  ```
1030
 
1031
- *Effects:* Calls `append(str)`.
1032
-
1033
- *Returns:* `*this`.
1034
 
1035
  ``` cpp
1036
- basic_string& operator+=(basic_string_view<charT, traits> sv);
 
1037
  ```
1038
 
1039
- *Effects:* Calls `append(sv)`.
 
 
 
 
1040
 
1041
- *Returns:* `*this`.
1042
 
1043
  ``` cpp
1044
- basic_string& operator+=(const charT* s);
 
1045
  ```
1046
 
1047
- *Effects:* Calls `append(s)`.
 
 
1048
 
1049
- *Returns:* `*this`.
1050
 
1051
  ``` cpp
1052
- basic_string& operator+=(charT c);
1053
  ```
1054
 
1055
- *Effects:* Calls `push_back(c)`;
1056
-
1057
- *Returns:* `*this`.
1058
 
1059
  ``` cpp
1060
- basic_string& operator+=(initializer_list<charT> il);
1061
  ```
1062
 
1063
- *Effects:* Calls `append(il)`.
1064
-
1065
- *Returns:* `*this`.
1066
 
1067
  ##### `basic_string::append` <a id="string.append">[[string.append]]</a>
1068
 
1069
  ``` cpp
1070
- basic_string&
1071
- append(const basic_string& str);
1072
  ```
1073
 
1074
- *Effects:* Calls `append(str.data(), str.size())`.
1075
-
1076
- *Returns:* `*this`.
1077
 
1078
  ``` cpp
1079
- basic_string&
1080
- append(const basic_string& str, size_type pos, size_type n = npos);
1081
  ```
1082
 
1083
- *Throws:* `out_of_range` if `pos > str.size()`.
1084
-
1085
- *Effects:* Determines the effective length `rlen` of the string to
1086
- append as the smaller of `n` and `str``.size() - ``pos` and calls
1087
- `append(str.data() + pos, rlen)`.
1088
-
1089
- *Returns:* `*this`.
1090
 
1091
  ``` cpp
1092
- basic_string& append(basic_string_view<charT, traits> sv);
1093
  ```
1094
 
1095
- *Effects:* Equivalent to: `return append(sv.data(), sv.size());`
1096
-
1097
  ``` cpp
1098
  template<class T>
1099
- basic_string& append(const T& t, size_type pos, size_type n = npos);
1100
  ```
1101
 
1102
- *Throws:* `out_of_range` if `pos > sv.size()`.
1103
 
1104
- *Effects:* Creates a variable, `sv`, as if by
1105
- `basic_string_view<charT, traits> sv = t`. Determines the effective
1106
- length `rlen` of the string to append as the smaller of `n` and
1107
- `sv.size() - pos` and calls `append(sv.data() + pos, rlen)`.
1108
 
1109
- *Remarks:* This function shall not participate in overload resolution
1110
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1111
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
1112
 
1113
- *Returns:* `*this`.
 
 
 
1114
 
1115
  ``` cpp
1116
- basic_string&
1117
- append(const charT* s, size_type n);
1118
  ```
1119
 
1120
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
1121
 
1122
- *Throws:* `length_error` if `size() + n > max_size()`.
 
 
1123
 
1124
- *Effects:* The function replaces the string controlled by `*this` with a
1125
- string of length `size() + n` whose first `size()` elements are a copy
1126
- of the original string controlled by `*this` and whose remaining
1127
- elements are a copy of the initial `n` elements of `s`.
1128
 
1129
- *Returns:* `*this`.
 
 
 
1130
 
1131
  ``` cpp
1132
- basic_string& append(const charT* s);
1133
  ```
1134
 
1135
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1136
- elements of `charT`.
1137
 
1138
- *Effects:* Calls `append(s, traits::length(s))`.
1139
 
1140
  *Returns:* `*this`.
1141
 
1142
  ``` cpp
1143
- basic_string& append(size_type n, charT c);
 
 
 
 
 
 
1144
  ```
1145
 
1146
- *Effects:* Equivalent to `append(basic_string(n, c))`.
1147
 
1148
  *Returns:* `*this`.
1149
 
1150
  ``` cpp
1151
  template<class InputIterator>
1152
- basic_string& append(InputIterator first, InputIterator last);
1153
  ```
1154
 
1155
- *Requires:* \[`first`, `last`) is a valid range.
 
1156
 
1157
- *Effects:* Equivalent to
1158
- `append(basic_string(first, last, get_allocator()))`.
1159
-
1160
- *Returns:* `*this`.
1161
 
1162
  ``` cpp
1163
- basic_string& append(initializer_list<charT> il);
1164
  ```
1165
 
1166
- *Effects:* Calls `append(il.begin(), il.size())`.
1167
-
1168
- *Returns:* `*this`.
1169
 
1170
  ``` cpp
1171
- void push_back(charT c);
1172
  ```
1173
 
1174
- *Effects:* Equivalent to `append(static_cast<size_type>(1), c)`.
1175
 
1176
  ##### `basic_string::assign` <a id="string.assign">[[string.assign]]</a>
1177
 
1178
  ``` cpp
1179
- basic_string& assign(const basic_string& str);
1180
  ```
1181
 
1182
- *Effects:* Equivalent to `*this = str`.
1183
-
1184
- *Returns:* `*this`.
1185
 
1186
  ``` cpp
1187
- basic_string& assign(basic_string&& str)
1188
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
1189
  allocator_traits<Allocator>::is_always_equal::value);
1190
  ```
1191
 
1192
- *Effects:* Equivalent to `*this = std::move(str)`.
1193
-
1194
- *Returns:* `*this`.
1195
 
1196
  ``` cpp
1197
- basic_string&
1198
- assign(const basic_string& str, size_type pos,
1199
- size_type n = npos);
1200
  ```
1201
 
1202
- *Throws:* `out_of_range` if `pos > str.size()`.
1203
-
1204
- *Effects:* Determines the effective length `rlen` of the string to
1205
- assign as the smaller of `n` and `str``.size() - ``pos` and calls
1206
- `assign(str.data() + pos, rlen)`.
1207
-
1208
- *Returns:* `*this`.
1209
 
1210
  ``` cpp
1211
- basic_string& assign(basic_string_view<charT, traits> sv);
1212
  ```
1213
 
1214
- *Effects:* Equivalent to: `return assign(sv.data(), sv.size());`
1215
-
1216
  ``` cpp
1217
  template<class T>
1218
- basic_string& assign(const T& t, size_type pos, size_type n = npos);
1219
  ```
1220
 
1221
- *Throws:* `out_of_range` if `pos > sv.size()`.
1222
 
1223
- *Effects:* Creates a variable, `sv`, as if by
1224
- `basic_string_view<charT, traits> sv = t`. Determines the effective
1225
- length `rlen` of the string to assign as the smaller of `n` and
1226
- `sv.size() - pos` and calls `assign(sv.data() + pos, rlen)`.
1227
 
1228
- *Remarks:* This function shall not participate in overload resolution
1229
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1230
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
1231
 
1232
- *Returns:* `*this`.
 
 
 
1233
 
1234
  ``` cpp
1235
- basic_string& assign(const charT* s, size_type n);
 
1236
  ```
1237
 
1238
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
1239
 
1240
- *Throws:* `length_error` if `n > max_size()`.
 
 
1241
 
1242
- *Effects:* Replaces the string controlled by `*this` with a string of
1243
- length `n` whose elements are a copy of those pointed to by `s`.
1244
 
1245
- *Returns:* `*this`.
 
 
 
1246
 
1247
  ``` cpp
1248
- basic_string& assign(const charT* s);
1249
  ```
1250
 
1251
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1252
- elements of `charT`.
1253
 
1254
- *Effects:* Calls `assign(s, traits::length(s))`.
 
1255
 
1256
  *Returns:* `*this`.
1257
 
1258
  ``` cpp
1259
- basic_string& assign(initializer_list<charT> il);
1260
  ```
1261
 
1262
- *Effects:* Calls `assign(il.begin(), il.size())`.
1263
 
1264
- `*this`.
 
 
 
 
1265
 
1266
  ``` cpp
1267
- basic_string& assign(size_type n, charT c);
1268
  ```
1269
 
1270
- *Effects:* Equivalent to `assign(basic_string(n, c))`.
1271
 
1272
- *Returns:* `*this`.
 
 
 
 
1273
 
1274
  ``` cpp
1275
  template<class InputIterator>
1276
- basic_string& assign(InputIterator first, InputIterator last);
1277
  ```
1278
 
1279
- *Effects:* Equivalent to
1280
- `assign(basic_string(first, last, get_allocator()))`.
1281
 
1282
- *Returns:* `*this`.
 
1283
 
1284
  ##### `basic_string::insert` <a id="string.insert">[[string.insert]]</a>
1285
 
1286
  ``` cpp
1287
- basic_string&
1288
- insert(size_type pos,
1289
- const basic_string& str);
1290
  ```
1291
 
1292
  *Effects:* Equivalent to: `return insert(pos, str.data(), str.size());`
1293
 
1294
  ``` cpp
1295
- basic_string&
1296
- insert(size_type pos1,
1297
- const basic_string& str,
1298
  size_type pos2, size_type n = npos);
1299
  ```
1300
 
1301
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
1302
 
1303
- *Effects:* Determines the effective length `rlen` of the string to
1304
- insert as the smaller of `n` and `str.size() - pos2` and calls
1305
- `insert(pos1, str.data() + pos2, rlen)`.
1306
-
1307
- *Returns:* `*this`.
1308
 
1309
  ``` cpp
1310
- basic_string& insert(size_type pos, basic_string_view<charT, traits> sv);
 
1311
  ```
1312
 
1313
- *Effects:* Equivalent to: `return insert(pos, sv.data(), sv.size());`
 
 
 
 
 
 
 
 
 
 
 
1314
 
1315
  ``` cpp
1316
  template<class T>
1317
- basic_string& insert(size_type pos1, const T& t,
1318
  size_type pos2, size_type n = npos);
1319
  ```
1320
 
1321
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > sv.size()`.
1322
 
1323
- *Effects:* Creates a variable, `sv`, as if by
1324
- `basic_string_view<charT, traits> sv = t`. Determines the effective
1325
- length `rlen` of the string to assign as the smaller of `n` and
1326
- `sv.size() - pos2` and calls `insert(pos1, sv.data() + pos2, rlen)`.
1327
 
1328
- *Remarks:* This function shall not participate in overload resolution
1329
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1330
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
1331
 
1332
- *Returns:* `*this`.
 
 
 
1333
 
1334
  ``` cpp
1335
- basic_string&
1336
- insert(size_type pos, const charT* s, size_type n);
1337
  ```
1338
 
1339
- *Requires:* `s` points to an array of at least `n` elements of `charT`.
 
 
1340
 
1341
- *Throws:* `out_of_range` if `pos > size()` or `length_error` if
1342
- `size() + n > max_size()`.
 
1343
 
1344
- *Effects:* Replaces the string controlled by `*this` with a string of
1345
- length `size() + n` whose first `pos` elements are a copy of the initial
1346
- elements of the original string controlled by `*this` and whose next `n`
1347
- elements are a copy of the elements in `s` and whose remaining elements
1348
- are a copy of the remaining elements of the original string controlled
1349
- by `*this`.
1350
 
1351
  *Returns:* `*this`.
1352
 
1353
  ``` cpp
1354
- basic_string&
1355
- insert(size_type pos, const charT* s);
1356
  ```
1357
 
1358
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1359
- elements of `charT`.
1360
-
1361
  *Effects:* Equivalent to: `return insert(pos, s, traits::length(s));`
1362
 
1363
  ``` cpp
1364
- basic_string&
1365
- insert(size_type pos, size_type n, charT c);
1366
  ```
1367
 
1368
- *Effects:* Equivalent to `insert(pos, basic_string(n, c))`.
 
1369
 
1370
- *Returns:* `*this`.
 
 
 
 
 
 
1371
 
1372
  ``` cpp
1373
- iterator insert(const_iterator p, charT c);
1374
  ```
1375
 
1376
- *Requires:* `p` is a valid iterator on `*this`.
1377
 
1378
- *Effects:* Inserts a copy of `c` before the character referred to by
1379
- `p`.
1380
 
1381
- *Returns:* An iterator which refers to the copy of the inserted
1382
- character.
1383
 
1384
  ``` cpp
1385
- iterator insert(const_iterator p, size_type n, charT c);
1386
  ```
1387
 
1388
- *Requires:* `p` is a valid iterator on `*this`.
1389
 
1390
- *Effects:* Inserts `n` copies of `c` before the character referred to by
1391
- `p`.
1392
 
1393
- *Returns:* An iterator which refers to the copy of the first inserted
1394
- character, or `p` if `n == 0`.
1395
 
1396
  ``` cpp
1397
  template<class InputIterator>
1398
- iterator insert(const_iterator p, InputIterator first, InputIterator last);
1399
  ```
1400
 
1401
- *Requires:* `p` is a valid iterator on `*this`. `[first, last)` is a
1402
- valid range.
 
 
1403
 
1404
  *Effects:* Equivalent to
1405
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
1406
 
1407
- *Returns:* An iterator which refers to the copy of the first inserted
1408
- character, or `p` if `first == last`.
1409
 
1410
  ``` cpp
1411
- iterator insert(const_iterator p, initializer_list<charT> il);
1412
  ```
1413
 
1414
- *Effects:* As if by `insert(p, il.begin(), il.end())`.
1415
-
1416
- *Returns:* An iterator which refers to the copy of the first inserted
1417
- character, or `p` if `i1` is empty.
1418
 
1419
  ##### `basic_string::erase` <a id="string.erase">[[string.erase]]</a>
1420
 
1421
  ``` cpp
1422
- basic_string& erase(size_type pos = 0, size_type n = npos);
1423
  ```
1424
 
1425
  *Throws:* `out_of_range` if `pos` `> size()`.
1426
 
1427
  *Effects:* Determines the effective length `xlen` of the string to be
1428
- removed as the smaller of `n` and `size() - pos`.
1429
-
1430
- The function then replaces the string controlled by `*this` with a
1431
- string of length `size() - xlen` whose first `pos` elements are a copy
1432
- of the initial elements of the original string controlled by `*this`,
1433
- and whose remaining elements are a copy of the elements of the original
1434
- string controlled by `*this` beginning at position `pos + xlen`.
1435
 
1436
  *Returns:* `*this`.
1437
 
1438
  ``` cpp
1439
- iterator erase(const_iterator p);
1440
  ```
1441
 
 
 
1442
  *Throws:* Nothing.
1443
 
1444
  *Effects:* Removes the character referred to by `p`.
1445
 
1446
  *Returns:* An iterator which points to the element immediately following
1447
  `p` prior to the element being erased. If no such element exists,
1448
  `end()` is returned.
1449
 
1450
  ``` cpp
1451
- iterator erase(const_iterator first, const_iterator last);
1452
  ```
1453
 
1454
- *Requires:* `first` and `last` are valid iterators on `*this`, defining
1455
- a range `[first, last)`.
1456
 
1457
  *Throws:* Nothing.
1458
 
1459
  *Effects:* Removes the characters in the range `[first, last)`.
1460
 
1461
  *Returns:* An iterator which points to the element pointed to by `last`
1462
  prior to the other elements being erased. If no such element exists,
1463
  `end()` is returned.
1464
 
1465
  ``` cpp
1466
- void pop_back();
1467
  ```
1468
 
1469
- *Requires:* `!empty()`.
1470
 
1471
  *Throws:* Nothing.
1472
 
1473
- *Effects:* Equivalent to `erase(size() - 1, 1)`.
1474
 
1475
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
1476
 
1477
  ``` cpp
1478
- basic_string&
1479
- replace(size_type pos1, size_type n1,
1480
- const basic_string& str);
1481
  ```
1482
 
1483
  *Effects:* Equivalent to:
1484
  `return replace(pos1, n1, str.data(), str.size());`
1485
 
1486
  ``` cpp
1487
- basic_string&
1488
- replace(size_type pos1, size_type n1,
1489
- const basic_string& str,
1490
  size_type pos2, size_type n2 = npos);
1491
  ```
1492
 
1493
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
1494
-
1495
- *Effects:* Determines the effective length `rlen` of the string to be
1496
- inserted as the smaller of `n2` and `str.size() - pos2` and calls
1497
- `replace(pos1, n1, str.data() + pos2, rlen)`.
1498
 
1499
- *Returns:* `*this`.
 
 
1500
 
1501
  ``` cpp
1502
- basic_string& replace(size_type pos1, size_type n1,
1503
- basic_string_view<charT, traits> sv);
1504
  ```
1505
 
 
 
 
 
 
 
1506
  *Effects:* Equivalent to:
1507
- `return replace(pos1, n1, sv.data(), sv.size());`
 
 
 
 
1508
 
1509
  ``` cpp
1510
  template<class T>
1511
- basic_string& replace(size_type pos1, size_type n1, const T& t,
1512
  size_type pos2, size_type n2 = npos);
1513
  ```
1514
 
1515
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > sv.size()`.
1516
 
1517
- *Effects:* Creates a variable, `sv`, as if by
1518
- `basic_string_view<charT, traits> sv = t`. Determines the effective
1519
- length `rlen` of the string to be inserted as the smaller of `n2` and
1520
- `sv.size() - pos2` and calls
1521
- `replace(pos1, n1, sv.data() + pos2, rlen)`.
1522
 
1523
- *Remarks:* This function shall not participate in overload resolution
1524
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1525
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
1526
 
1527
- *Returns:* `*this`.
 
 
 
1528
 
1529
  ``` cpp
1530
- basic_string&
1531
- replace(size_type pos1, size_type n1, const charT* s, size_type n2);
1532
  ```
1533
 
1534
- *Requires:* `s` points to an array of at least `n2` elements of `charT`.
 
 
1535
 
1536
- *Throws:* `out_of_range` if `pos1 > size()` or `length_error` if the
1537
- length of the resulting string would exceed `max_size()` (see below).
 
 
1538
 
1539
  *Effects:* Determines the effective length `xlen` of the string to be
1540
  removed as the smaller of `n1` and `size() - pos1`. If
1541
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
1542
- function replaces the string controlled by \*`this` with a string of
1543
- length `size() - xlen + n2` whose first `pos1` elements are a copy of
1544
- the initial elements of the original string controlled by `*this`, whose
1545
- next `n2` elements are a copy of the initial `n2` elements of `s`, and
1546
- whose remaining elements are a copy of the elements of the original
1547
- string controlled by `*this` beginning at position `pos + xlen`.
1548
 
1549
  *Returns:* `*this`.
1550
 
1551
  ``` cpp
1552
- basic_string&
1553
- replace(size_type pos, size_type n, const charT* s);
1554
  ```
1555
 
1556
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1557
- elements of `charT`.
1558
-
1559
  *Effects:* Equivalent to:
1560
  `return replace(pos, n, s, traits::length(s));`
1561
 
1562
  ``` cpp
1563
- basic_string&
1564
- replace(size_type pos1, size_type n1,
1565
- size_type n2, charT c);
1566
  ```
1567
 
1568
- *Effects:* Equivalent to `replace(pos1, n1, basic_string(n2, c))`.
 
 
 
 
 
 
 
 
 
 
 
1569
 
1570
  *Returns:* `*this`.
1571
 
1572
  ``` cpp
1573
- basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
1574
  ```
1575
 
1576
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1577
-
1578
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, str)`.
1579
-
1580
- *Returns:* `*this`.
1581
 
1582
  ``` cpp
1583
- basic_string& replace(const_iterator i1, const_iterator i2,
1584
- basic_string_view<charT, traits> sv);
1585
  ```
1586
 
1587
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1588
 
1589
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, sv)`.
 
 
1590
 
1591
- *Returns:* `*this`.
 
 
1592
 
1593
  ``` cpp
1594
- basic_string&
1595
- replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
1596
  ```
1597
 
1598
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges and
1599
- `s` points to an array of at least `n` elements of `charT`.
1600
-
1601
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, s, n)`.
1602
-
1603
- *Returns:* `*this`.
1604
-
1605
  ``` cpp
1606
- basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
1607
  ```
1608
 
1609
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges and
1610
- `s` points to an array of at least `traits::length(s) + 1` elements of
1611
- `charT`.
1612
 
1613
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, s, traits::length(s))`.
 
 
1614
 
1615
- *Returns:* `*this`.
 
1616
 
1617
  ``` cpp
1618
- basic_string& replace(const_iterator i1, const_iterator i2, size_type n,
1619
- charT c);
1620
  ```
1621
 
1622
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1623
 
1624
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, basic_string(n, c))`.
1625
-
1626
- *Returns:* `*this`.
1627
 
1628
  ``` cpp
1629
  template<class InputIterator>
1630
- basic_string& replace(const_iterator i1, const_iterator i2,
1631
  InputIterator j1, InputIterator j2);
1632
  ```
1633
 
1634
- *Requires:* \[`begin()`, `i1`), \[`i1`, `i2`) and \[`j1`, `j2`) are
1635
- valid ranges.
1636
 
1637
- *Effects:* Calls
1638
- `replace(i1 - begin(), i2 - i1, basic_string(j1, j2, get_allocator()))`.
1639
-
1640
- *Returns:* `*this`.
1641
 
1642
  ``` cpp
1643
- basic_string& replace(const_iterator i1, const_iterator i2,
1644
- initializer_list<charT> il);
1645
  ```
1646
 
1647
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1648
-
1649
- *Effects:* Calls
1650
- `replace(i1 - begin(), i2 - i1, il.begin(), il.size())`.
1651
-
1652
- *Returns:* `*this`.
1653
 
1654
  ##### `basic_string::copy` <a id="string.copy">[[string.copy]]</a>
1655
 
1656
  ``` cpp
1657
- size_type copy(charT* s, size_type n, size_type pos = 0) const;
1658
  ```
1659
 
1660
- Let `rlen` be the smaller of `n` and `size() - pos`.
1661
-
1662
- *Throws:* `out_of_range` if `pos > size()`.
1663
-
1664
- *Requires:* \[`s`, `s + rlen`) is a valid range.
1665
-
1666
- *Effects:* Equivalent to: `traits::copy(s, data() + pos, rlen)`.
1667
 
1668
  [*Note 1*: This does not terminate `s` with a null
1669
  object. — *end note*]
1670
 
1671
- *Returns:* `rlen`.
1672
-
1673
  ##### `basic_string::swap` <a id="string.swap">[[string.swap]]</a>
1674
 
1675
  ``` cpp
1676
- void swap(basic_string& s)
1677
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1678
  allocator_traits<Allocator>::is_always_equal::value);
1679
  ```
1680
 
1681
- *Postconditions:* `*this` contains the same sequence of characters that
1682
- was in `s`, `s` contains the same sequence of characters that was in
1683
- `*this`.
 
 
 
1684
 
1685
  *Throws:* Nothing.
1686
 
1687
  *Complexity:* Constant time.
1688
 
1689
- #### `basic_string` string operations <a id="string.ops">[[string.ops]]</a>
1690
 
1691
- ##### `basic_string` accessors <a id="string.accessors">[[string.accessors]]</a>
1692
 
1693
  ``` cpp
1694
- const charT* c_str() const noexcept;
1695
- const charT* data() const noexcept;
1696
  ```
1697
 
1698
- *Returns:* A pointer `p` such that `p + i == &operator[](i)` for each
1699
- `i` in \[`0`, `size()`\].
1700
 
1701
  *Complexity:* Constant time.
1702
 
1703
- *Requires:* The program shall not alter any of the values stored in the
1704
- character array.
1705
 
1706
  ``` cpp
1707
- charT* data() noexcept;
1708
  ```
1709
 
1710
- *Returns:* A pointer `p` such that `p + i == &operator[](i)` for each
1711
- `i` in \[`0`, `size()`\].
1712
 
1713
  *Complexity:* Constant time.
1714
 
1715
- *Requires:* The program shall not alter the value stored at
1716
- `p + size()`.
1717
 
1718
  ``` cpp
1719
- operator basic_string_view<charT, traits>() const noexcept;
1720
  ```
1721
 
1722
  *Effects:* Equivalent to:
1723
  `return basic_string_view<charT, traits>(data(), size());`
1724
 
1725
  ``` cpp
1726
- allocator_type get_allocator() const noexcept;
1727
  ```
1728
 
1729
  *Returns:* A copy of the `Allocator` object used to construct the string
1730
  or, if that allocator has been replaced, a copy of the most recent
1731
  replacement.
1732
 
1733
- ##### `basic_string::find` <a id="string.find">[[string.find]]</a>
1734
 
1735
- ``` cpp
1736
- size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
1737
- ```
1738
-
1739
- *Effects:* Determines the lowest position `xpos`, if possible, such that
1740
- both of the following conditions hold:
1741
-
1742
- - `pos <= xpos` and `xpos + sv.size() <= size()`;
1743
- - `traits::eq(at(xpos + I), sv.at(I))` for all elements `I` of the data
1744
- referenced by `sv`.
1745
-
1746
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1747
- Otherwise, returns `npos`.
1748
-
1749
- ``` cpp
1750
- size_type find(const basic_string& str, size_type pos = 0) const noexcept;
1751
- ```
1752
-
1753
- *Effects:* Equivalent to:
1754
- `return find(basic_string_view<charT, traits>(str), pos);`
1755
-
1756
- ``` cpp
1757
- size_type find(const charT* s, size_type pos, size_type n) const;
1758
- ```
1759
-
1760
- *Returns:* `find(basic_string_view<charT, traits>(s, n), pos)`.
1761
-
1762
- ``` cpp
1763
- size_type find(const charT* s, size_type pos = 0) const;
1764
- ```
1765
-
1766
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1767
- elements of `charT`.
1768
-
1769
- *Returns:* `find(basic_string_view<charT, traits>(s), pos)`.
1770
-
1771
- ``` cpp
1772
- size_type find(charT c, size_type pos = 0) const;
1773
- ```
1774
-
1775
- *Returns:* `find(basic_string(1, c), pos)`.
1776
-
1777
- ##### `basic_string::rfind` <a id="string.rfind">[[string.rfind]]</a>
1778
-
1779
- ``` cpp
1780
- size_type rfind(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
1781
- ```
1782
-
1783
- *Effects:* Determines the highest position `xpos`, if possible, such
1784
- that both of the following conditions hold:
1785
-
1786
- - `xpos <= pos` and `xpos + sv.size() <= size()`;
1787
- - `traits::eq(at(xpos + I), sv.at(I))` for all elements `I` of the data
1788
- referenced by `sv`.
1789
-
1790
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1791
- Otherwise, returns `npos`.
1792
-
1793
- ``` cpp
1794
- size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
1795
- ```
1796
-
1797
- *Effects:* Equivalent to:
1798
- `return rfind(basic_string_view<charT, traits>(str), pos);`
1799
-
1800
- ``` cpp
1801
- size_type rfind(const charT* s, size_type pos, size_type n) const;
1802
- ```
1803
-
1804
- *Returns:* `rfind(basic_string_view<charT, traits>(s, n), pos)`.
1805
 
 
1806
  ``` cpp
1807
- size_type rfind(const charT* s, size_type pos = npos) const;
1808
  ```
1809
 
1810
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1811
- elements of `charT`.
1812
-
1813
- *Returns:* `rfind(basic_string_view<charT, traits>(s), pos)`.
1814
-
1815
  ``` cpp
1816
- size_type rfind(charT c, size_type pos = npos) const;
1817
  ```
1818
 
1819
- *Returns:* `rfind(basic_string(1, c), pos)`.
1820
-
1821
- ##### `basic_string::find_first_of` <a id="string.find.first.of">[[string.find.first.of]]</a>
1822
-
1823
  ``` cpp
1824
- size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
1825
  ```
1826
 
1827
- *Effects:* Determines the lowest position `xpos`, if possible, such that
1828
- both of the following conditions hold:
1829
-
1830
- - `pos <= xpos` and `xpos < size()`;
1831
- - `traits::eq(at(xpos), sv.at(I))` for some element `I` of the data
1832
- referenced by `sv`.
1833
-
1834
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1835
- Otherwise, returns `npos`.
1836
-
1837
  ``` cpp
1838
- size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
1839
  ```
1840
 
1841
- *Effects:* Equivalent to:
1842
- `return find_first_of(basic_string_view<charT, traits>(str), pos);`
1843
-
1844
  ``` cpp
1845
- size_type find_first_of(const charT* s, size_type pos, size_type n) const;
1846
  ```
1847
 
1848
- *Returns:* `find_first_of(basic_string_view<charT, traits>(s, n), pos)`.
1849
-
1850
- ``` cpp
1851
- size_type find_first_of(const charT* s, size_type pos = 0) const;
1852
- ```
1853
-
1854
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1855
- elements of `charT`.
1856
-
1857
- *Returns:* `find_first_of(basic_string_view<charT, traits>(s), pos)`.
1858
-
1859
- ``` cpp
1860
- size_type find_first_of(charT c, size_type pos = 0) const;
1861
- ```
1862
-
1863
- *Returns:* `find_first_of(basic_string(1, c), pos)`.
1864
-
1865
- ##### `basic_string::find_last_of` <a id="string.find.last.of">[[string.find.last.of]]</a>
1866
-
1867
- ``` cpp
1868
- size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
1869
- ```
1870
-
1871
- *Effects:* Determines the highest position `xpos`, if possible, such
1872
- that both of the following conditions hold:
1873
-
1874
- - `xpos <= pos` and `xpos < size()`;
1875
- - `traits::eq(at(xpos), sv.at(I))` for some element `I` of the data
1876
- referenced by `sv`.
1877
-
1878
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1879
- Otherwise, returns `npos`.
1880
-
1881
  ``` cpp
1882
- size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
 
 
 
 
 
 
 
 
 
 
 
1883
  ```
1884
 
1885
- *Effects:* Equivalent to:
1886
- `return find_last_of(basic_string_view<charT, traits>(str), pos);`
1887
-
1888
- ``` cpp
1889
- size_type find_last_of(const charT* s, size_type pos, size_type n) const;
1890
- ```
1891
-
1892
- *Returns:* `find_last_of(basic_string_view<charT, traits>(s, n), pos)`.
1893
-
1894
- ``` cpp
1895
- size_type find_last_of(const charT* s, size_type pos = npos) const;
1896
- ```
1897
-
1898
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1899
- elements of `charT`.
1900
-
1901
- *Returns:* `find_last_of(basic_string_view<charT, traits>(s), pos)`.
1902
-
1903
- ``` cpp
1904
- size_type find_last_of(charT c, size_type pos = npos) const;
1905
- ```
1906
-
1907
- *Returns:* `find_last_of(basic_string(1, c), pos)`.
1908
-
1909
- ##### `basic_string::find_first_not_of` <a id="string.find.first.not.of">[[string.find.first.not.of]]</a>
1910
-
1911
- ``` cpp
1912
- size_type find_first_not_of(basic_string_view<charT, traits> sv,
1913
- size_type pos = 0) const noexcept;
1914
- ```
1915
-
1916
- *Effects:* Determines the lowest position `xpos`, if possible, such that
1917
- both of the following conditions hold:
1918
-
1919
- - `pos <= xpos` and `xpos < size()`;
1920
- - `traits::eq(at(xpos), sv.at(I))` for no element `I` of the data
1921
- referenced by `sv`.
1922
-
1923
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1924
- Otherwise, returns `npos`.
1925
-
1926
- ``` cpp
1927
- size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
1928
- ```
1929
-
1930
- *Effects:* Equivalent to:
1931
-
1932
- ``` cpp
1933
- return find_first_not_of(basic_string_view<charT, traits>(str), pos);
1934
- ```
1935
-
1936
- ``` cpp
1937
- size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
1938
- ```
1939
-
1940
- *Returns:*
1941
- `find_first_not_of(basic_string_view<charT, traits>(s, n), pos)`.
1942
-
1943
- ``` cpp
1944
- size_type find_first_not_of(const charT* s, size_type pos = 0) const;
1945
- ```
1946
-
1947
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1948
- elements of `charT`.
1949
-
1950
- *Returns:*
1951
- `find_first_not_of(basic_string_view<charT, traits>(s), pos)`.
1952
-
1953
- ``` cpp
1954
- size_type find_first_not_of(charT c, size_type pos = 0) const;
1955
- ```
1956
-
1957
- *Returns:* `find_first_not_of(basic_string(1, c), pos)`.
1958
-
1959
- ##### `basic_string::find_last_not_of` <a id="string.find.last.not.of">[[string.find.last.not.of]]</a>
1960
-
1961
- ``` cpp
1962
- size_type find_last_not_of(basic_string_view<charT, traits> sv,
1963
- size_type pos = npos) const noexcept;
1964
- ```
1965
-
1966
- *Effects:* Determines the highest position `xpos`, if possible, such
1967
- that both of the following conditions hold:
1968
-
1969
- - `xpos <= pos` and `xpos < size()`;
1970
- - `traits::eq(at(xpos), sv.at(I))` for no element `I` of the data
1971
- referenced by `sv`.
1972
-
1973
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
1974
- Otherwise, returns `npos`.
1975
-
1976
- ``` cpp
1977
- size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
1978
- ```
1979
-
1980
- *Effects:* Equivalent to:
1981
-
1982
- ``` cpp
1983
- return find_last_not_of(basic_string_view<charT, traits>(str), pos);
1984
- ```
1985
-
1986
- ``` cpp
1987
- size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
1988
- ```
1989
-
1990
- *Returns:*
1991
- `find_last_not_of(basic_string_view<charT, traits>(s, n), pos)`.
1992
-
1993
- ``` cpp
1994
- size_type find_last_not_of(const charT* s, size_type pos = npos) const;
1995
- ```
1996
 
1997
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
1998
- elements of `charT`.
 
1999
 
2000
- *Returns:* `find_last_not_of(basic_string_view<charT, traits>(s), pos)`.
2001
 
2002
  ``` cpp
2003
- size_type find_last_not_of(charT c, size_type pos = npos) const;
 
2004
  ```
2005
 
2006
- *Returns:* `find_last_not_of(basic_string(1, c), pos)`.
 
2007
 
2008
  ##### `basic_string::substr` <a id="string.substr">[[string.substr]]</a>
2009
 
2010
  ``` cpp
2011
- basic_string substr(size_type pos = 0, size_type n = npos) const;
2012
  ```
2013
 
2014
  *Throws:* `out_of_range` if `pos > size()`.
2015
 
2016
  *Effects:* Determines the effective length `rlen` of the string to copy
@@ -2019,409 +1729,327 @@ as the smaller of `n` and `size() - pos`.
2019
  *Returns:* `basic_string(data()+pos, rlen)`.
2020
 
2021
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
2022
 
2023
  ``` cpp
2024
- int compare(basic_string_view<charT, traits> sv) const noexcept;
 
2025
  ```
2026
 
2027
- *Effects:* Determines the effective length `rlen` of the strings to
2028
- compare as the smaller of `size()` and `sv.size()`. The function then
2029
- compares the two strings by calling
2030
- `traits::compare(data(), sv.data(), rlen)`.
2031
 
2032
- *Returns:* The nonzero result if the result of the comparison is
2033
- nonzero. Otherwise, returns a value as indicated in
2034
- Table  [[tab:strings.compare]].
2035
 
2036
- **Table: `compare()` results** <a id="tab:strings.compare">[tab:strings.compare]</a>
 
2037
 
2038
- | Condition | Return Value |
2039
- | --------------------- | ------------ |
2040
- | `size() < sv.size()` | `< 0` |
2041
- | `size() == sv.size()` | ` 0` |
2042
- | `size() > sv.size()` | `> 0` |
2043
 
2044
  ``` cpp
2045
- int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
 
2046
  ```
2047
 
 
 
 
 
 
 
2048
  *Effects:* Equivalent to:
2049
 
2050
  ``` cpp
2051
- return basic_string_view<charT, traits>(data(), size()).substr(pos1, n1).compare(sv);
2052
  ```
2053
 
2054
  ``` cpp
2055
  template<class T>
2056
- int compare(size_type pos1, size_type n1, const T& t,
2057
  size_type pos2, size_type n2 = npos) const;
2058
  ```
2059
 
 
 
 
 
 
 
2060
  *Effects:* Equivalent to:
2061
 
2062
  ``` cpp
2063
- basic_string_view<charT, traits> sv = t;
2064
- return basic_string_view<charT, traits>(
2065
- data(), size()).substr(pos1, n1).compare(sv.substr(pos2, n2));
2066
  ```
2067
 
2068
- *Remarks:* This function shall not participate in overload resolution
2069
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
2070
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
2071
-
2072
  ``` cpp
2073
- int compare(const basic_string& str) const noexcept;
2074
  ```
2075
 
2076
  *Effects:* Equivalent to:
2077
  `return compare(basic_string_view<charT, traits>(str));`
2078
 
2079
  ``` cpp
2080
- int compare(size_type pos1, size_type n1, const basic_string& str) const;
2081
  ```
2082
 
2083
  *Effects:* Equivalent to:
2084
  `return compare(pos1, n1, basic_string_view<charT, traits>(str));`
2085
 
2086
  ``` cpp
2087
- int compare(size_type pos1, size_type n1,
2088
- const basic_string& str,
2089
  size_type pos2, size_type n2 = npos) const;
2090
  ```
2091
 
2092
  *Effects:* Equivalent to:
2093
 
2094
  ``` cpp
2095
  return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);
2096
  ```
2097
 
2098
  ``` cpp
2099
- int compare(const charT* s) const;
2100
  ```
2101
 
2102
- *Returns:* `compare(basic_string(s))`.
 
2103
 
2104
  ``` cpp
2105
- int compare(size_type pos, size_type n1, const charT* s) const;
2106
  ```
2107
 
2108
- *Returns:* `basic_string(*this, pos, n1).compare(basic_string(s))`.
 
2109
 
2110
  ``` cpp
2111
- int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
2112
  ```
2113
 
2114
- *Returns:* `basic_string(*this, pos, n1).compare(basic_string(s, n2))`.
 
2115
 
2116
- ### `basic_string` non-member functions <a id="string.nonmembers">[[string.nonmembers]]</a>
2117
-
2118
- #### `operator+` <a id="string.op+">[[string.op+]]</a>
2119
 
2120
  ``` cpp
2121
- template<class charT, class traits, class Allocator>
2122
- basic_string<charT, traits, Allocator>
2123
- operator+(const basic_string<charT, traits, Allocator>& lhs,
2124
- const basic_string<charT, traits, Allocator>& rhs);
2125
  ```
2126
 
2127
- *Returns:* `basic_string<charT, traits, Allocator>(lhs).append(rhs)`.
2128
 
2129
  ``` cpp
2130
- template<class charT, class traits, class Allocator>
2131
- basic_string<charT, traits, Allocator>
2132
- operator+(basic_string<charT, traits, Allocator>&& lhs,
2133
- const basic_string<charT, traits, Allocator>& rhs);
2134
  ```
2135
 
2136
- *Returns:* `std::move(lhs.append(rhs))`.
2137
 
2138
  ``` cpp
2139
- template<class charT, class traits, class Allocator>
2140
- basic_string<charT, traits, Allocator>
2141
- operator+(const basic_string<charT, traits, Allocator>& lhs,
2142
- basic_string<charT, traits, Allocator>&& rhs);
2143
  ```
2144
 
2145
- *Returns:* `std::move(rhs.insert(0, lhs))`.
2146
 
2147
  ``` cpp
2148
- template<class charT, class traits, class Allocator>
2149
- basic_string<charT, traits, Allocator>
2150
- operator+(basic_string<charT, traits, Allocator>&& lhs,
2151
- basic_string<charT, traits, Allocator>&& rhs);
2152
  ```
2153
 
2154
- *Returns:* `std::move(lhs.append(rhs))`.
2155
 
2156
- [*Note 1*: Or equivalently,
2157
- `std::move(rhs.insert(0, lhs))`. — *end note*]
2158
 
2159
  ``` cpp
2160
  template<class charT, class traits, class Allocator>
2161
- basic_string<charT, traits, Allocator>
2162
- operator+(const charT* lhs,
2163
  const basic_string<charT, traits, Allocator>& rhs);
 
 
 
2164
  ```
2165
 
2166
- *Returns:* `basic_string<charT, traits, Allocator>(lhs) + rhs`.
2167
-
2168
- *Remarks:* Uses `traits::length()`.
2169
 
2170
  ``` cpp
2171
- template<class charT, class traits, class Allocator>
2172
- basic_string<charT, traits, Allocator>
2173
- operator+(const charT* lhs,
2174
- basic_string<charT, traits, Allocator>&& rhs);
2175
  ```
2176
 
2177
- *Returns:* `std::move(rhs.insert(0, lhs))`.
2178
-
2179
- *Remarks:* Uses `traits::length()`.
2180
-
2181
  ``` cpp
2182
  template<class charT, class traits, class Allocator>
2183
- basic_string<charT, traits, Allocator>
2184
- operator+(charT lhs,
2185
  const basic_string<charT, traits, Allocator>& rhs);
2186
- ```
2187
-
2188
- *Returns:* `basic_string<charT, traits, Allocator>(1, lhs) + rhs`.
2189
-
2190
- ``` cpp
2191
  template<class charT, class traits, class Allocator>
2192
- basic_string<charT, traits, Allocator>
2193
- operator+(charT lhs,
2194
- basic_string<charT, traits, Allocator>&& rhs);
2195
  ```
2196
 
2197
- *Returns:* `std::move(rhs.insert(0, 1, lhs))`.
2198
 
2199
  ``` cpp
2200
- template<class charT, class traits, class Allocator>
2201
- basic_string<charT, traits, Allocator>
2202
- operator+(const basic_string<charT, traits, Allocator>& lhs,
2203
- const charT* rhs);
2204
  ```
2205
 
2206
- *Returns:* `lhs + basic_string<charT, traits, Allocator>(rhs)`.
2207
-
2208
- *Remarks:* Uses `traits::length()`.
2209
-
2210
  ``` cpp
2211
  template<class charT, class traits, class Allocator>
2212
- basic_string<charT, traits, Allocator>
2213
  operator+(basic_string<charT, traits, Allocator>&& lhs,
2214
- const charT* rhs);
2215
- ```
2216
-
2217
- *Returns:* `std::move(lhs.append(rhs))`.
2218
-
2219
- *Remarks:* Uses `traits::length()`.
2220
-
2221
- ``` cpp
2222
- template<class charT, class traits, class Allocator>
2223
- basic_string<charT, traits, Allocator>
2224
- operator+(const basic_string<charT, traits, Allocator>& lhs,
2225
- charT rhs);
2226
  ```
2227
 
2228
- *Returns:* `lhs + basic_string<charT, traits, Allocator>(1, rhs)`.
2229
 
2230
  ``` cpp
2231
- template<class charT, class traits, class Allocator>
2232
- basic_string<charT, traits, Allocator>
2233
- operator+(basic_string<charT, traits, Allocator>&& lhs,
2234
- charT rhs);
2235
  ```
2236
 
2237
- *Returns:* `std::move(lhs.append(1, rhs))`.
 
2238
 
2239
- #### `operator==` <a id="string.operator==">[[string.operator==]]</a>
 
2240
 
2241
  ``` cpp
2242
  template<class charT, class traits, class Allocator>
2243
- bool operator==(const basic_string<charT, traits, Allocator>& lhs,
2244
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
2245
- ```
2246
-
2247
- *Returns:* `lhs.compare(rhs) == 0`.
2248
-
2249
- ``` cpp
2250
  template<class charT, class traits, class Allocator>
2251
- bool operator==(const charT* lhs,
2252
- const basic_string<charT, traits, Allocator>& rhs);
2253
  ```
2254
 
2255
- *Returns:* `rhs == lhs`.
2256
 
2257
  ``` cpp
2258
- template<class charT, class traits, class Allocator>
2259
- bool operator==(const basic_string<charT, traits, Allocator>& lhs,
2260
- const charT* rhs);
2261
  ```
2262
 
2263
- *Requires:* `rhs` points to an array of at least
2264
- `traits::length(rhs) + 1` elements of `charT`.
2265
-
2266
- *Returns:* `lhs.compare(rhs) == 0`.
2267
-
2268
- #### `operator!=` <a id="string.op!=">[[string.op!=]]</a>
2269
-
2270
  ``` cpp
2271
  template<class charT, class traits, class Allocator>
2272
- bool operator!=(const basic_string<charT, traits, Allocator>& lhs,
2273
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
2274
  ```
2275
 
2276
- *Returns:* `!(lhs == rhs)`.
2277
 
2278
  ``` cpp
2279
- template<class charT, class traits, class Allocator>
2280
- bool operator!=(const charT* lhs,
2281
- const basic_string<charT, traits, Allocator>& rhs);
2282
  ```
2283
 
2284
- *Returns:* `rhs != lhs`.
2285
-
2286
  ``` cpp
2287
  template<class charT, class traits, class Allocator>
2288
- bool operator!=(const basic_string<charT, traits, Allocator>& lhs,
2289
- const charT* rhs);
2290
  ```
2291
 
2292
- *Requires:* `rhs` points to an array of at least
2293
- `traits::length(rhs) + 1` elements of `charT`.
2294
-
2295
- *Returns:* `lhs.compare(rhs) != 0`.
2296
-
2297
- #### `operator<` <a id="string.op<">[[string.op<]]</a>
2298
 
2299
  ``` cpp
2300
- template<class charT, class traits, class Allocator>
2301
- bool operator< (const basic_string<charT, traits, Allocator>& lhs,
2302
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
2303
  ```
2304
 
2305
- *Returns:* `lhs.compare(rhs) < 0`.
2306
-
2307
  ``` cpp
2308
  template<class charT, class traits, class Allocator>
2309
- bool operator< (const charT* lhs,
2310
- const basic_string<charT, traits, Allocator>& rhs);
2311
  ```
2312
 
2313
- *Returns:* `rhs.compare(lhs) > 0`.
2314
 
2315
  ``` cpp
2316
- template<class charT, class traits, class Allocator>
2317
- bool operator< (const basic_string<charT, traits, Allocator>& lhs,
2318
- const charT* rhs);
2319
  ```
2320
 
2321
- *Returns:* `lhs.compare(rhs) < 0`.
2322
-
2323
- #### `operator>` <a id="string.op>">[[string.op>]]</a>
2324
-
2325
  ``` cpp
2326
  template<class charT, class traits, class Allocator>
2327
- bool operator> (const basic_string<charT, traits, Allocator>& lhs,
2328
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
2329
  ```
2330
 
2331
- *Returns:* `lhs.compare(rhs) > 0`.
2332
 
2333
  ``` cpp
2334
- template<class charT, class traits, class Allocator>
2335
- bool operator> (const charT* lhs,
2336
- const basic_string<charT, traits, Allocator>& rhs);
2337
  ```
2338
 
2339
- *Returns:* `rhs.compare(lhs) < 0`.
2340
-
2341
  ``` cpp
2342
  template<class charT, class traits, class Allocator>
2343
- bool operator> (const basic_string<charT, traits, Allocator>& lhs,
2344
- const charT* rhs);
2345
  ```
2346
 
2347
- *Returns:* `lhs.compare(rhs) > 0`.
2348
-
2349
- #### `operator<=` <a id="string.op<=">[[string.op<=]]</a>
2350
 
2351
  ``` cpp
2352
- template<class charT, class traits, class Allocator>
2353
- bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
2354
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
2355
  ```
2356
 
2357
- *Returns:* `lhs.compare(rhs) <= 0`.
2358
 
2359
  ``` cpp
2360
  template<class charT, class traits, class Allocator>
2361
- bool operator<=(const charT* lhs,
2362
- const basic_string<charT, traits, Allocator>& rhs);
2363
- ```
2364
-
2365
- *Returns:* `rhs.compare(lhs) >= 0`.
2366
-
2367
- ``` cpp
2368
  template<class charT, class traits, class Allocator>
2369
- bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
2370
  const charT* rhs);
2371
- ```
2372
 
2373
- *Returns:* `lhs.compare(rhs) <= 0`.
2374
-
2375
- #### `operator>=` <a id="string.op>=">[[string.op>=]]</a>
2376
-
2377
- ``` cpp
2378
  template<class charT, class traits, class Allocator>
2379
- bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
2380
- const basic_string<charT, traits, Allocator>& rhs) noexcept;
2381
- ```
2382
-
2383
- *Returns:* `lhs.compare(rhs) >= 0`.
2384
-
2385
- ``` cpp
2386
  template<class charT, class traits, class Allocator>
2387
- bool operator>=(const charT* lhs,
2388
- const basic_string<charT, traits, Allocator>& rhs);
2389
  ```
2390
 
2391
- *Returns:* `rhs.compare(lhs) <= 0`.
2392
 
2393
  ``` cpp
2394
- template<class charT, class traits, class Allocator>
2395
- bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
2396
- const charT* rhs);
2397
  ```
2398
 
2399
- *Returns:* `lhs.compare(rhs) >= 0`.
2400
-
2401
  #### `swap` <a id="string.special">[[string.special]]</a>
2402
 
2403
  ``` cpp
2404
  template<class charT, class traits, class Allocator>
2405
- void swap(basic_string<charT, traits, Allocator>& lhs,
 
2406
  basic_string<charT, traits, Allocator>& rhs)
2407
  noexcept(noexcept(lhs.swap(rhs)));
2408
  ```
2409
 
2410
- *Effects:* Equivalent to: `lhs.swap(rhs);`
2411
 
2412
  #### Inserters and extractors <a id="string.io">[[string.io]]</a>
2413
 
2414
  ``` cpp
2415
  template<class charT, class traits, class Allocator>
2416
  basic_istream<charT, traits>&
2417
- operator>>(basic_istream<charT, traits>& is,
2418
- basic_string<charT, traits, Allocator>& str);
2419
  ```
2420
 
2421
  *Effects:* Behaves as a formatted input
2422
- function ([[istream.formatted.reqmts]]). After constructing a `sentry`
2423
  object, if the sentry converts to `true`, calls `str.erase()` and then
2424
  extracts characters from `is` and appends them to `str` as if by calling
2425
  `str.append(1, c)`. If `is.width()` is greater than zero, the maximum
2426
  number `n` of characters appended is `is.width()`; otherwise `n` is
2427
  `str.max_size()`. Characters are extracted and appended until any of the
@@ -2434,12 +2062,12 @@ following occurs:
2434
 
2435
  After the last character (if any) is extracted, `is.width(0)` is called
2436
  and the `sentry` object is destroyed.
2437
 
2438
  If the function extracts no characters, it calls
2439
- `is.setstate(ios::failbit)`, which may throw
2440
- `ios_base::failure` ([[iostate.flags]]).
2441
 
2442
  *Returns:* `is`.
2443
 
2444
  ``` cpp
2445
  template<class charT, class traits, class Allocator>
@@ -2463,30 +2091,30 @@ template<class charT, class traits, class Allocator>
2463
  basic_string<charT, traits, Allocator>& str,
2464
  charT delim);
2465
  ```
2466
 
2467
  *Effects:* Behaves as an unformatted input
2468
- function ([[istream.unformatted]]), except that it does not affect the
2469
  value returned by subsequent calls to `basic_istream<>::gcount()`. After
2470
  constructing a `sentry` object, if the sentry converts to `true`, calls
2471
  `str.erase()` and then extracts characters from `is` and appends them to
2472
  `str` as if by calling `str.append(1, c)` until any of the following
2473
  occurs:
2474
 
2475
  - end-of-file occurs on the input sequence (in which case, the `getline`
2476
  function calls `is.setstate(ios_base::eofbit)`).
2477
  - `traits::eq(c, delim)` for the next available input character *c* (in
2478
- which case, *c* is extracted but not appended) ([[iostate.flags]])
2479
  - `str.max_size()` characters are stored (in which case, the function
2480
- calls `is.setstate(ios_base::failbit))` ([[iostate.flags]])
2481
 
2482
  The conditions are tested in the order shown. In any case, after the
2483
  last character is extracted, the `sentry` object is destroyed.
2484
 
2485
  If the function extracts no characters, it calls
2486
- `is.setstate(ios_base::failbit)` which may throw
2487
- `ios_base::failure` ([[iostate.flags]]).
2488
 
2489
  *Returns:* `is`.
2490
 
2491
  ``` cpp
2492
  template<class charT, class traits, class Allocator>
@@ -2499,21 +2127,53 @@ template<class charT, class traits, class Allocator>
2499
  basic_string<charT, traits, Allocator>& str);
2500
  ```
2501
 
2502
  *Returns:* `getline(is, str, is.widen(’\n’))`.
2503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2504
  ### Numeric conversions <a id="string.conversions">[[string.conversions]]</a>
2505
 
2506
  ``` cpp
2507
- int stoi(const string& str, size_t* idx = 0, int base = 10);
2508
- long stol(const string& str, size_t* idx = 0, int base = 10);
2509
- unsigned long stoul(const string& str, size_t* idx = 0, int base = 10);
2510
- long long stoll(const string& str, size_t* idx = 0, int base = 10);
2511
- unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
2512
  ```
2513
 
2514
- *Effects:* the first two functions call
2515
  `strtol(str.c_str(), ptr, base)`, and the last three functions call
2516
  `strtoul(str.c_str(), ptr, base)`, `strtoll(str.c_str(), ptr, base)`,
2517
  and `strtoull(str.c_str(), ptr, base)`, respectively. Each function
2518
  returns the converted result, if any. The argument `ptr` designates a
2519
  pointer to an object internal to the function that is used to determine
@@ -2528,13 +2188,13 @@ unconverted element of `str`.
2528
  `out_of_range` if `strtol`, `strtoul`, `strtoll` or `strtoull` sets
2529
  `errno` to `ERANGE`, or if the converted value is outside the range of
2530
  representable values for the return type.
2531
 
2532
  ``` cpp
2533
- float stof(const string& str, size_t* idx = 0);
2534
- double stod(const string& str, size_t* idx = 0);
2535
- long double stold(const string& str, size_t* idx = 0);
2536
  ```
2537
 
2538
  *Effects:* These functions call `strtof(str.c_str(), ptr)`,
2539
  `strtod(str.c_str(), ptr)`, and `strtold(str.c_str(), ptr)`,
2540
  respectively. Each function returns the converted result, if any. The
@@ -2569,18 +2229,18 @@ calling `sprintf(buf, fmt, val)` with a format specifier of `"%d"`,
2569
  `"%u"`, `"%ld"`, `"%lu"`, `"%lld"`, `"%llu"`, `"%f"`, `"%f"`, or
2570
  `"%Lf"`, respectively, where `buf` designates an internal character
2571
  buffer of sufficient size.
2572
 
2573
  ``` cpp
2574
- int stoi(const wstring& str, size_t* idx = 0, int base = 10);
2575
- long stol(const wstring& str, size_t* idx = 0, int base = 10);
2576
- unsigned long stoul(const wstring& str, size_t* idx = 0, int base = 10);
2577
- long long stoll(const wstring& str, size_t* idx = 0, int base = 10);
2578
- unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
2579
  ```
2580
 
2581
- *Effects:* the first two functions call
2582
  `wcstol(str.c_str(), ptr, base)`, and the last three functions call
2583
  `wcstoul(str.c_str(), ptr, base)`, `wcstoll(str.c_str(), ptr, base)`,
2584
  and `wcstoull(str.c_str(), ptr, base)`, respectively. Each function
2585
  returns the converted result, if any. The argument `ptr` designates a
2586
  pointer to an object internal to the function that is used to determine
@@ -2594,13 +2254,13 @@ unconverted element of `str`.
2594
  `wcstoull` reports that no conversion could be performed. Throws
2595
  `out_of_range` if the converted value is outside the range of
2596
  representable values for the return type.
2597
 
2598
  ``` cpp
2599
- float stof(const wstring& str, size_t* idx = 0);
2600
- double stod(const wstring& str, size_t* idx = 0);
2601
- long double stold(const wstring& str, size_t* idx = 0);
2602
  ```
2603
 
2604
  *Effects:* These functions call `wcstof(str.c_str(), ptr)`,
2605
  `wcstod(str.c_str(), ptr)`, and `wcstold(str.c_str(), ptr)`,
2606
  respectively. Each function returns the converted result, if any. The
@@ -2636,41 +2296,53 @@ internal character buffer of sufficient size `buffsz`.
2636
 
2637
  ### Hash support <a id="basic.string.hash">[[basic.string.hash]]</a>
2638
 
2639
  ``` cpp
2640
  template<> struct hash<string>;
 
2641
  template<> struct hash<u16string>;
2642
  template<> struct hash<u32string>;
2643
  template<> struct hash<wstring>;
 
 
 
 
 
2644
  ```
2645
 
2646
  If `S` is one of these string types, `SV` is the corresponding string
2647
  view type, and `s` is an object of type `S`, then
2648
  `hash<S>()(s) == hash<SV>()(SV(s))`.
2649
 
2650
  ### Suffix for `basic_string` literals <a id="basic.string.literals">[[basic.string.literals]]</a>
2651
 
2652
  ``` cpp
2653
- string operator""s(const char* str, size_t len);
2654
  ```
2655
 
2656
  *Returns:* `string{str, len}`.
2657
 
2658
  ``` cpp
2659
- u16string operator""s(const char16_t* str, size_t len);
 
 
 
 
 
 
2660
  ```
2661
 
2662
  *Returns:* `u16string{str, len}`.
2663
 
2664
  ``` cpp
2665
- u32string operator""s(const char32_t* str, size_t len);
2666
  ```
2667
 
2668
  *Returns:* `u32string{str, len}`.
2669
 
2670
  ``` cpp
2671
- wstring operator""s(const wchar_t* str, size_t len);
2672
  ```
2673
 
2674
  *Returns:* `wstring{str, len}`.
2675
 
2676
  [*Note 1*: The same suffix `s` is used for `chrono::duration` literals
 
1
  ## String classes <a id="string.classes">[[string.classes]]</a>
2
 
3
  The header `<string>` defines the `basic_string` class template for
4
+ manipulating varying-length sequences of char-like objects and five
5
+ *typedef-name*s, `string`, `u8string`, `u16string`, `u32string`, and
6
+ `wstring`, that name the specializations `basic_string<char>`,
7
+ `basic_string<char8_t>`, `basic_string<char16_t>`,
8
  `basic_string<char32_t>`, and `basic_string<{}wchar_t>`, respectively.
9
 
10
  ### Header `<string>` synopsis <a id="string.syn">[[string.syn]]</a>
11
 
12
  ``` cpp
13
+ #include <compare> // see [compare.syn]
14
+ #include <initializer_list> // see [initializer.list.syn]
15
 
16
  namespace std {
17
  // [char.traits], character traits
18
  template<class charT> struct char_traits;
19
  template<> struct char_traits<char>;
20
+ template<> struct char_traits<char8_t>;
21
  template<> struct char_traits<char16_t>;
22
  template<> struct char_traits<char32_t>;
23
  template<> struct char_traits<wchar_t>;
24
 
25
  // [basic.string], basic_string
26
+ template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>
 
27
  class basic_string;
28
 
29
  template<class charT, class traits, class Allocator>
30
+ constexpr basic_string<charT, traits, Allocator>
31
  operator+(const basic_string<charT, traits, Allocator>& lhs,
32
  const basic_string<charT, traits, Allocator>& rhs);
33
  template<class charT, class traits, class Allocator>
34
+ constexpr basic_string<charT, traits, Allocator>
35
  operator+(basic_string<charT, traits, Allocator>&& lhs,
36
  const basic_string<charT, traits, Allocator>& rhs);
37
  template<class charT, class traits, class Allocator>
38
+ constexpr basic_string<charT, traits, Allocator>
39
  operator+(const basic_string<charT, traits, Allocator>& lhs,
40
  basic_string<charT, traits, Allocator>&& rhs);
41
  template<class charT, class traits, class Allocator>
42
+ constexpr basic_string<charT, traits, Allocator>
43
  operator+(basic_string<charT, traits, Allocator>&& lhs,
44
  basic_string<charT, traits, Allocator>&& rhs);
45
  template<class charT, class traits, class Allocator>
46
+ constexpr basic_string<charT, traits, Allocator>
47
  operator+(const charT* lhs,
48
  const basic_string<charT, traits, Allocator>& rhs);
49
  template<class charT, class traits, class Allocator>
50
+ constexpr basic_string<charT, traits, Allocator>
51
  operator+(const charT* lhs,
52
  basic_string<charT, traits, Allocator>&& rhs);
53
  template<class charT, class traits, class Allocator>
54
+ constexpr basic_string<charT, traits, Allocator>
55
+ operator+(charT lhs,
56
+ const basic_string<charT, traits, Allocator>& rhs);
57
  template<class charT, class traits, class Allocator>
58
+ constexpr basic_string<charT, traits, Allocator>
59
+ operator+(charT lhs,
60
+ basic_string<charT, traits, Allocator>&& rhs);
61
  template<class charT, class traits, class Allocator>
62
+ constexpr basic_string<charT, traits, Allocator>
63
  operator+(const basic_string<charT, traits, Allocator>& lhs,
64
  const charT* rhs);
65
  template<class charT, class traits, class Allocator>
66
+ constexpr basic_string<charT, traits, Allocator>
67
  operator+(basic_string<charT, traits, Allocator>&& lhs,
68
  const charT* rhs);
69
  template<class charT, class traits, class Allocator>
70
+ constexpr basic_string<charT, traits, Allocator>
71
+ operator+(const basic_string<charT, traits, Allocator>& lhs,
72
+ charT rhs);
73
  template<class charT, class traits, class Allocator>
74
+ constexpr basic_string<charT, traits, Allocator>
75
+ operator+(basic_string<charT, traits, Allocator>&& lhs,
76
+ charT rhs);
77
 
78
  template<class charT, class traits, class Allocator>
79
+ constexpr bool
80
+ operator==(const basic_string<charT, traits, Allocator>& lhs,
 
 
 
 
 
 
 
 
81
  const basic_string<charT, traits, Allocator>& rhs) noexcept;
82
  template<class charT, class traits, class Allocator>
83
+ constexpr bool operator==(const basic_string<charT, traits, Allocator>& lhs,
 
 
 
84
  const charT* rhs);
85
 
86
  template<class charT, class traits, class Allocator>
87
+ constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs,
88
+ \itcorr const basic_string<charT, traits, Allocator>& rhs) noexcept;
89
  template<class charT, class traits, class Allocator>
90
+ constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs,
91
+ \itcorr const charT* rhs);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  // [string.special], swap
94
  template<class charT, class traits, class Allocator>
95
+ constexpr void
96
+ swap(basic_string<charT, traits, Allocator>& lhs,
97
  basic_string<charT, traits, Allocator>& rhs)
98
  noexcept(noexcept(lhs.swap(rhs)));
99
 
100
  // [string.io], inserters and extractors
101
  template<class charT, class traits, class Allocator>
 
123
  template<class charT, class traits, class Allocator>
124
  basic_istream<charT, traits>&
125
  getline(basic_istream<charT, traits>&& is,
126
  basic_string<charT, traits, Allocator>& str);
127
 
128
+ // [string.erasure], erasure
129
+ template<class charT, class traits, class Allocator, class U>
130
+ constexpr typename basic_string<charT, traits, Allocator>::size_type
131
+ erase(basic_string<charT, traits, Allocator>& c, const U& value);
132
+ template<class charT, class traits, class Allocator, class Predicate>
133
+ constexpr typename basic_string<charT, traits, Allocator>::size_type
134
+ erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred);
135
+
136
  // basic_string typedef names
137
  using string = basic_string<char>;
138
+ using u8string = basic_string<char8_t>;
139
  using u16string = basic_string<char16_t>;
140
  using u32string = basic_string<char32_t>;
141
  using wstring = basic_string<wchar_t>;
142
 
143
  // [string.conversions], numeric conversions
144
+ int stoi(const string& str, size_t* idx = nullptr, int base = 10);
145
+ long stol(const string& str, size_t* idx = nullptr, int base = 10);
146
+ unsigned long stoul(const string& str, size_t* idx = nullptr, int base = 10);
147
+ long long stoll(const string& str, size_t* idx = nullptr, int base = 10);
148
+ unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
149
+ float stof(const string& str, size_t* idx = nullptr);
150
+ double stod(const string& str, size_t* idx = nullptr);
151
+ long double stold(const string& str, size_t* idx = nullptr);
152
  string to_string(int val);
153
  string to_string(unsigned val);
154
  string to_string(long val);
155
  string to_string(unsigned long val);
156
  string to_string(long long val);
157
  string to_string(unsigned long long val);
158
  string to_string(float val);
159
  string to_string(double val);
160
  string to_string(long double val);
161
 
162
+ int stoi(const wstring& str, size_t* idx = nullptr, int base = 10);
163
+ long stol(const wstring& str, size_t* idx = nullptr, int base = 10);
164
+ unsigned long stoul(const wstring& str, size_t* idx = nullptr, int base = 10);
165
+ long long stoll(const wstring& str, size_t* idx = nullptr, int base = 10);
166
+ unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
167
+ float stof(const wstring& str, size_t* idx = nullptr);
168
+ double stod(const wstring& str, size_t* idx = nullptr);
169
+ long double stold(const wstring& str, size_t* idx = nullptr);
170
  wstring to_wstring(int val);
171
  wstring to_wstring(unsigned val);
172
  wstring to_wstring(long val);
173
  wstring to_wstring(unsigned long val);
174
  wstring to_wstring(long long val);
175
  wstring to_wstring(unsigned long long val);
176
  wstring to_wstring(float val);
177
  wstring to_wstring(double val);
178
  wstring to_wstring(long double val);
179
 
 
 
 
 
 
 
 
180
  namespace pmr {
181
  template<class charT, class traits = char_traits<charT>>
182
+ using basic_string = std::basic_string<charT, traits, polymorphic_allocator<charT>>;
 
183
 
184
  using string = basic_string<char>;
185
+ using u8string = basic_string<char8_t>;
186
  using u16string = basic_string<char16_t>;
187
  using u32string = basic_string<char32_t>;
188
  using wstring = basic_string<wchar_t>;
189
  }
190
 
191
+ // [basic.string.hash], hash support
192
+ template<class T> struct hash;
193
+ template<> struct hash<string>;
194
+ template<> struct hash<u8string>;
195
+ template<> struct hash<u16string>;
196
+ template<> struct hash<u32string>;
197
+ template<> struct hash<wstring>;
198
+ template<> struct hash<pmr::string>;
199
+ template<> struct hash<pmr::u8string>;
200
+ template<> struct hash<pmr::u16string>;
201
+ template<> struct hash<pmr::u32string>;
202
+ template<> struct hash<pmr::wstring>;
203
+
204
  inline namespace literals {
205
  inline namespace string_literals {
206
  // [basic.string.literals], suffix for basic_string literals
207
+ constexpr string operator""s(const char* str, size_t len);
208
+ constexpr u8string operator""s(const char8_t* str, size_t len);
209
+ constexpr u16string operator""s(const char16_t* str, size_t len);
210
+ constexpr u32string operator""s(const char32_t* str, size_t len);
211
+ constexpr wstring operator""s(const wchar_t* str, size_t len);
212
  }
213
  }
214
  }
215
  ```
216
 
 
222
  is also called a “string” if the type of the char-like objects that it
223
  holds is clear from context. In the rest of this Clause, the type of the
224
  char-like objects held in a `basic_string` object is designated by
225
  `charT`.
226
 
227
+ A specialization of `basic_string` is a contiguous container
228
+ [[container.requirements.general]].
 
229
 
230
+ In all cases, \[`data()`, `data() + size()`\] is a valid range,
231
+ `data() + size()` points at an object with value `charT()` (a “null
232
+ terminator”), and `size() <= capacity()` is `true`.
 
 
 
 
 
 
 
 
 
233
 
234
  ``` cpp
235
  namespace std {
236
  template<class charT, class traits = char_traits<charT>,
237
  class Allocator = allocator<charT>>
238
  class basic_string {
239
  public:
240
+ // types
241
  using traits_type = traits;
242
  using value_type = charT;
243
  using allocator_type = Allocator;
244
  using size_type = typename allocator_traits<Allocator>::size_type;
245
  using difference_type = typename allocator_traits<Allocator>::difference_type;
 
253
  using reverse_iterator = std::reverse_iterator<iterator>;
254
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
255
  static const size_type npos = -1;
256
 
257
  // [string.cons], construct/copy/destroy
258
+ constexpr basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }
259
+ constexpr explicit basic_string(const Allocator& a) noexcept;
260
+ constexpr basic_string(const basic_string& str);
261
+ constexpr basic_string(basic_string&& str) noexcept;
262
+ constexpr basic_string(const basic_string& str, size_type pos,
263
  const Allocator& a = Allocator());
264
+ constexpr basic_string(const basic_string& str, size_type pos, size_type n,
265
  const Allocator& a = Allocator());
266
  template<class T>
267
+ constexpr basic_string(const T& t, size_type pos, size_type n,
268
  const Allocator& a = Allocator());
269
+ template<class T>
270
+ constexpr explicit basic_string(const T& t, const Allocator& a = Allocator());
271
+ constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
272
+ constexpr basic_string(const charT* s, const Allocator& a = Allocator());
273
+ constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
 
274
  template<class InputIterator>
275
+ constexpr basic_string(InputIterator begin, InputIterator end,
276
  const Allocator& a = Allocator());
277
+ constexpr basic_string(initializer_list<charT>, const Allocator& = Allocator());
278
+ constexpr basic_string(const basic_string&, const Allocator&);
279
+ constexpr basic_string(basic_string&&, const Allocator&);
280
+ constexpr ~basic_string();
281
 
282
+ constexpr basic_string& operator=(const basic_string& str);
283
+ constexpr basic_string& operator=(basic_string&& str)
 
284
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
285
  allocator_traits<Allocator>::is_always_equal::value);
286
+ template<class T>
287
+ constexpr basic_string& operator=(const T& t);
288
+ constexpr basic_string& operator=(const charT* s);
289
+ constexpr basic_string& operator=(charT c);
290
+ constexpr basic_string& operator=(initializer_list<charT>);
291
 
292
  // [string.iterators], iterators
293
+ constexpr iterator begin() noexcept;
294
+ constexpr const_iterator begin() const noexcept;
295
+ constexpr iterator end() noexcept;
296
+ constexpr const_iterator end() const noexcept;
297
 
298
+ constexpr reverse_iterator rbegin() noexcept;
299
+ constexpr const_reverse_iterator rbegin() const noexcept;
300
+ constexpr reverse_iterator rend() noexcept;
301
+ constexpr const_reverse_iterator rend() const noexcept;
302
 
303
+ constexpr const_iterator cbegin() const noexcept;
304
+ constexpr const_iterator cend() const noexcept;
305
+ constexpr const_reverse_iterator crbegin() const noexcept;
306
+ constexpr const_reverse_iterator crend() const noexcept;
307
 
308
  // [string.capacity], capacity
309
+ constexpr size_type size() const noexcept;
310
+ constexpr size_type length() const noexcept;
311
+ constexpr size_type max_size() const noexcept;
312
+ constexpr void resize(size_type n, charT c);
313
+ constexpr void resize(size_type n);
314
+ constexpr size_type capacity() const noexcept;
315
+ constexpr void reserve(size_type res_arg);
316
+ constexpr void shrink_to_fit();
317
+ constexpr void clear() noexcept;
318
+ [[nodiscard]] constexpr bool empty() const noexcept;
319
 
320
  // [string.access], element access
321
+ constexpr const_reference operator[](size_type pos) const;
322
+ constexpr reference operator[](size_type pos);
323
+ constexpr const_reference at(size_type n) const;
324
+ constexpr reference at(size_type n);
325
 
326
+ constexpr const charT& front() const;
327
+ constexpr charT& front();
328
+ constexpr const charT& back() const;
329
+ constexpr charT& back();
330
 
331
  // [string.modifiers], modifiers
332
+ constexpr basic_string& operator+=(const basic_string& str);
 
 
 
 
 
 
 
 
333
  template<class T>
334
+ constexpr basic_string& operator+=(const T& t);
335
+ constexpr basic_string& operator+=(const charT* s);
336
+ constexpr basic_string& operator+=(charT c);
337
+ constexpr basic_string& operator+=(initializer_list<charT>);
338
+ constexpr basic_string& append(const basic_string& str);
339
+ constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
340
+ template<class T>
341
+ constexpr basic_string& append(const T& t);
342
+ template<class T>
343
+ constexpr basic_string& append(const T& t, size_type pos, size_type n = npos);
344
+ constexpr basic_string& append(const charT* s, size_type n);
345
+ constexpr basic_string& append(const charT* s);
346
+ constexpr basic_string& append(size_type n, charT c);
347
  template<class InputIterator>
348
+ constexpr basic_string& append(InputIterator first, InputIterator last);
349
+ constexpr basic_string& append(initializer_list<charT>);
 
350
 
351
+ constexpr void push_back(charT c);
352
+
353
+ constexpr basic_string& assign(const basic_string& str);
354
+ constexpr basic_string& assign(basic_string&& str)
355
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
356
  allocator_traits<Allocator>::is_always_equal::value);
357
+ constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
 
 
358
  template<class T>
359
+ constexpr basic_string& assign(const T& t);
360
+ template<class T>
361
+ constexpr basic_string& assign(const T& t, size_type pos, size_type n = npos);
362
+ constexpr basic_string& assign(const charT* s, size_type n);
363
+ constexpr basic_string& assign(const charT* s);
364
+ constexpr basic_string& assign(size_type n, charT c);
365
  template<class InputIterator>
366
+ constexpr basic_string& assign(InputIterator first, InputIterator last);
367
+ constexpr basic_string& assign(initializer_list<charT>);
368
 
369
+ constexpr basic_string& insert(size_type pos, const basic_string& str);
370
+ constexpr basic_string& insert(size_type pos1, const basic_string& str,
371
  size_type pos2, size_type n = npos);
 
372
  template<class T>
373
+ constexpr basic_string& insert(size_type pos, const T& t);
374
+ template<class T>
375
+ constexpr basic_string& insert(size_type pos1, const T& t,
376
  size_type pos2, size_type n = npos);
377
+ constexpr basic_string& insert(size_type pos, const charT* s, size_type n);
378
+ constexpr basic_string& insert(size_type pos, const charT* s);
379
+ constexpr basic_string& insert(size_type pos, size_type n, charT c);
380
+ constexpr iterator insert(const_iterator p, charT c);
381
+ constexpr iterator insert(const_iterator p, size_type n, charT c);
382
  template<class InputIterator>
383
+ constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
384
+ constexpr iterator insert(const_iterator p, initializer_list<charT>);
385
 
386
+ constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
387
+ constexpr iterator erase(const_iterator p);
388
+ constexpr iterator erase(const_iterator first, const_iterator last);
389
 
390
+ constexpr void pop_back();
391
 
392
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
393
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
 
 
394
  size_type pos2, size_type n2 = npos);
 
 
395
  template<class T>
396
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t);
397
+ template<class T>
398
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t,
399
  size_type pos2, size_type n2 = npos);
400
+ constexpr basic_string& replace(size_type pos, size_type n1, const charT* s, size_type n2);
401
+ constexpr basic_string& replace(size_type pos, size_type n1, const charT* s);
402
+ constexpr basic_string& replace(size_type pos, size_type n1, size_type n2, charT c);
403
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2,
 
 
 
404
  const basic_string& str);
405
+ template<class T>
406
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t);
407
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s,
408
  size_type n);
409
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
410
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
 
411
  template<class InputIterator>
412
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2,
413
  InputIterator j1, InputIterator j2);
414
+ constexpr basic_string& replace(const_iterator, const_iterator, initializer_list<charT>);
415
 
416
+ constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
417
+
418
+ constexpr void swap(basic_string& str)
419
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
420
  allocator_traits<Allocator>::is_always_equal::value);
421
 
422
  // [string.ops], string operations
423
+ constexpr const charT* c_str() const noexcept;
424
+ constexpr const charT* data() const noexcept;
425
+ constexpr charT* data() noexcept;
426
+ constexpr operator basic_string_view<charT, traits>() const noexcept;
427
+ constexpr allocator_type get_allocator() const noexcept;
428
 
429
+ template<class T>
430
+ constexpr size_type find(const T& t, size_type pos = 0) const noexcept(see below);
431
+ constexpr size_type find(const basic_string& str, size_type pos = 0) const noexcept;
432
+ constexpr size_type find(const charT* s, size_type pos, size_type n) const;
433
+ constexpr size_type find(const charT* s, size_type pos = 0) const;
434
+ constexpr size_type find(charT c, size_type pos = 0) const noexcept;
435
+ template<class T>
436
+ constexpr size_type rfind(const T& t, size_type pos = npos) const noexcept(see below);
437
+ constexpr size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
438
+ constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
439
+ constexpr size_type rfind(const charT* s, size_type pos = npos) const;
440
+ constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
441
 
442
+ template<class T>
443
+ constexpr size_type find_first_of(const T& t, size_type pos = 0) const noexcept(see below);
444
+ constexpr size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
445
+ constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
446
+ constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
447
+ constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
448
+ template<class T>
449
+ constexpr size_type find_last_of(const T& t,
450
+ size_type pos = npos) const noexcept(see below);
451
+ constexpr size_type find_last_of(const basic_string& str,
 
452
  size_type pos = npos) const noexcept;
453
+ constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
454
+ constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
455
+ constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
 
456
 
457
+ template<class T>
458
+ constexpr size_type find_first_not_of(const T& t,
459
+ size_type pos = 0) const noexcept(see below);
460
+ constexpr size_type find_first_not_of(const basic_string& str,
461
  size_type pos = 0) const noexcept;
462
+ constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
463
+ constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
464
+ constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
465
+ template<class T>
466
+ constexpr size_type find_last_not_of(const T& t,
467
+ size_type pos = npos) const noexcept(see below);
468
+ constexpr size_type find_last_not_of(const basic_string& str,
469
  size_type pos = npos) const noexcept;
470
+ constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
471
+ constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
472
+ constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
 
 
473
 
474
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) const;
475
+
476
+ template<class T>
477
+ constexpr int compare(const T& t) const noexcept(see below);
478
  template<class T>
479
+ constexpr int compare(size_type pos1, size_type n1, const T& t) const;
480
+ template<class T>
481
+ constexpr int compare(size_type pos1, size_type n1, const T& t,
482
  size_type pos2, size_type n2 = npos) const;
483
+ constexpr int compare(const basic_string& str) const noexcept;
484
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const;
485
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str,
 
 
486
  size_type pos2, size_type n2 = npos) const;
487
+ constexpr int compare(const charT* s) const;
488
+ constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
489
+ constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
490
+
491
+ constexpr bool starts_with(basic_string_view<charT, traits> x) const noexcept;
492
+ constexpr bool starts_with(charT x) const noexcept;
493
+ constexpr bool starts_with(const charT* x) const;
494
+ constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept;
495
+ constexpr bool ends_with(charT x) const noexcept;
496
+ constexpr bool ends_with(const charT* x) const;
497
  };
498
 
499
  template<class InputIterator,
500
  class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
501
  basic_string(InputIterator, InputIterator, Allocator = Allocator())
502
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
503
  char_traits<typename iterator_traits<InputIterator>::value_type>,
504
  Allocator>;
505
+
506
+ template<class charT,
507
+ class traits,
508
+ class Allocator = allocator<charT>>
509
+ explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
510
+ -> basic_string<charT, traits, Allocator>;
511
+
512
+ template<class charT,
513
+ class traits,
514
+ class Allocator = allocator<charT>>
515
+ basic_string(basic_string_view<charT, traits>,
516
+ typename see below::size_type, typename see below::size_type,
517
+ const Allocator& = Allocator())
518
+ -> basic_string<charT, traits, Allocator>;
519
  }
520
  ```
521
 
522
+ A `size_type` parameter type in a `basic_string` deduction guide refers
523
+ to the `size_type` member type of the type deduced by the deduction
524
+ guide.
525
+
526
+ #### General requirements <a id="string.require">[[string.require]]</a>
527
 
528
  If any operation would cause `size()` to exceed `max_size()`, that
529
+ operation throws an exception object of type `length_error`.
530
 
531
  If any member function or operator of `basic_string` throws an
532
+ exception, that function or operator has no other effect on the
533
+ `basic_string` object.
534
 
535
  In every specialization `basic_string<charT, traits, Allocator>`, the
536
  type `allocator_traits<Allocator>::value_type` shall name the same type
537
  as `charT`. Every object of type
538
+ `basic_string<charT, traits, Allocator>` uses an object of type
539
  `Allocator` to allocate and free storage for the contained `charT`
540
+ objects as needed. The `Allocator` object used is obtained as described
541
+ in [[container.requirements.general]]. In every specialization
542
+ `basic_string<charT, traits, Allocator>`, the type `traits` shall meet
543
+ the character traits requirements [[char.traits]].
544
+
545
+ [*Note 1*: The program is ill-formed if `traits::char_type` is not the
546
+ same type as `charT`. — *end note*]
547
 
548
  References, pointers, and iterators referring to the elements of a
549
  `basic_string` sequence may be invalidated by the following uses of that
550
  `basic_string` object:
551
 
552
+ - Passing as an argument to any standard library function taking a
553
+ reference to non-const `basic_string` as an argument.[^2]
554
  - Calling non-const member functions, except `operator[]`, `at`, `data`,
555
  `front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
556
 
557
+ #### Constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
558
 
559
  ``` cpp
560
+ constexpr explicit basic_string(const Allocator& a) noexcept;
561
  ```
562
 
563
+ *Ensures:* `size()` is equal to `0`.
 
 
 
 
 
 
 
 
 
 
564
 
565
  ``` cpp
566
+ constexpr basic_string(const basic_string& str);
567
+ constexpr basic_string(basic_string&& str) noexcept;
568
  ```
569
 
570
+ *Effects:* Constructs an object whose value is that of `str` prior to
571
+ this call.
 
 
 
572
 
573
+ *Remarks:* In the second form, `str` is left in a valid but unspecified
574
+ state.
 
 
 
575
 
576
  ``` cpp
577
+ constexpr basic_string(const basic_string& str, size_type pos,
578
+ const Allocator& a = Allocator());
579
+ constexpr basic_string(const basic_string& str, size_type pos, size_type n,
580
  const Allocator& a = Allocator());
581
  ```
582
 
583
+ *Effects:* Let `n` be `npos` for the first overload. Equivalent to:
 
 
 
 
584
 
585
  ``` cpp
586
+ basic_string(basic_string_view<charT, traits>(str).substr(pos, n), a)
 
587
  ```
588
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
589
  ``` cpp
590
  template<class T>
591
+ constexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
 
592
  ```
593
 
594
+ *Constraints:*
595
+ `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
596
+ `true`.
597
+
598
  *Effects:* Creates a variable, `sv`, as if by
599
  `basic_string_view<charT, traits> sv = t;` and then behaves the same as:
600
 
601
  ``` cpp
602
  basic_string(sv.substr(pos, n), a);
603
  ```
604
 
 
 
 
 
605
  ``` cpp
606
+ template<class T>
607
+ constexpr explicit basic_string(const T& t, const Allocator& a = Allocator());
608
  ```
609
 
610
+ *Constraints:*
611
+
612
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
613
+ `true` and
614
+ - `is_convertible_v<const T&, const charT*>` is `false`.
615
+
616
+ *Effects:* Creates a variable, `sv`, as if by
617
+ `basic_string_view<charT, traits> sv = t;` and then behaves the same as
618
+ `basic_string(sv.data(), sv.size(), a)`.
619
 
620
  ``` cpp
621
+ constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
 
622
  ```
623
 
624
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
625
 
626
+ *Effects:* Constructs an object whose initial value is the range \[`s`,
627
+ `s + n`).
 
 
628
 
629
+ *Ensures:* `size()` is equal to `n`, and `traits::compare(data(), s, n)`
630
+ is equal to `0`.
 
 
 
 
 
631
 
632
  ``` cpp
633
+ constexpr basic_string(const charT* s, const Allocator& a = Allocator());
634
  ```
635
 
636
+ *Constraints:* `Allocator` is a type that qualifies as an
637
+ allocator [[container.requirements.general]].
 
 
 
 
 
638
 
639
+ [*Note 1*: This affects class template argument
640
+ deduction. — *end note*]
641
 
642
+ *Effects:* Equivalent to: `basic_string(s, traits::length(s), a)`.
 
 
 
 
643
 
644
  ``` cpp
645
+ constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
646
  ```
647
 
648
+ *Constraints:* `Allocator` is a type that qualifies as an
649
+ allocator [[container.requirements.general]].
 
 
 
650
 
651
+ [*Note 2*: This affects class template argument
652
+ deduction. — *end note*]
653
 
654
+ *Effects:* Constructs an object whose value consists of `n` copies of
655
+ `c`.
 
 
 
656
 
657
  ``` cpp
658
  template<class InputIterator>
659
+ constexpr basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());
 
660
  ```
661
 
662
+ *Constraints:* `InputIterator` is a type that qualifies as an input
663
+ iterator [[container.requirements.general]].
664
 
665
+ *Effects:* Constructs a string from the values in the range \[`begin`,
666
+ `end`), as indicated in [[container.seq.req]].
 
 
 
 
 
667
 
668
  ``` cpp
669
+ constexpr basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
670
  ```
671
 
672
+ *Effects:* Equivalent to `basic_string(il.begin(), il.end(), a)`.
673
 
674
  ``` cpp
675
+ constexpr basic_string(const basic_string& str, const Allocator& alloc);
676
+ constexpr basic_string(basic_string&& str, const Allocator& alloc);
677
  ```
678
 
679
+ *Effects:* Constructs an object whose value is that of `str` prior to
680
+ this call. The stored allocator is constructed from `alloc`. In the
681
+ second form, `str` is left in a valid but unspecified state.
 
 
 
 
 
 
 
 
 
 
 
 
682
 
683
  *Throws:* The second form throws nothing if
684
  `alloc == str.get_allocator()`.
685
 
686
  ``` cpp
 
690
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
691
  char_traits<typename iterator_traits<InputIterator>::value_type>,
692
  Allocator>;
693
  ```
694
 
695
+ *Constraints:* `InputIterator` is a type that qualifies as an input
696
+ iterator, and `Allocator` is a type that qualifies as an
697
+ allocator [[container.requirements.general]].
 
698
 
699
  ``` cpp
700
+ template<class charT,
701
+ class traits,
702
+ class Allocator = allocator<charT>>
703
+ explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
704
+ -> basic_string<charT, traits, Allocator>;
705
+
706
+ template<class charT,
707
+ class traits,
708
+ class Allocator = allocator<charT>>
709
+ basic_string(basic_string_view<charT, traits>,
710
+ typename see below::size_type, typename see below::size_type,
711
+ const Allocator& = Allocator())
712
+ -> basic_string<charT, traits, Allocator>;
713
  ```
714
 
715
+ *Constraints:* `Allocator` is a type that qualifies as an
716
+ allocator [[container.requirements.general]].
717
+
718
+ ``` cpp
719
+ constexpr basic_string& operator=(const basic_string& str);
720
+ ```
721
 
722
+ *Effects:* If `*this` and `str` are the same object, has no effect.
723
+ Otherwise, replaces the value of `*this` with a copy of `str`.
724
 
725
  *Returns:* `*this`.
726
 
 
 
 
 
 
 
 
 
727
  ``` cpp
728
+ constexpr basic_string& operator=(basic_string&& str)
729
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
730
  allocator_traits<Allocator>::is_always_equal::value);
731
  ```
732
 
733
  *Effects:* Move assigns as a sequence
734
+ container [[container.requirements]], except that iterators, pointers
735
  and references may be invalidated.
736
 
737
  *Returns:* `*this`.
738
 
739
  ``` cpp
740
+ template<class T>
741
+ constexpr basic_string& operator=(const T& t);
742
  ```
743
 
744
+ *Constraints:*
745
+
746
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
747
+ `true` and
748
+ - `is_convertible_v<const T&, const charT*>` is `false`.
749
+
750
+ *Effects:* Equivalent to:
751
 
752
  ``` cpp
753
+ basic_string_view<charT, traits> sv = t;
754
+ return assign(sv);
755
  ```
756
 
757
+ ``` cpp
758
+ constexpr basic_string& operator=(const charT* s);
759
+ ```
760
 
761
+ *Effects:* Equivalent to:
762
+ `return *this = basic_string_view<charT, traits>(s);`
763
 
764
  ``` cpp
765
+ constexpr basic_string& operator=(charT c);
766
  ```
767
 
768
+ *Effects:* Equivalent to:
769
 
770
  ``` cpp
771
+ return *this = basic_string_view<charT, traits>(addressof(c), 1);
772
  ```
773
 
774
+ ``` cpp
775
+ constexpr basic_string& operator=(initializer_list<charT> il);
776
+ ```
777
+
778
+ *Effects:* Equivalent to:
779
 
780
+ ``` cpp
781
+ return *this = basic_string_view<charT, traits>(il.begin(), il.size());
782
+ ```
783
 
784
+ #### Iterator support <a id="string.iterators">[[string.iterators]]</a>
785
 
786
  ``` cpp
787
+ constexpr iterator begin() noexcept;
788
+ constexpr const_iterator begin() const noexcept;
789
+ constexpr const_iterator cbegin() const noexcept;
790
  ```
791
 
792
  *Returns:* An iterator referring to the first character in the string.
793
 
794
  ``` cpp
795
+ constexpr iterator end() noexcept;
796
+ constexpr const_iterator end() const noexcept;
797
+ constexpr const_iterator cend() const noexcept;
798
  ```
799
 
800
  *Returns:* An iterator which is the past-the-end value.
801
 
802
  ``` cpp
803
+ constexpr reverse_iterator rbegin() noexcept;
804
+ constexpr const_reverse_iterator rbegin() const noexcept;
805
+ constexpr const_reverse_iterator crbegin() const noexcept;
806
  ```
807
 
808
  *Returns:* An iterator which is semantically equivalent to
809
  `reverse_iterator(end())`.
810
 
811
  ``` cpp
812
+ constexpr reverse_iterator rend() noexcept;
813
+ constexpr const_reverse_iterator rend() const noexcept;
814
+ constexpr const_reverse_iterator crend() const noexcept;
815
  ```
816
 
817
  *Returns:* An iterator which is semantically equivalent to
818
  `reverse_iterator(begin())`.
819
 
820
+ #### Capacity <a id="string.capacity">[[string.capacity]]</a>
821
 
822
  ``` cpp
823
+ constexpr size_type size() const noexcept;
824
+ constexpr size_type length() const noexcept;
825
  ```
826
 
827
  *Returns:* A count of the number of char-like objects currently in the
828
  string.
829
 
830
  *Complexity:* Constant time.
831
 
832
  ``` cpp
833
+ constexpr size_type max_size() const noexcept;
 
 
 
 
 
 
834
  ```
835
 
836
  *Returns:* The largest possible number of char-like objects that can be
837
  stored in a `basic_string`.
838
 
839
  *Complexity:* Constant time.
840
 
841
  ``` cpp
842
+ constexpr void resize(size_type n, charT c);
843
  ```
844
 
845
+ *Effects:* Alters the value of `*this` as follows:
846
 
847
+ - If `n <= size()`, erases the last `size() - n` elements.
848
+ - If `n > size()`, appends `n - size()` copies of `c`.
 
 
 
 
 
 
 
 
849
 
850
  ``` cpp
851
+ constexpr void resize(size_type n);
852
  ```
853
 
854
+ *Effects:* Equivalent to `resize(n, charT())`.
855
 
856
  ``` cpp
857
+ constexpr size_type capacity() const noexcept;
858
  ```
859
 
860
  *Returns:* The size of the allocated storage in the string.
861
 
862
+ *Complexity:* Constant time.
863
+
864
  ``` cpp
865
+ constexpr void reserve(size_type res_arg);
866
  ```
867
 
868
+ *Effects:* A directive that informs a `basic_string` of a planned change
869
+ in size, so that the storage allocation can be managed accordingly.
870
+ After `reserve()`, `capacity()` is greater or equal to the argument of
871
+ `reserve` if reallocation happens; and equal to the previous value of
872
+ `capacity()` otherwise. Reallocation happens at this point if and only
873
+ if the current capacity is less than the argument of `reserve()`.
874
 
875
+ *Throws:* `length_error` if `res_arg > max_size()` or any exceptions
876
+ thrown by `allocator_traits` `<Allocator>::allocate`.
 
 
 
 
 
 
 
877
 
878
  ``` cpp
879
+ constexpr void shrink_to_fit();
880
  ```
881
 
882
  *Effects:* `shrink_to_fit` is a non-binding request to reduce
883
  `capacity()` to `size()`.
884
 
885
+ [*Note 1*: The request is non-binding to allow latitude for
886
  implementation-specific optimizations. — *end note*]
887
 
888
  It does not increase `capacity()`, but may reduce `capacity()` by
889
  causing reallocation.
890
 
891
+ *Complexity:* If the size is not equal to the old capacity, linear in
892
+ the size of the sequence; otherwise constant.
893
 
894
  *Remarks:* Reallocation invalidates all the references, pointers, and
895
+ iterators referring to the elements in the sequence, as well as the
896
+ past-the-end iterator.
897
 
898
+ [*Note 2*: If no reallocation happens, they remain
899
+ valid. *end note*]
 
 
 
900
 
901
  ``` cpp
902
+ constexpr void clear() noexcept;
903
  ```
904
 
905
+ *Effects:* Equivalent to: `erase(begin(), end());`
906
+
907
  ``` cpp
908
+ [[nodiscard]] constexpr bool empty() const noexcept;
909
  ```
910
 
911
+ *Effects:* Equivalent to: `return size() == 0;`
912
 
913
+ #### Element access <a id="string.access">[[string.access]]</a>
914
 
915
  ``` cpp
916
+ constexpr const_reference operator[](size_type pos) const;
917
+ constexpr reference operator[](size_type pos);
918
  ```
919
 
920
+ *Preconditions:* `pos <= size()`.
921
 
922
  *Returns:* `*(begin() + pos)` if `pos < size()`. Otherwise, returns a
923
  reference to an object of type `charT` with value `charT()`, where
924
  modifying the object to any value other than `charT()` leads to
925
  undefined behavior.
 
927
  *Throws:* Nothing.
928
 
929
  *Complexity:* Constant time.
930
 
931
  ``` cpp
932
+ constexpr const_reference at(size_type pos) const;
933
+ constexpr reference at(size_type pos);
934
  ```
935
 
936
  *Throws:* `out_of_range` if `pos >= size()`.
937
 
938
  *Returns:* `operator[](pos)`.
939
 
940
  ``` cpp
941
+ constexpr const charT& front() const;
942
+ constexpr charT& front();
943
  ```
944
 
945
+ *Preconditions:* `!empty()`.
946
 
947
  *Effects:* Equivalent to: `return operator[](0);`
948
 
949
  ``` cpp
950
+ constexpr const charT& back() const;
951
+ constexpr charT& back();
952
  ```
953
 
954
+ *Preconditions:* `!empty()`.
955
 
956
  *Effects:* Equivalent to: `return operator[](size() - 1);`
957
 
958
+ #### Modifiers <a id="string.modifiers">[[string.modifiers]]</a>
959
 
960
+ ##### `basic_string::operator+=` <a id="string.op.append">[[string.op.append]]</a>
961
 
962
  ``` cpp
963
+ constexpr basic_string& operator+=(const basic_string& str);
 
964
  ```
965
 
966
+ *Effects:* Equivalent to: `return append(str);`
 
 
967
 
968
  ``` cpp
969
+ template<class T>
970
+ constexpr basic_string& operator+=(const T& t);
971
  ```
972
 
973
+ *Constraints:*
974
+
975
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
976
+ `true` and
977
+ - `is_convertible_v<const T&, const charT*>` is `false`.
978
 
979
+ *Effects:* Equivalent to:
980
 
981
  ``` cpp
982
+ basic_string_view<charT, traits> sv = t;
983
+ return append(sv);
984
  ```
985
 
986
+ ``` cpp
987
+ constexpr basic_string& operator+=(const charT* s);
988
+ ```
989
 
990
+ *Effects:* Equivalent to: `return append(s);`
991
 
992
  ``` cpp
993
+ constexpr basic_string& operator+=(charT c);
994
  ```
995
 
996
+ *Effects:* Equivalent to: `return append(size_type{1}, c);`
 
 
997
 
998
  ``` cpp
999
+ constexpr basic_string& operator+=(initializer_list<charT> il);
1000
  ```
1001
 
1002
+ *Effects:* Equivalent to: `return append(il);`
 
 
1003
 
1004
  ##### `basic_string::append` <a id="string.append">[[string.append]]</a>
1005
 
1006
  ``` cpp
1007
+ constexpr basic_string& append(const basic_string& str);
 
1008
  ```
1009
 
1010
+ *Effects:* Equivalent to: `return append(str.data(), str.size());`
 
 
1011
 
1012
  ``` cpp
1013
+ constexpr basic_string& append(const basic_string& str, size_type pos, size_type n = npos);
 
1014
  ```
1015
 
1016
+ *Effects:* Equivalent to:
 
 
 
 
 
 
1017
 
1018
  ``` cpp
1019
+ return append(basic_string_view<charT, traits>(str).substr(pos, n));
1020
  ```
1021
 
 
 
1022
  ``` cpp
1023
  template<class T>
1024
+ constexpr basic_string& append(const T& t);
1025
  ```
1026
 
1027
+ *Constraints:*
1028
 
1029
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1030
+ `true` and
1031
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
1032
 
1033
+ *Effects:* Equivalent to:
 
 
1034
 
1035
+ ``` cpp
1036
+ basic_string_view<charT, traits> sv = t;
1037
+ return append(sv.data(), sv.size());
1038
+ ```
1039
 
1040
  ``` cpp
1041
+ template<class T>
1042
+ constexpr basic_string& append(const T& t, size_type pos, size_type n = npos);
1043
  ```
1044
 
1045
+ *Constraints:*
1046
 
1047
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1048
+ `true` and
1049
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1050
 
1051
+ *Effects:* Equivalent to:
 
 
 
1052
 
1053
+ ``` cpp
1054
+ basic_string_view<charT, traits> sv = t;
1055
+ return append(sv.substr(pos, n));
1056
+ ```
1057
 
1058
  ``` cpp
1059
+ constexpr basic_string& append(const charT* s, size_type n);
1060
  ```
1061
 
1062
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
 
1063
 
1064
+ *Effects:* Appends a copy of the range \[`s`, `s + n`) to the string.
1065
 
1066
  *Returns:* `*this`.
1067
 
1068
  ``` cpp
1069
+ constexpr basic_string& append(const charT* s);
1070
+ ```
1071
+
1072
+ *Effects:* Equivalent to: `return append(s, traits::length(s));`
1073
+
1074
+ ``` cpp
1075
+ constexpr basic_string& append(size_type n, charT c);
1076
  ```
1077
 
1078
+ *Effects:* Appends `n` copies of `c` to the string.
1079
 
1080
  *Returns:* `*this`.
1081
 
1082
  ``` cpp
1083
  template<class InputIterator>
1084
+ constexpr basic_string& append(InputIterator first, InputIterator last);
1085
  ```
1086
 
1087
+ *Constraints:* `InputIterator` is a type that qualifies as an input
1088
+ iterator [[container.requirements.general]].
1089
 
1090
+ *Effects:* Equivalent to:
1091
+ `return append(basic_string(first, last, get_allocator()));`
 
 
1092
 
1093
  ``` cpp
1094
+ constexpr basic_string& append(initializer_list<charT> il);
1095
  ```
1096
 
1097
+ *Effects:* Equivalent to: `return append(il.begin(), il.size());`
 
 
1098
 
1099
  ``` cpp
1100
+ constexpr void push_back(charT c);
1101
  ```
1102
 
1103
+ *Effects:* Equivalent to `append(size_type{1}, c)`.
1104
 
1105
  ##### `basic_string::assign` <a id="string.assign">[[string.assign]]</a>
1106
 
1107
  ``` cpp
1108
+ constexpr basic_string& assign(const basic_string& str);
1109
  ```
1110
 
1111
+ *Effects:* Equivalent to: `return *this = str;`
 
 
1112
 
1113
  ``` cpp
1114
+ constexpr basic_string& assign(basic_string&& str)
1115
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
1116
  allocator_traits<Allocator>::is_always_equal::value);
1117
  ```
1118
 
1119
+ *Effects:* Equivalent to: `return *this = std::move(str);`
 
 
1120
 
1121
  ``` cpp
1122
+ constexpr basic_string& assign(const basic_string& str, size_type pos, size_type n = npos);
 
 
1123
  ```
1124
 
1125
+ *Effects:* Equivalent to:
 
 
 
 
 
 
1126
 
1127
  ``` cpp
1128
+ return assign(basic_string_view<charT, traits>(str).substr(pos, n));
1129
  ```
1130
 
 
 
1131
  ``` cpp
1132
  template<class T>
1133
+ constexpr basic_string& assign(const T& t);
1134
  ```
1135
 
1136
+ *Constraints:*
1137
 
1138
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1139
+ `true` and
1140
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
1141
 
1142
+ *Effects:* Equivalent to:
 
 
1143
 
1144
+ ``` cpp
1145
+ basic_string_view<charT, traits> sv = t;
1146
+ return assign(sv.data(), sv.size());
1147
+ ```
1148
 
1149
  ``` cpp
1150
+ template<class T>
1151
+ constexpr basic_string& assign(const T& t, size_type pos, size_type n = npos);
1152
  ```
1153
 
1154
+ *Constraints:*
1155
 
1156
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1157
+ `true` and
1158
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1159
 
1160
+ *Effects:* Equivalent to:
 
1161
 
1162
+ ``` cpp
1163
+ basic_string_view<charT, traits> sv = t;
1164
+ return assign(sv.substr(pos, n));
1165
+ ```
1166
 
1167
  ``` cpp
1168
+ constexpr basic_string& assign(const charT* s, size_type n);
1169
  ```
1170
 
1171
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
 
1172
 
1173
+ *Effects:* Replaces the string controlled by `*this` with a copy of the
1174
+ range \[`s`, `s + n`).
1175
 
1176
  *Returns:* `*this`.
1177
 
1178
  ``` cpp
1179
+ constexpr basic_string& assign(const charT* s);
1180
  ```
1181
 
1182
+ *Effects:* Equivalent to: `return assign(s, traits::length(s));`
1183
 
1184
+ ``` cpp
1185
+ constexpr basic_string& assign(initializer_list<charT> il);
1186
+ ```
1187
+
1188
+ *Effects:* Equivalent to: `return assign(il.begin(), il.size());`
1189
 
1190
  ``` cpp
1191
+ constexpr basic_string& assign(size_type n, charT c);
1192
  ```
1193
 
1194
+ *Effects:* Equivalent to:
1195
 
1196
+ ``` cpp
1197
+ clear();
1198
+ resize(n, c);
1199
+ return *this;
1200
+ ```
1201
 
1202
  ``` cpp
1203
  template<class InputIterator>
1204
+ constexpr basic_string& assign(InputIterator first, InputIterator last);
1205
  ```
1206
 
1207
+ *Constraints:* `InputIterator` is a type that qualifies as an input
1208
+ iterator [[container.requirements.general]].
1209
 
1210
+ *Effects:* Equivalent to:
1211
+ `return assign(basic_string(first, last, get_allocator()));`
1212
 
1213
  ##### `basic_string::insert` <a id="string.insert">[[string.insert]]</a>
1214
 
1215
  ``` cpp
1216
+ constexpr basic_string& insert(size_type pos, const basic_string& str);
 
 
1217
  ```
1218
 
1219
  *Effects:* Equivalent to: `return insert(pos, str.data(), str.size());`
1220
 
1221
  ``` cpp
1222
+ constexpr basic_string& insert(size_type pos1, const basic_string& str,
 
 
1223
  size_type pos2, size_type n = npos);
1224
  ```
1225
 
1226
+ *Effects:* Equivalent to:
1227
 
1228
+ ``` cpp
1229
+ return insert(pos1, basic_string_view<charT, traits>(str), pos2, n);
1230
+ ```
 
 
1231
 
1232
  ``` cpp
1233
+ template<class T>
1234
+ constexpr basic_string& insert(size_type pos, const T& t);
1235
  ```
1236
 
1237
+ *Constraints:*
1238
+
1239
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1240
+ `true` and
1241
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1242
+
1243
+ *Effects:* Equivalent to:
1244
+
1245
+ ``` cpp
1246
+ basic_string_view<charT, traits> sv = t;
1247
+ return insert(pos, sv.data(), sv.size());
1248
+ ```
1249
 
1250
  ``` cpp
1251
  template<class T>
1252
+ constexpr basic_string& insert(size_type pos1, const T& t,
1253
  size_type pos2, size_type n = npos);
1254
  ```
1255
 
1256
+ *Constraints:*
1257
 
1258
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1259
+ `true` and
1260
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
1261
 
1262
+ *Effects:* Equivalent to:
 
 
1263
 
1264
+ ``` cpp
1265
+ basic_string_view<charT, traits> sv = t;
1266
+ return insert(pos1, sv.substr(pos2, n));
1267
+ ```
1268
 
1269
  ``` cpp
1270
+ constexpr basic_string& insert(size_type pos, const charT* s, size_type n);
 
1271
  ```
1272
 
1273
+ *Preconditions:* \[`s`, `s + n`) is a valid range.
1274
+
1275
+ *Throws:*
1276
 
1277
+ - `out_of_range` if `pos > size()`,
1278
+ - `length_error` if `n > max_size() - size()`, or
1279
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1280
 
1281
+ *Effects:* Inserts a copy of the range \[`s`, `s + n`) immediately
1282
+ before the character at position `pos` if `pos < size()`, or otherwise
1283
+ at the end of the string.
 
 
 
1284
 
1285
  *Returns:* `*this`.
1286
 
1287
  ``` cpp
1288
+ constexpr basic_string& insert(size_type pos, const charT* s);
 
1289
  ```
1290
 
 
 
 
1291
  *Effects:* Equivalent to: `return insert(pos, s, traits::length(s));`
1292
 
1293
  ``` cpp
1294
+ constexpr basic_string& insert(size_type pos, size_type n, charT c);
 
1295
  ```
1296
 
1297
+ *Effects:* Inserts `n` copies of `c` before the character at position
1298
+ `pos` if `pos < size()`, or otherwise at the end of the string.
1299
 
1300
+ *Returns:* `*this`
1301
+
1302
+ *Throws:*
1303
+
1304
+ - `out_of_range` if `pos > size()`,
1305
+ - `length_error` if `n > max_size() - size()`, or
1306
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1307
 
1308
  ``` cpp
1309
+ constexpr iterator insert(const_iterator p, charT c);
1310
  ```
1311
 
1312
+ *Preconditions:* `p` is a valid iterator on `*this`.
1313
 
1314
+ *Effects:* Inserts a copy of `c` at the position `p`.
 
1315
 
1316
+ *Returns:* An iterator which refers to the inserted character.
 
1317
 
1318
  ``` cpp
1319
+ constexpr iterator insert(const_iterator p, size_type n, charT c);
1320
  ```
1321
 
1322
+ *Preconditions:* `p` is a valid iterator on `*this`.
1323
 
1324
+ *Effects:* Inserts `n` copies of `c` at the position `p`.
 
1325
 
1326
+ *Returns:* An iterator which refers to the first inserted character, or
1327
+ `p` if `n == 0`.
1328
 
1329
  ``` cpp
1330
  template<class InputIterator>
1331
+ constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
1332
  ```
1333
 
1334
+ *Constraints:* `InputIterator` is a type that qualifies as an input
1335
+ iterator [[container.requirements.general]].
1336
+
1337
+ *Preconditions:* `p` is a valid iterator on `*this`.
1338
 
1339
  *Effects:* Equivalent to
1340
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
1341
 
1342
+ *Returns:* An iterator which refers to the first inserted character, or
1343
+ `p` if `first == last`.
1344
 
1345
  ``` cpp
1346
+ constexpr iterator insert(const_iterator p, initializer_list<charT> il);
1347
  ```
1348
 
1349
+ *Effects:* Equivalent to: `return insert(p, il.begin(), il.end());`
 
 
 
1350
 
1351
  ##### `basic_string::erase` <a id="string.erase">[[string.erase]]</a>
1352
 
1353
  ``` cpp
1354
+ constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
1355
  ```
1356
 
1357
  *Throws:* `out_of_range` if `pos` `> size()`.
1358
 
1359
  *Effects:* Determines the effective length `xlen` of the string to be
1360
+ removed as the smaller of `n` and `size() - pos`. Removes the characters
1361
+ in the range \[`begin() + pos`, `begin() + pos + xlen`).
 
 
 
 
 
1362
 
1363
  *Returns:* `*this`.
1364
 
1365
  ``` cpp
1366
+ constexpr iterator erase(const_iterator p);
1367
  ```
1368
 
1369
+ *Preconditions:* `p` is a valid dereferenceable iterator on `*this`.
1370
+
1371
  *Throws:* Nothing.
1372
 
1373
  *Effects:* Removes the character referred to by `p`.
1374
 
1375
  *Returns:* An iterator which points to the element immediately following
1376
  `p` prior to the element being erased. If no such element exists,
1377
  `end()` is returned.
1378
 
1379
  ``` cpp
1380
+ constexpr iterator erase(const_iterator first, const_iterator last);
1381
  ```
1382
 
1383
+ *Preconditions:* `first` and `last` are valid iterators on `*this`.
1384
+ \[`first`, `last`) is a valid range.
1385
 
1386
  *Throws:* Nothing.
1387
 
1388
  *Effects:* Removes the characters in the range `[first, last)`.
1389
 
1390
  *Returns:* An iterator which points to the element pointed to by `last`
1391
  prior to the other elements being erased. If no such element exists,
1392
  `end()` is returned.
1393
 
1394
  ``` cpp
1395
+ constexpr void pop_back();
1396
  ```
1397
 
1398
+ *Preconditions:* `!empty()`.
1399
 
1400
  *Throws:* Nothing.
1401
 
1402
+ *Effects:* Equivalent to `erase(end() - 1)`.
1403
 
1404
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
1405
 
1406
  ``` cpp
1407
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
 
 
1408
  ```
1409
 
1410
  *Effects:* Equivalent to:
1411
  `return replace(pos1, n1, str.data(), str.size());`
1412
 
1413
  ``` cpp
1414
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
 
 
1415
  size_type pos2, size_type n2 = npos);
1416
  ```
1417
 
1418
+ *Effects:* Equivalent to:
 
 
 
 
1419
 
1420
+ ``` cpp
1421
+ return replace(pos1, n1, basic_string_view<charT, traits>(str).substr(pos2, n2));
1422
+ ```
1423
 
1424
  ``` cpp
1425
+ template<class T>
1426
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t);
1427
  ```
1428
 
1429
+ *Constraints:*
1430
+
1431
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1432
+ `true` and
1433
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1434
+
1435
  *Effects:* Equivalent to:
1436
+
1437
+ ``` cpp
1438
+ basic_string_view<charT, traits> sv = t;
1439
+ return replace(pos1, n1, sv.data(), sv.size());
1440
+ ```
1441
 
1442
  ``` cpp
1443
  template<class T>
1444
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t,
1445
  size_type pos2, size_type n2 = npos);
1446
  ```
1447
 
1448
+ *Constraints:*
1449
 
1450
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1451
+ `true` and
1452
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
 
1453
 
1454
+ *Effects:* Equivalent to:
 
 
1455
 
1456
+ ``` cpp
1457
+ basic_string_view<charT, traits> sv = t;
1458
+ return replace(pos1, n1, sv.substr(pos2, n2));
1459
+ ```
1460
 
1461
  ``` cpp
1462
+ constexpr basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);
 
1463
  ```
1464
 
1465
+ *Preconditions:* \[`s`, `s + n2`) is a valid range.
1466
+
1467
+ *Throws:*
1468
 
1469
+ - `out_of_range` if `pos1 > size()`,
1470
+ - `length_error` if the length of the resulting string would exceed
1471
+ `max_size()` (see below), or
1472
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1473
 
1474
  *Effects:* Determines the effective length `xlen` of the string to be
1475
  removed as the smaller of `n1` and `size() - pos1`. If
1476
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
1477
+ function replaces the characters in the range \[`begin() + pos1`,
1478
+ `begin() + pos1 + xlen`) with a copy of the range \[`s`, `s + n2`).
 
 
 
 
1479
 
1480
  *Returns:* `*this`.
1481
 
1482
  ``` cpp
1483
+ constexpr basic_string& replace(size_type pos, size_type n, const charT* s);
 
1484
  ```
1485
 
 
 
 
1486
  *Effects:* Equivalent to:
1487
  `return replace(pos, n, s, traits::length(s));`
1488
 
1489
  ``` cpp
1490
+ constexpr basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);
 
 
1491
  ```
1492
 
1493
+ *Throws:*
1494
+
1495
+ - `out_of_range` if `pos1 > size()`,
1496
+ - `length_error` if the length of the resulting string would exceed
1497
+ `max_size()` (see below), or
1498
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate.`
1499
+
1500
+ *Effects:* Determines the effective length `xlen` of the string to be
1501
+ removed as the smaller of `n1` and `size() - pos1`. If
1502
+ `size() - xlen >=` `max_size() - n2` throws `length_error`. Otherwise,
1503
+ the function replaces the characters in the range \[`begin() + pos1`,
1504
+ `begin() + pos1 + xlen`) with `n2` copies of `c`.
1505
 
1506
  *Returns:* `*this`.
1507
 
1508
  ``` cpp
1509
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
1510
  ```
1511
 
1512
+ *Effects:* Equivalent to:
1513
+ `return replace(i1, i2, basic_string_view<charT, traits>(str));`
 
 
 
1514
 
1515
  ``` cpp
1516
+ template<class T>
1517
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t);
1518
  ```
1519
 
1520
+ *Constraints:*
1521
 
1522
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1523
+ `true` and
1524
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1525
 
1526
+ *Preconditions:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1527
+
1528
+ *Effects:* Equivalent to:
1529
 
1530
  ``` cpp
1531
+ basic_string_view<charT, traits> sv = t;
1532
+ return replace(i1 - begin(), i2 - i1, sv.data(), sv.size());
1533
  ```
1534
 
 
 
 
 
 
 
 
1535
  ``` cpp
1536
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
1537
  ```
1538
 
1539
+ *Effects:* Equivalent to:
1540
+ `return replace(i1, i2, basic_string_view<charT, traits>(s, n));`
 
1541
 
1542
+ ``` cpp
1543
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
1544
+ ```
1545
 
1546
+ *Effects:* Equivalent to:
1547
+ `return replace(i1, i2, basic_string_view<charT, traits>(s));`
1548
 
1549
  ``` cpp
1550
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
 
1551
  ```
1552
 
1553
+ *Preconditions:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
1554
 
1555
+ *Effects:* Equivalent to: `return replace(i1 - begin(), i2 - i1, n, c);`
 
 
1556
 
1557
  ``` cpp
1558
  template<class InputIterator>
1559
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2,
1560
  InputIterator j1, InputIterator j2);
1561
  ```
1562
 
1563
+ *Constraints:* `InputIterator` is a type that qualifies as an input
1564
+ iterator [[container.requirements.general]].
1565
 
1566
+ *Effects:* Equivalent to:
1567
+ `return replace(i1, i2, basic_string(j1, j2, get_allocator()));`
 
 
1568
 
1569
  ``` cpp
1570
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
 
1571
  ```
1572
 
1573
+ *Effects:* Equivalent to:
1574
+ `return replace(i1, i2, il.begin(), il.size());`
 
 
 
 
1575
 
1576
  ##### `basic_string::copy` <a id="string.copy">[[string.copy]]</a>
1577
 
1578
  ``` cpp
1579
+ constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
1580
  ```
1581
 
1582
+ *Effects:* Equivalent to:
1583
+ `return basic_string_view<charT, traits>(*this).copy(s, n, pos);`
 
 
 
 
 
1584
 
1585
  [*Note 1*: This does not terminate `s` with a null
1586
  object. — *end note*]
1587
 
 
 
1588
  ##### `basic_string::swap` <a id="string.swap">[[string.swap]]</a>
1589
 
1590
  ``` cpp
1591
+ constexpr void swap(basic_string& s)
1592
  noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
1593
  allocator_traits<Allocator>::is_always_equal::value);
1594
  ```
1595
 
1596
+ *Preconditions:*
1597
+ `allocator_traits<Allocator>::propagate_on_container_swap::value` is
1598
+ `true` or `get_allocator() == s.get_allocator()`.
1599
+
1600
+ *Ensures:* `*this` contains the same sequence of characters that was in
1601
+ `s`, `s` contains the same sequence of characters that was in `*this`.
1602
 
1603
  *Throws:* Nothing.
1604
 
1605
  *Complexity:* Constant time.
1606
 
1607
+ #### String operations <a id="string.ops">[[string.ops]]</a>
1608
 
1609
+ ##### Accessors <a id="string.accessors">[[string.accessors]]</a>
1610
 
1611
  ``` cpp
1612
+ constexpr const charT* c_str() const noexcept;
1613
+ constexpr const charT* data() const noexcept;
1614
  ```
1615
 
1616
+ *Returns:* A pointer `p` such that `p + i == addressof(operator[](i))`
1617
+ for each `i` in \[`0`, `size()`\].
1618
 
1619
  *Complexity:* Constant time.
1620
 
1621
+ *Remarks:* The program shall not modify any of the values stored in the
1622
+ character array; otherwise, the behavior is undefined.
1623
 
1624
  ``` cpp
1625
+ constexpr charT* data() noexcept;
1626
  ```
1627
 
1628
+ *Returns:* A pointer `p` such that `p + i == addressof(operator[](i))`
1629
+ for each `i` in \[`0`, `size()`\].
1630
 
1631
  *Complexity:* Constant time.
1632
 
1633
+ *Remarks:* The program shall not modify the value stored at `p + size()`
1634
+ to any value other than `charT()`; otherwise, the behavior is undefined.
1635
 
1636
  ``` cpp
1637
+ constexpr operator basic_string_view<charT, traits>() const noexcept;
1638
  ```
1639
 
1640
  *Effects:* Equivalent to:
1641
  `return basic_string_view<charT, traits>(data(), size());`
1642
 
1643
  ``` cpp
1644
+ constexpr allocator_type get_allocator() const noexcept;
1645
  ```
1646
 
1647
  *Returns:* A copy of the `Allocator` object used to construct the string
1648
  or, if that allocator has been replaced, a copy of the most recent
1649
  replacement.
1650
 
1651
+ ##### Searching <a id="string.find">[[string.find]]</a>
1652
 
1653
+ Let *F* be one of `find`, `rfind`, `find_first_of`, `find_last_of`,
1654
+ `find_first_not_of`, and `find_last_not_of`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1655
 
1656
+ - Each member function of the form
1657
  ``` cpp
1658
+ constexpr size_type F(const basic_string& str, size_type pos) const noexcept;
1659
  ```
1660
 
1661
+ has effects equivalent to:
1662
+ `return F(basic_string_view<charT, traits>(str), pos);`
1663
+ - Each member function of the form
 
 
1664
  ``` cpp
1665
+ constexpr size_type F(const charT* s, size_type pos) const;
1666
  ```
1667
 
1668
+ has effects equivalent to:
1669
+ `return F(basic_string_view<charT, traits>(s), pos);`
1670
+ - Each member function of the form
 
1671
  ``` cpp
1672
+ constexpr size_type F(const charT* s, size_type pos, size_type n) const;
1673
  ```
1674
 
1675
+ has effects equivalent to:
1676
+ `return F(basic_string_view<charT, traits>(s, n), pos);`
1677
+ - Each member function of the form
 
 
 
 
 
 
 
1678
  ``` cpp
1679
+ constexpr size_type F(charT c, size_type pos) const noexcept;
1680
  ```
1681
 
1682
+ has effects equivalent to:
 
 
1683
  ``` cpp
1684
+ return F(basic_string_view<charT, traits>(addressof(c), 1), pos);
1685
  ```
1686
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1687
  ``` cpp
1688
+ template<class T>
1689
+ constexpr size_type find(const T& t, size_type pos = 0) const noexcept(see below);
1690
+ template<class T>
1691
+ constexpr size_type rfind(const T& t, size_type pos = npos) const noexcept(see below);
1692
+ template<class T>
1693
+ constexpr size_type find_first_of(const T& t, size_type pos = 0) const noexcept(see below);
1694
+ template<class T>
1695
+ constexpr size_type find_last_of(const T& t, size_type pos = npos) const noexcept(see below);
1696
+ template<class T>
1697
+ constexpr size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept(see below);
1698
+ template<class T>
1699
+ constexpr size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept(see below);
1700
  ```
1701
 
1702
+ *Constraints:*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1703
 
1704
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1705
+ `true` and
1706
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1707
 
1708
+ *Effects:* Let *G* be the name of the function. Equivalent to:
1709
 
1710
  ``` cpp
1711
+ basic_string_view<charT, traits> s = *this, sv = t;
1712
+ return s.G(sv, pos);
1713
  ```
1714
 
1715
+ *Remarks:* The expression inside `noexcept` is equivalent to
1716
+ `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
1717
 
1718
  ##### `basic_string::substr` <a id="string.substr">[[string.substr]]</a>
1719
 
1720
  ``` cpp
1721
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) const;
1722
  ```
1723
 
1724
  *Throws:* `out_of_range` if `pos > size()`.
1725
 
1726
  *Effects:* Determines the effective length `rlen` of the string to copy
 
1729
  *Returns:* `basic_string(data()+pos, rlen)`.
1730
 
1731
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
1732
 
1733
  ``` cpp
1734
+ template<class T>
1735
+ constexpr int compare(const T& t) const noexcept(see below);
1736
  ```
1737
 
1738
+ *Constraints:*
 
 
 
1739
 
1740
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1741
+ `true` and
1742
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1743
 
1744
+ *Effects:* Equivalent to:
1745
+ `return basic_string_view<charT, traits>(*this).compare(t);`
1746
 
1747
+ *Remarks:* The expression inside `noexcept` is equivalent to
1748
+ `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
 
 
 
1749
 
1750
  ``` cpp
1751
+ template<class T>
1752
+ constexpr int compare(size_type pos1, size_type n1, const T& t) const;
1753
  ```
1754
 
1755
+ *Constraints:*
1756
+
1757
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1758
+ `true` and
1759
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1760
+
1761
  *Effects:* Equivalent to:
1762
 
1763
  ``` cpp
1764
+ return basic_string_view<charT, traits>(*this).substr(pos1, n1).compare(t);
1765
  ```
1766
 
1767
  ``` cpp
1768
  template<class T>
1769
+ constexpr int compare(size_type pos1, size_type n1, const T& t,
1770
  size_type pos2, size_type n2 = npos) const;
1771
  ```
1772
 
1773
+ *Constraints:*
1774
+
1775
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
1776
+ `true` and
1777
+ - `is_convertible_v<const T&, const charT*>` is `false`.
1778
+
1779
  *Effects:* Equivalent to:
1780
 
1781
  ``` cpp
1782
+ basic_string_view<charT, traits> s = *this, sv = t;
1783
+ return s.substr(pos1, n1).compare(sv.substr(pos2, n2));
 
1784
  ```
1785
 
 
 
 
 
1786
  ``` cpp
1787
+ constexpr int compare(const basic_string& str) const noexcept;
1788
  ```
1789
 
1790
  *Effects:* Equivalent to:
1791
  `return compare(basic_string_view<charT, traits>(str));`
1792
 
1793
  ``` cpp
1794
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str) const;
1795
  ```
1796
 
1797
  *Effects:* Equivalent to:
1798
  `return compare(pos1, n1, basic_string_view<charT, traits>(str));`
1799
 
1800
  ``` cpp
1801
+ constexpr int compare(size_type pos1, size_type n1, const basic_string& str,
 
1802
  size_type pos2, size_type n2 = npos) const;
1803
  ```
1804
 
1805
  *Effects:* Equivalent to:
1806
 
1807
  ``` cpp
1808
  return compare(pos1, n1, basic_string_view<charT, traits>(str), pos2, n2);
1809
  ```
1810
 
1811
  ``` cpp
1812
+ constexpr int compare(const charT* s) const;
1813
  ```
1814
 
1815
+ *Effects:* Equivalent to:
1816
+ `return compare(basic_string_view<charT, traits>(s));`
1817
 
1818
  ``` cpp
1819
+ constexpr int compare(size_type pos, size_type n1, const charT* s) const;
1820
  ```
1821
 
1822
+ *Effects:* Equivalent to:
1823
+ `return compare(pos, n1, basic_string_view<charT, traits>(s));`
1824
 
1825
  ``` cpp
1826
+ constexpr int compare(size_type pos, size_type n1, const charT* s, size_type n2) const;
1827
  ```
1828
 
1829
+ *Effects:* Equivalent to:
1830
+ `return compare(pos, n1, basic_string_view<charT, traits>(s, n2));`
1831
 
1832
+ ##### `basic_string::starts_with` <a id="string.starts.with">[[string.starts.with]]</a>
 
 
1833
 
1834
  ``` cpp
1835
+ constexpr bool starts_with(basic_string_view<charT, traits> x) const noexcept;
1836
+ constexpr bool starts_with(charT x) const noexcept;
1837
+ constexpr bool starts_with(const charT* x) const;
 
1838
  ```
1839
 
1840
+ *Effects:* Equivalent to:
1841
 
1842
  ``` cpp
1843
+ return basic_string_view<charT, traits>(data(), size()).starts_with(x);
 
 
 
1844
  ```
1845
 
1846
+ ##### `basic_string::ends_with` <a id="string.ends.with">[[string.ends.with]]</a>
1847
 
1848
  ``` cpp
1849
+ constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept;
1850
+ constexpr bool ends_with(charT x) const noexcept;
1851
+ constexpr bool ends_with(const charT* x) const;
 
1852
  ```
1853
 
1854
+ *Effects:* Equivalent to:
1855
 
1856
  ``` cpp
1857
+ return basic_string_view<charT, traits>(data(), size()).ends_with(x);
 
 
 
1858
  ```
1859
 
1860
+ ### Non-member functions <a id="string.nonmembers">[[string.nonmembers]]</a>
1861
 
1862
+ #### `operator+` <a id="string.op.plus">[[string.op.plus]]</a>
 
1863
 
1864
  ``` cpp
1865
  template<class charT, class traits, class Allocator>
1866
+ constexpr basic_string<charT, traits, Allocator>
1867
+ operator+(const basic_string<charT, traits, Allocator>& lhs,
1868
  const basic_string<charT, traits, Allocator>& rhs);
1869
+ template<class charT, class traits, class Allocator>
1870
+ constexpr basic_string<charT, traits, Allocator>
1871
+ operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
1872
  ```
1873
 
1874
+ *Effects:* Equivalent to:
 
 
1875
 
1876
  ``` cpp
1877
+ basic_string<charT, traits, Allocator> r = lhs;
1878
+ r.append(rhs);
1879
+ return r;
 
1880
  ```
1881
 
 
 
 
 
1882
  ``` cpp
1883
  template<class charT, class traits, class Allocator>
1884
+ constexpr basic_string<charT, traits, Allocator>
1885
+ operator+(basic_string<charT, traits, Allocator>&& lhs,
1886
  const basic_string<charT, traits, Allocator>& rhs);
 
 
 
 
 
1887
  template<class charT, class traits, class Allocator>
1888
+ constexpr basic_string<charT, traits, Allocator>
1889
+ operator+(basic_string<charT, traits, Allocator>&& lhs, const charT* rhs);
 
1890
  ```
1891
 
1892
+ *Effects:* Equivalent to:
1893
 
1894
  ``` cpp
1895
+ lhs.append(rhs);
1896
+ return std::move(lhs);
 
 
1897
  ```
1898
 
 
 
 
 
1899
  ``` cpp
1900
  template<class charT, class traits, class Allocator>
1901
+ constexpr basic_string<charT, traits, Allocator>
1902
  operator+(basic_string<charT, traits, Allocator>&& lhs,
1903
+ basic_string<charT, traits, Allocator>&& rhs);
 
 
 
 
 
 
 
 
 
 
 
1904
  ```
1905
 
1906
+ *Effects:* Equivalent to:
1907
 
1908
  ``` cpp
1909
+ lhs.append(rhs);
1910
+ return std::move(lhs);
 
 
1911
  ```
1912
 
1913
+ except that both `lhs` and `rhs` are left in valid but unspecified
1914
+ states.
1915
 
1916
+ [*Note 1*: If `lhs` and `rhs` have equal allocators, the implementation
1917
+ may move from either. — *end note*]
1918
 
1919
  ``` cpp
1920
  template<class charT, class traits, class Allocator>
1921
+ constexpr basic_string<charT, traits, Allocator>
1922
+ operator+(const basic_string<charT, traits, Allocator>& lhs,
1923
+ basic_string<charT, traits, Allocator>&& rhs);
 
 
 
 
1924
  template<class charT, class traits, class Allocator>
1925
+ constexpr basic_string<charT, traits, Allocator>
1926
+ operator+(const charT* lhs, basic_string<charT, traits, Allocator>&& rhs);
1927
  ```
1928
 
1929
+ *Effects:* Equivalent to:
1930
 
1931
  ``` cpp
1932
+ rhs.insert(0, lhs);
1933
+ return std::move(rhs);
 
1934
  ```
1935
 
 
 
 
 
 
 
 
1936
  ``` cpp
1937
  template<class charT, class traits, class Allocator>
1938
+ constexpr basic_string<charT, traits, Allocator>
1939
+ operator+(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs);
1940
  ```
1941
 
1942
+ *Effects:* Equivalent to:
1943
 
1944
  ``` cpp
1945
+ basic_string<charT, traits, Allocator> r = rhs;
1946
+ r.insert(0, lhs);
1947
+ return r;
1948
  ```
1949
 
 
 
1950
  ``` cpp
1951
  template<class charT, class traits, class Allocator>
1952
+ constexpr basic_string<charT, traits, Allocator>
1953
+ operator+(charT lhs, const basic_string<charT, traits, Allocator>& rhs);
1954
  ```
1955
 
1956
+ *Effects:* Equivalent to:
 
 
 
 
 
1957
 
1958
  ``` cpp
1959
+ basic_string<charT, traits, Allocator> r = rhs;
1960
+ r.insert(r.begin(), lhs);
1961
+ return r;
1962
  ```
1963
 
 
 
1964
  ``` cpp
1965
  template<class charT, class traits, class Allocator>
1966
+ constexpr basic_string<charT, traits, Allocator>
1967
+ operator+(charT lhs, basic_string<charT, traits, Allocator>&& rhs);
1968
  ```
1969
 
1970
+ *Effects:* Equivalent to:
1971
 
1972
  ``` cpp
1973
+ rhs.insert(rhs.begin(), lhs);
1974
+ return std::move(rhs);
 
1975
  ```
1976
 
 
 
 
 
1977
  ``` cpp
1978
  template<class charT, class traits, class Allocator>
1979
+ constexpr basic_string<charT, traits, Allocator>
1980
+ operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
1981
  ```
1982
 
1983
+ *Effects:* Equivalent to:
1984
 
1985
  ``` cpp
1986
+ basic_string<charT, traits, Allocator> r = lhs;
1987
+ r.push_back(rhs);
1988
+ return r;
1989
  ```
1990
 
 
 
1991
  ``` cpp
1992
  template<class charT, class traits, class Allocator>
1993
+ constexpr basic_string<charT, traits, Allocator>
1994
+ operator+(basic_string<charT, traits, Allocator>&& lhs, charT rhs);
1995
  ```
1996
 
1997
+ *Effects:* Equivalent to:
 
 
1998
 
1999
  ``` cpp
2000
+ lhs.push_back(rhs);
2001
+ return std::move(lhs);
 
2002
  ```
2003
 
2004
+ #### Non-member comparison functions <a id="string.cmp">[[string.cmp]]</a>
2005
 
2006
  ``` cpp
2007
  template<class charT, class traits, class Allocator>
2008
+ constexpr bool
2009
+ operator==(const basic_string<charT, traits, Allocator>& lhs,
2010
+ const basic_string<charT, traits, Allocator>& rhs) noexcept;
 
 
 
 
2011
  template<class charT, class traits, class Allocator>
2012
+ constexpr bool operator==(const basic_string<charT, traits, Allocator>& lhs,
2013
  const charT* rhs);
 
2014
 
 
 
 
 
 
2015
  template<class charT, class traits, class Allocator>
2016
+ constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs,
2017
+ \itcorr const basic_string<charT, traits, Allocator>& rhs) noexcept;
 
 
 
 
 
2018
  template<class charT, class traits, class Allocator>
2019
+ constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs,
2020
+ \itcorr const charT* rhs);
2021
  ```
2022
 
2023
+ *Effects:* Let *`op`* be the operator. Equivalent to:
2024
 
2025
  ``` cpp
2026
+ return basic_string_view<charT, traits>(lhs) op basic_string_view<charT, traits>(rhs);
 
 
2027
  ```
2028
 
 
 
2029
  #### `swap` <a id="string.special">[[string.special]]</a>
2030
 
2031
  ``` cpp
2032
  template<class charT, class traits, class Allocator>
2033
+ constexpr void
2034
+ swap(basic_string<charT, traits, Allocator>& lhs,
2035
  basic_string<charT, traits, Allocator>& rhs)
2036
  noexcept(noexcept(lhs.swap(rhs)));
2037
  ```
2038
 
2039
+ *Effects:* Equivalent to `lhs.swap(rhs)`.
2040
 
2041
  #### Inserters and extractors <a id="string.io">[[string.io]]</a>
2042
 
2043
  ``` cpp
2044
  template<class charT, class traits, class Allocator>
2045
  basic_istream<charT, traits>&
2046
+ operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
 
2047
  ```
2048
 
2049
  *Effects:* Behaves as a formatted input
2050
+ function [[istream.formatted.reqmts]]. After constructing a `sentry`
2051
  object, if the sentry converts to `true`, calls `str.erase()` and then
2052
  extracts characters from `is` and appends them to `str` as if by calling
2053
  `str.append(1, c)`. If `is.width()` is greater than zero, the maximum
2054
  number `n` of characters appended is `is.width()`; otherwise `n` is
2055
  `str.max_size()`. Characters are extracted and appended until any of the
 
2062
 
2063
  After the last character (if any) is extracted, `is.width(0)` is called
2064
  and the `sentry` object is destroyed.
2065
 
2066
  If the function extracts no characters, it calls
2067
+ `is.setstate(ios_base::failbit)`, which may throw `ios_base::failure`
2068
+ [[iostate.flags]].
2069
 
2070
  *Returns:* `is`.
2071
 
2072
  ``` cpp
2073
  template<class charT, class traits, class Allocator>
 
2091
  basic_string<charT, traits, Allocator>& str,
2092
  charT delim);
2093
  ```
2094
 
2095
  *Effects:* Behaves as an unformatted input
2096
+ function [[istream.unformatted]], except that it does not affect the
2097
  value returned by subsequent calls to `basic_istream<>::gcount()`. After
2098
  constructing a `sentry` object, if the sentry converts to `true`, calls
2099
  `str.erase()` and then extracts characters from `is` and appends them to
2100
  `str` as if by calling `str.append(1, c)` until any of the following
2101
  occurs:
2102
 
2103
  - end-of-file occurs on the input sequence (in which case, the `getline`
2104
  function calls `is.setstate(ios_base::eofbit)`).
2105
  - `traits::eq(c, delim)` for the next available input character *c* (in
2106
+ which case, *c* is extracted but not appended) [[iostate.flags]]
2107
  - `str.max_size()` characters are stored (in which case, the function
2108
+ calls `is.setstate(ios_base::failbit))` [[iostate.flags]]
2109
 
2110
  The conditions are tested in the order shown. In any case, after the
2111
  last character is extracted, the `sentry` object is destroyed.
2112
 
2113
  If the function extracts no characters, it calls
2114
+ `is.setstate(ios_base::failbit)` which may throw `ios_base::failure`
2115
+ [[iostate.flags]].
2116
 
2117
  *Returns:* `is`.
2118
 
2119
  ``` cpp
2120
  template<class charT, class traits, class Allocator>
 
2127
  basic_string<charT, traits, Allocator>& str);
2128
  ```
2129
 
2130
  *Returns:* `getline(is, str, is.widen(’\n’))`.
2131
 
2132
+ #### Erasure <a id="string.erasure">[[string.erasure]]</a>
2133
+
2134
+ ``` cpp
2135
+ template<class charT, class traits, class Allocator, class U>
2136
+ constexpr typename basic_string<charT, traits, Allocator>::size_type
2137
+ erase(basic_string<charT, traits, Allocator>& c, const U& value);
2138
+ ```
2139
+
2140
+ *Effects:* Equivalent to:
2141
+
2142
+ ``` cpp
2143
+ auto it = remove(c.begin(), c.end(), value);
2144
+ auto r = distance(it, c.end());
2145
+ c.erase(it, c.end());
2146
+ return r;
2147
+ ```
2148
+
2149
+ ``` cpp
2150
+ template<class charT, class traits, class Allocator, class Predicate>
2151
+ constexpr typename basic_string<charT, traits, Allocator>::size_type
2152
+ erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred);
2153
+ ```
2154
+
2155
+ *Effects:* Equivalent to:
2156
+
2157
+ ``` cpp
2158
+ auto it = remove_if(c.begin(), c.end(), pred);
2159
+ auto r = distance(it, c.end());
2160
+ c.erase(it, c.end());
2161
+ return r;
2162
+ ```
2163
+
2164
  ### Numeric conversions <a id="string.conversions">[[string.conversions]]</a>
2165
 
2166
  ``` cpp
2167
+ int stoi(const string& str, size_t* idx = nullptr, int base = 10);
2168
+ long stol(const string& str, size_t* idx = nullptr, int base = 10);
2169
+ unsigned long stoul(const string& str, size_t* idx = nullptr, int base = 10);
2170
+ long long stoll(const string& str, size_t* idx = nullptr, int base = 10);
2171
+ unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10);
2172
  ```
2173
 
2174
+ *Effects:* The first two functions call
2175
  `strtol(str.c_str(), ptr, base)`, and the last three functions call
2176
  `strtoul(str.c_str(), ptr, base)`, `strtoll(str.c_str(), ptr, base)`,
2177
  and `strtoull(str.c_str(), ptr, base)`, respectively. Each function
2178
  returns the converted result, if any. The argument `ptr` designates a
2179
  pointer to an object internal to the function that is used to determine
 
2188
  `out_of_range` if `strtol`, `strtoul`, `strtoll` or `strtoull` sets
2189
  `errno` to `ERANGE`, or if the converted value is outside the range of
2190
  representable values for the return type.
2191
 
2192
  ``` cpp
2193
+ float stof(const string& str, size_t* idx = nullptr);
2194
+ double stod(const string& str, size_t* idx = nullptr);
2195
+ long double stold(const string& str, size_t* idx = nullptr);
2196
  ```
2197
 
2198
  *Effects:* These functions call `strtof(str.c_str(), ptr)`,
2199
  `strtod(str.c_str(), ptr)`, and `strtold(str.c_str(), ptr)`,
2200
  respectively. Each function returns the converted result, if any. The
 
2229
  `"%u"`, `"%ld"`, `"%lu"`, `"%lld"`, `"%llu"`, `"%f"`, `"%f"`, or
2230
  `"%Lf"`, respectively, where `buf` designates an internal character
2231
  buffer of sufficient size.
2232
 
2233
  ``` cpp
2234
+ int stoi(const wstring& str, size_t* idx = nullptr, int base = 10);
2235
+ long stol(const wstring& str, size_t* idx = nullptr, int base = 10);
2236
+ unsigned long stoul(const wstring& str, size_t* idx = nullptr, int base = 10);
2237
+ long long stoll(const wstring& str, size_t* idx = nullptr, int base = 10);
2238
+ unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10);
2239
  ```
2240
 
2241
+ *Effects:* The first two functions call
2242
  `wcstol(str.c_str(), ptr, base)`, and the last three functions call
2243
  `wcstoul(str.c_str(), ptr, base)`, `wcstoll(str.c_str(), ptr, base)`,
2244
  and `wcstoull(str.c_str(), ptr, base)`, respectively. Each function
2245
  returns the converted result, if any. The argument `ptr` designates a
2246
  pointer to an object internal to the function that is used to determine
 
2254
  `wcstoull` reports that no conversion could be performed. Throws
2255
  `out_of_range` if the converted value is outside the range of
2256
  representable values for the return type.
2257
 
2258
  ``` cpp
2259
+ float stof(const wstring& str, size_t* idx = nullptr);
2260
+ double stod(const wstring& str, size_t* idx = nullptr);
2261
+ long double stold(const wstring& str, size_t* idx = nullptr);
2262
  ```
2263
 
2264
  *Effects:* These functions call `wcstof(str.c_str(), ptr)`,
2265
  `wcstod(str.c_str(), ptr)`, and `wcstold(str.c_str(), ptr)`,
2266
  respectively. Each function returns the converted result, if any. The
 
2296
 
2297
  ### Hash support <a id="basic.string.hash">[[basic.string.hash]]</a>
2298
 
2299
  ``` cpp
2300
  template<> struct hash<string>;
2301
+ template<> struct hash<u8string>;
2302
  template<> struct hash<u16string>;
2303
  template<> struct hash<u32string>;
2304
  template<> struct hash<wstring>;
2305
+ template<> struct hash<pmr::string>;
2306
+ template<> struct hash<pmr::u8string>;
2307
+ template<> struct hash<pmr::u16string>;
2308
+ template<> struct hash<pmr::u32string>;
2309
+ template<> struct hash<pmr::wstring>;
2310
  ```
2311
 
2312
  If `S` is one of these string types, `SV` is the corresponding string
2313
  view type, and `s` is an object of type `S`, then
2314
  `hash<S>()(s) == hash<SV>()(SV(s))`.
2315
 
2316
  ### Suffix for `basic_string` literals <a id="basic.string.literals">[[basic.string.literals]]</a>
2317
 
2318
  ``` cpp
2319
+ constexpr string operator""s(const char* str, size_t len);
2320
  ```
2321
 
2322
  *Returns:* `string{str, len}`.
2323
 
2324
  ``` cpp
2325
+ constexpr u8string operator""s(const char8_t* str, size_t len);
2326
+ ```
2327
+
2328
+ *Returns:* `u8string{str, len}`.
2329
+
2330
+ ``` cpp
2331
+ constexpr u16string operator""s(const char16_t* str, size_t len);
2332
  ```
2333
 
2334
  *Returns:* `u16string{str, len}`.
2335
 
2336
  ``` cpp
2337
+ constexpr u32string operator""s(const char32_t* str, size_t len);
2338
  ```
2339
 
2340
  *Returns:* `u32string{str, len}`.
2341
 
2342
  ``` cpp
2343
+ constexpr wstring operator""s(const wchar_t* str, size_t len);
2344
  ```
2345
 
2346
  *Returns:* `wstring{str, len}`.
2347
 
2348
  [*Note 1*: The same suffix `s` is used for `chrono::duration` literals