From Jason Turner

[string.classes]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpl0r6py9p/{from.md → to.md} +2473 -17
tmp/tmpl0r6py9p/{from.md → to.md} RENAMED
@@ -1,26 +1,27 @@
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
- typedefs, `string`, `u16string`, `u32string`, and `wstring`, that name
6
- the specializations `basic_string<char>`, `basic_string<char16_t>`,
7
  `basic_string<char32_t>`, and `basic_string<{}wchar_t>`, respectively.
8
 
 
 
9
  ``` cpp
10
  #include <initializer_list>
11
 
12
  namespace std {
13
-
14
- // [char.traits], character traits:
15
  template<class charT> struct char_traits;
16
  template<> struct char_traits<char>;
17
  template<> struct char_traits<char16_t>;
18
  template<> struct char_traits<char32_t>;
19
  template<> struct char_traits<wchar_t>;
20
 
21
- // [basic.string], basic_string:
22
  template<class charT, class traits = char_traits<charT>,
23
  class Allocator = allocator<charT>>
24
  class basic_string;
25
 
26
  template<class charT, class traits, class Allocator>
@@ -123,16 +124,17 @@ namespace std {
123
  const charT* rhs);
124
  template<class charT, class traits, class Allocator>
125
  bool operator>=(const charT* lhs,
126
  const basic_string<charT, traits, Allocator>& rhs);
127
 
128
- // [string.special], swap:
129
  template<class charT, class traits, class Allocator>
130
  void swap(basic_string<charT, traits, Allocator>& lhs,
131
- basic_string<charT,traits,Allocator>& rhs);
 
132
 
133
- // [string.io], inserters and extractors:
134
  template<class charT, class traits, class Allocator>
135
  basic_istream<charT, traits>&
136
  operator>>(basic_istream<charT, traits>& is,
137
  basic_string<charT, traits, Allocator>& str);
138
  template<class charT, class traits, class Allocator>
@@ -157,16 +159,16 @@ namespace std {
157
  basic_istream<charT, traits>&
158
  getline(basic_istream<charT, traits>&& is,
159
  basic_string<charT, traits, Allocator>& str);
160
 
161
  // basic_string typedef names
162
- typedef basic_string<char> string;
163
- typedef basic_string<char16_t> u16string;
164
- typedef basic_string<char32_t> u32string;
165
- typedef basic_string<wchar_t> wstring;
166
 
167
- // [string.conversions], numeric conversions:
168
  int stoi(const string& str, size_t* idx = 0, int base = 10);
169
  long stol(const string& str, size_t* idx = 0, int base = 10);
170
  unsigned long stoul(const string& str, size_t* idx = 0, int base = 10);
171
  long long stoll(const string& str, size_t* idx = 0, int base = 10);
172
  unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
@@ -199,26 +201,2480 @@ namespace std {
199
  wstring to_wstring(unsigned long long val);
200
  wstring to_wstring(float val);
201
  wstring to_wstring(double val);
202
  wstring to_wstring(long double val);
203
 
204
- // [basic.string.hash], hash support:
205
  template<class T> struct hash;
206
  template<> struct hash<string>;
207
  template<> struct hash<u16string>;
208
  template<> struct hash<u32string>;
209
  template<> struct hash<wstring>;
210
 
 
 
 
 
 
 
 
 
 
 
 
211
  inline namespace literals {
212
  inline namespace string_literals {
213
-
214
- // [basic.string.literals], suffix for basic_string literals:
215
  string operator""s(const char* str, size_t len);
216
  u16string operator""s(const char16_t* str, size_t len);
217
  u32string operator""s(const char32_t* str, size_t len);
218
  wstring operator""s(const wchar_t* str, size_t len);
219
-
220
  }
221
  }
222
  }
223
  ```
224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>
 
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>
137
  basic_istream<charT, traits>&
138
  operator>>(basic_istream<charT, traits>& is,
139
  basic_string<charT, traits, Allocator>& str);
140
  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);
 
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
 
236
+ ### Class template `basic_string` <a id="basic.string">[[basic.string]]</a>
237
+
238
+ The class template `basic_string` describes objects that can store a
239
+ sequence consisting of a varying number of arbitrary char-like objects
240
+ 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;
275
+ using pointer = typename allocator_traits<Allocator>::pointer;
276
+ using const_pointer = typename allocator_traits<Allocator>::const_pointer;
277
+ using reference = value_type&;
278
+ using const_reference = const value_type&;
279
+
280
+ using iterator = implementation-defined // type of basic_string::iterator; // see [container.requirements]
281
+ using const_iterator = implementation-defined // type of basic_string::const_iterator; // see [container.requirements]
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
761
+ template<class InputIterator,
762
+ class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
763
+ basic_string(InputIterator, InputIterator, Allocator = Allocator())
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.
990
+
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
2017
+ as the smaller of `n` and `size() - pos`.
2018
+
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
2428
+ following occurs:
2429
+
2430
+ - *n* characters are stored;
2431
+ - end-of-file occurs on the input sequence;
2432
+ - `isspace(c, is.getloc())` is `true` for the next available input
2433
+ character *c*.
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>
2446
+ basic_ostream<charT, traits>&
2447
+ operator<<(basic_ostream<charT, traits>& os,
2448
+ const basic_string<charT, traits, Allocator>& str);
2449
+ ```
2450
+
2451
+ *Effects:* Equivalent to:
2452
+ `return os << basic_string_view<charT, traits>(str);`
2453
+
2454
+ ``` cpp
2455
+ template<class charT, class traits, class Allocator>
2456
+ basic_istream<charT, traits>&
2457
+ getline(basic_istream<charT, traits>& is,
2458
+ basic_string<charT, traits, Allocator>& str,
2459
+ charT delim);
2460
+ template<class charT, class traits, class Allocator>
2461
+ basic_istream<charT, traits>&
2462
+ getline(basic_istream<charT, traits>&& is,
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>
2493
+ basic_istream<charT, traits>&
2494
+ getline(basic_istream<charT, traits>& is,
2495
+ basic_string<charT, traits, Allocator>& str);
2496
+ template<class charT, class traits, class Allocator>
2497
+ basic_istream<charT, traits>&
2498
+ getline(basic_istream<charT, traits>&& is,
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
2520
+ what to store at `*idx`. If the function does not throw an exception and
2521
+ `idx != 0`, the function stores in `*idx` the index of the first
2522
+ unconverted element of `str`.
2523
+
2524
+ *Returns:* The converted result.
2525
+
2526
+ *Throws:* `invalid_argument` if `strtol`, `strtoul`, `strtoll`, or
2527
+ `strtoull` reports that no conversion could be performed. Throws
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
2541
+ argument `ptr` designates a pointer to an object internal to the
2542
+ function that is used to determine what to store at `*idx`. If the
2543
+ function does not throw an exception and `idx != 0`, the function stores
2544
+ in `*idx` the index of the first unconverted element of `str`.
2545
+
2546
+ *Returns:* The converted result.
2547
+
2548
+ *Throws:* `invalid_argument` if `strtof`, `strtod`, or `strtold` reports
2549
+ that no conversion could be performed. Throws `out_of_range` if
2550
+ `strtof`, `strtod`, or `strtold` sets `errno` to `ERANGE` or if the
2551
+ converted value is outside the range of representable values for the
2552
+ return type.
2553
+
2554
+ ``` cpp
2555
+ string to_string(int val);
2556
+ string to_string(unsigned val);
2557
+ string to_string(long val);
2558
+ string to_string(unsigned long val);
2559
+ string to_string(long long val);
2560
+ string to_string(unsigned long long val);
2561
+ string to_string(float val);
2562
+ string to_string(double val);
2563
+ string to_string(long double val);
2564
+ ```
2565
+
2566
+ *Returns:* Each function returns a `string` object holding the character
2567
+ representation of the value of its argument that would be generated by
2568
+ 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
2587
+ what to store at `*idx`. If the function does not throw an exception and
2588
+ `idx != 0`, the function stores in `*idx` the index of the first
2589
+ unconverted element of `str`.
2590
+
2591
+ *Returns:* The converted result.
2592
+
2593
+ *Throws:* `invalid_argument` if `wcstol`, `wcstoul`, `wcstoll`, or
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
2607
+ argument `ptr` designates a pointer to an object internal to the
2608
+ function that is used to determine what to store at `*idx`. If the
2609
+ function does not throw an exception and `idx != 0`, the function stores
2610
+ in `*idx` the index of the first unconverted element of `str`.
2611
+
2612
+ *Returns:* The converted result.
2613
+
2614
+ *Throws:* `invalid_argument` if `wcstof`, `wcstod`, or `wcstold` reports
2615
+ that no conversion could be performed. Throws `out_of_range` if
2616
+ `wcstof`, `wcstod`, or `wcstold` sets `errno` to `ERANGE`.
2617
+
2618
+ ``` cpp
2619
+ wstring to_wstring(int val);
2620
+ wstring to_wstring(unsigned val);
2621
+ wstring to_wstring(long val);
2622
+ wstring to_wstring(unsigned long val);
2623
+ wstring to_wstring(long long val);
2624
+ wstring to_wstring(unsigned long long val);
2625
+ wstring to_wstring(float val);
2626
+ wstring to_wstring(double val);
2627
+ wstring to_wstring(long double val);
2628
+ ```
2629
+
2630
+ *Returns:* Each function returns a `wstring` object holding the
2631
+ character representation of the value of its argument that would be
2632
+ generated by calling `swprintf(buf, buffsz, fmt, val)` with a format
2633
+ specifier of `L"%d"`, `L"%u"`, `L"%ld"`, `L"%lu"`, `L"%lld"`, `L"%llu"`,
2634
+ `L"%f"`, `L"%f"`, or `L"%Lf"`, respectively, where `buf` designates an
2635
+ 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
2677
+ denoting seconds but there is no conflict, since duration suffixes apply
2678
+ to numbers and string literal suffixes apply to character array
2679
+ literals. — *end note*]
2680
+