2 //===--------------------------- string -----------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef _LIBCPP_STRING
12 #define _LIBCPP_STRING
20 template <class stateT>
26 fpos(streamoff = streamoff());
28 operator streamoff() const;
33 fpos& operator+=(streamoff);
34 fpos operator+ (streamoff) const;
35 fpos& operator-=(streamoff);
36 fpos operator- (streamoff) const;
39 template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
41 template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
42 template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
44 template <class charT>
47 typedef charT char_type;
49 typedef streamoff off_type;
50 typedef streampos pos_type;
51 typedef mbstate_t state_type;
53 static void assign(char_type& c1, const char_type& c2) noexcept;
54 static constexpr bool eq(char_type c1, char_type c2) noexcept;
55 static constexpr bool lt(char_type c1, char_type c2) noexcept;
57 static int compare(const char_type* s1, const char_type* s2, size_t n);
58 static size_t length(const char_type* s);
59 static const char_type* find(const char_type* s, size_t n, const char_type& a);
60 static char_type* move(char_type* s1, const char_type* s2, size_t n);
61 static char_type* copy(char_type* s1, const char_type* s2, size_t n);
62 static char_type* assign(char_type* s, size_t n, char_type a);
64 static constexpr int_type not_eof(int_type c) noexcept;
65 static constexpr char_type to_char_type(int_type c) noexcept;
66 static constexpr int_type to_int_type(char_type c) noexcept;
67 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
68 static constexpr int_type eof() noexcept;
71 template <> struct char_traits<char>;
72 template <> struct char_traits<wchar_t>;
74 template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
79 typedef traits traits_type;
80 typedef typename traits_type::char_type value_type;
81 typedef Allocator allocator_type;
82 typedef typename allocator_type::size_type size_type;
83 typedef typename allocator_type::difference_type difference_type;
84 typedef typename allocator_type::reference reference;
85 typedef typename allocator_type::const_reference const_reference;
86 typedef typename allocator_type::pointer pointer;
87 typedef typename allocator_type::const_pointer const_pointer;
88 typedef implementation-defined iterator;
89 typedef implementation-defined const_iterator;
90 typedef std::reverse_iterator<iterator> reverse_iterator;
91 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
93 static const size_type npos = -1;
96 noexcept(is_nothrow_default_constructible<allocator_type>::value);
97 explicit basic_string(const allocator_type& a);
98 basic_string(const basic_string& str);
99 basic_string(basic_string&& str)
100 noexcept(is_nothrow_move_constructible<allocator_type>::value);
101 basic_string(const basic_string& str, size_type pos,
102 const allocator_type& a = allocator_type());
103 basic_string(const basic_string& str, size_type pos, size_type n,
104 const Allocator& a = Allocator());
106 basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
107 explicit basic_string(const basic_string_view<charT, traits> sv, const Allocator& a = Allocator());
108 basic_string(const value_type* s, const allocator_type& a = allocator_type());
109 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
110 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
111 template<class InputIterator>
112 basic_string(InputIterator begin, InputIterator end,
113 const allocator_type& a = allocator_type());
114 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
115 basic_string(const basic_string&, const Allocator&);
116 basic_string(basic_string&&, const Allocator&);
120 operator basic_string_view<charT, traits>() const noexcept;
122 basic_string& operator=(const basic_string& str);
123 basic_string& operator=(basic_string_view<charT, traits> sv);
124 basic_string& operator=(basic_string&& str)
126 allocator_type::propagate_on_container_move_assignment::value ||
127 allocator_type::is_always_equal::value ); // C++17
128 basic_string& operator=(const value_type* s);
129 basic_string& operator=(value_type c);
130 basic_string& operator=(initializer_list<value_type>);
132 iterator begin() noexcept;
133 const_iterator begin() const noexcept;
134 iterator end() noexcept;
135 const_iterator end() const noexcept;
137 reverse_iterator rbegin() noexcept;
138 const_reverse_iterator rbegin() const noexcept;
139 reverse_iterator rend() noexcept;
140 const_reverse_iterator rend() const noexcept;
142 const_iterator cbegin() const noexcept;
143 const_iterator cend() const noexcept;
144 const_reverse_iterator crbegin() const noexcept;
145 const_reverse_iterator crend() const noexcept;
147 size_type size() const noexcept;
148 size_type length() const noexcept;
149 size_type max_size() const noexcept;
150 size_type capacity() const noexcept;
152 void resize(size_type n, value_type c);
153 void resize(size_type n);
155 void reserve(size_type res_arg = 0);
156 void shrink_to_fit();
157 void clear() noexcept;
158 bool empty() const noexcept;
160 const_reference operator[](size_type pos) const;
161 reference operator[](size_type pos);
163 const_reference at(size_type n) const;
164 reference at(size_type n);
166 basic_string& operator+=(const basic_string& str);
167 basic_string& operator+=(basic_string_view<charT, traits> sv);
168 basic_string& operator+=(const value_type* s);
169 basic_string& operator+=(value_type c);
170 basic_string& operator+=(initializer_list<value_type>);
172 basic_string& append(const basic_string& str);
173 basic_string& append(basic_string_view<charT, traits> sv);
174 basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
176 basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
177 basic_string& append(const value_type* s, size_type n);
178 basic_string& append(const value_type* s);
179 basic_string& append(size_type n, value_type c);
180 template<class InputIterator>
181 basic_string& append(InputIterator first, InputIterator last);
182 basic_string& append(initializer_list<value_type>);
184 void push_back(value_type c);
187 const_reference front() const;
189 const_reference back() const;
191 basic_string& assign(const basic_string& str);
192 basic_string& assign(basic_string_view<charT, traits> sv);
193 basic_string& assign(basic_string&& str);
194 basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
196 basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
197 basic_string& assign(const value_type* s, size_type n);
198 basic_string& assign(const value_type* s);
199 basic_string& assign(size_type n, value_type c);
200 template<class InputIterator>
201 basic_string& assign(InputIterator first, InputIterator last);
202 basic_string& assign(initializer_list<value_type>);
204 basic_string& insert(size_type pos1, const basic_string& str);
205 basic_string& insert(size_type pos1, basic_string_view<charT, traits> sv);
206 basic_string& insert(size_type pos1, const basic_string& str,
207 size_type pos2, size_type n);
209 basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
210 basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
211 basic_string& insert(size_type pos, const value_type* s);
212 basic_string& insert(size_type pos, size_type n, value_type c);
213 iterator insert(const_iterator p, value_type c);
214 iterator insert(const_iterator p, size_type n, value_type c);
215 template<class InputIterator>
216 iterator insert(const_iterator p, InputIterator first, InputIterator last);
217 iterator insert(const_iterator p, initializer_list<value_type>);
219 basic_string& erase(size_type pos = 0, size_type n = npos);
220 iterator erase(const_iterator position);
221 iterator erase(const_iterator first, const_iterator last);
223 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
224 basic_string& replace(size_type pos1, size_type n1, basic_string_view<charT, traits> sv);
225 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
226 size_type pos2, size_type n2=npos); // C++14
228 basic_string& replace(size_type pos1, size_type n1, const T& t,
229 size_type pos2, size_type n); // C++17
230 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
231 basic_string& replace(size_type pos, size_type n1, const value_type* s);
232 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
233 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
234 basic_string& replace(const_iterator i1, const_iterator i2, basic_string_view<charT, traits> sv);
235 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
236 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
237 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
238 template<class InputIterator>
239 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
240 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
242 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
243 basic_string substr(size_type pos = 0, size_type n = npos) const;
245 void swap(basic_string& str)
246 noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
247 allocator_traits<allocator_type>::is_always_equal::value); // C++17
249 const value_type* c_str() const noexcept;
250 const value_type* data() const noexcept;
251 value_type* data() noexcept; // C++17
253 allocator_type get_allocator() const noexcept;
255 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
256 size_type find(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
257 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
258 size_type find(const value_type* s, size_type pos = 0) const noexcept;
259 size_type find(value_type c, size_type pos = 0) const noexcept;
261 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
262 size_type rfind(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
263 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
264 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
265 size_type rfind(value_type c, size_type pos = npos) const noexcept;
267 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
268 size_type find_first_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
269 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
270 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
271 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
273 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
274 size_type find_last_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
275 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
276 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
277 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
279 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
280 size_type find_first_not_of(basic_string_view<charT, traits> sv, size_type pos = 0) const noexcept;
281 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
282 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
283 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
285 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
286 size_type find_last_not_of(basic_string_view<charT, traits> sv, size_type pos = npos) const noexcept;
287 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
288 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
289 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
291 int compare(const basic_string& str) const noexcept;
292 int compare(basic_string_view<charT, traits> sv) const noexcept;
293 int compare(size_type pos1, size_type n1, const basic_string& str) const;
294 int compare(size_type pos1, size_type n1, basic_string_view<charT, traits> sv) const;
295 int compare(size_type pos1, size_type n1, const basic_string& str,
296 size_type pos2, size_type n2=npos) const; // C++14
298 int compare(size_type pos1, size_type n1, const T& t,
299 size_type pos2, size_type n2=npos) const; // C++17
300 int compare(const value_type* s) const noexcept;
301 int compare(size_type pos1, size_type n1, const value_type* s) const;
302 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
304 bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
305 bool starts_with(charT c) const noexcept; // C++2a
306 bool starts_with(const charT* s) const; // C++2a
307 bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
308 bool ends_with(charT c) const noexcept; // C++2a
309 bool ends_with(const charT* s) const; // C++2a
311 bool __invariants() const;
314 template<class charT, class traits, class Allocator>
315 basic_string<charT, traits, Allocator>
316 operator+(const basic_string<charT, traits, Allocator>& lhs,
317 const basic_string<charT, traits, Allocator>& rhs);
319 template<class charT, class traits, class Allocator>
320 basic_string<charT, traits, Allocator>
321 operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
323 template<class charT, class traits, class Allocator>
324 basic_string<charT, traits, Allocator>
325 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
327 template<class charT, class traits, class Allocator>
328 basic_string<charT, traits, Allocator>
329 operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
331 template<class charT, class traits, class Allocator>
332 basic_string<charT, traits, Allocator>
333 operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
335 template<class charT, class traits, class Allocator>
336 bool operator==(const basic_string<charT, traits, Allocator>& lhs,
337 const basic_string<charT, traits, Allocator>& rhs) noexcept;
339 template<class charT, class traits, class Allocator>
340 bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
342 template<class charT, class traits, class Allocator>
343 bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
345 template<class charT, class traits, class Allocator>
346 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
347 const basic_string<charT, traits, Allocator>& rhs) noexcept;
349 template<class charT, class traits, class Allocator>
350 bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
352 template<class charT, class traits, class Allocator>
353 bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
355 template<class charT, class traits, class Allocator>
356 bool operator< (const basic_string<charT, traits, Allocator>& lhs,
357 const basic_string<charT, traits, Allocator>& rhs) noexcept;
359 template<class charT, class traits, class Allocator>
360 bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
362 template<class charT, class traits, class Allocator>
363 bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
365 template<class charT, class traits, class Allocator>
366 bool operator> (const basic_string<charT, traits, Allocator>& lhs,
367 const basic_string<charT, traits, Allocator>& rhs) noexcept;
369 template<class charT, class traits, class Allocator>
370 bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
372 template<class charT, class traits, class Allocator>
373 bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
375 template<class charT, class traits, class Allocator>
376 bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
377 const basic_string<charT, traits, Allocator>& rhs) noexcept;
379 template<class charT, class traits, class Allocator>
380 bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
382 template<class charT, class traits, class Allocator>
383 bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
385 template<class charT, class traits, class Allocator>
386 bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
387 const basic_string<charT, traits, Allocator>& rhs) noexcept;
389 template<class charT, class traits, class Allocator>
390 bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
392 template<class charT, class traits, class Allocator>
393 bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
395 template<class charT, class traits, class Allocator>
396 void swap(basic_string<charT, traits, Allocator>& lhs,
397 basic_string<charT, traits, Allocator>& rhs)
398 noexcept(noexcept(lhs.swap(rhs)));
400 template<class charT, class traits, class Allocator>
401 basic_istream<charT, traits>&
402 operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
404 template<class charT, class traits, class Allocator>
405 basic_ostream<charT, traits>&
406 operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
408 template<class charT, class traits, class Allocator>
409 basic_istream<charT, traits>&
410 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
413 template<class charT, class traits, class Allocator>
414 basic_istream<charT, traits>&
415 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
417 typedef basic_string<char> string;
418 typedef basic_string<wchar_t> wstring;
419 typedef basic_string<char16_t> u16string;
420 typedef basic_string<char32_t> u32string;
422 int stoi (const string& str, size_t* idx = 0, int base = 10);
423 long stol (const string& str, size_t* idx = 0, int base = 10);
424 unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
425 long long stoll (const string& str, size_t* idx = 0, int base = 10);
426 unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
428 float stof (const string& str, size_t* idx = 0);
429 double stod (const string& str, size_t* idx = 0);
430 long double stold(const string& str, size_t* idx = 0);
432 string to_string(int val);
433 string to_string(unsigned val);
434 string to_string(long val);
435 string to_string(unsigned long val);
436 string to_string(long long val);
437 string to_string(unsigned long long val);
438 string to_string(float val);
439 string to_string(double val);
440 string to_string(long double val);
442 int stoi (const wstring& str, size_t* idx = 0, int base = 10);
443 long stol (const wstring& str, size_t* idx = 0, int base = 10);
444 unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
445 long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
446 unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
448 float stof (const wstring& str, size_t* idx = 0);
449 double stod (const wstring& str, size_t* idx = 0);
450 long double stold(const wstring& str, size_t* idx = 0);
452 wstring to_wstring(int val);
453 wstring to_wstring(unsigned val);
454 wstring to_wstring(long val);
455 wstring to_wstring(unsigned long val);
456 wstring to_wstring(long long val);
457 wstring to_wstring(unsigned long long val);
458 wstring to_wstring(float val);
459 wstring to_wstring(double val);
460 wstring to_wstring(long double val);
462 template <> struct hash<string>;
463 template <> struct hash<u16string>;
464 template <> struct hash<u32string>;
465 template <> struct hash<wstring>;
467 basic_string<char> operator "" s( const char *str, size_t len ); // C++14
468 basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
469 basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
470 basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
477 #include <string_view>
480 #include <cstdio> // For EOF.
487 #include <type_traits>
488 #include <initializer_list>
489 #include <__functional_base>
490 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
496 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
497 #pragma GCC system_header
501 #include <__undef_macros>
504 _LIBCPP_BEGIN_NAMESPACE_STD
508 template <class _StateT>
509 class _LIBCPP_TEMPLATE_VIS fpos
515 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
517 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
519 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
520 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
522 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
523 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
524 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
525 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
528 template <class _StateT>
529 inline _LIBCPP_INLINE_VISIBILITY
530 streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
531 {return streamoff(__x) - streamoff(__y);}
533 template <class _StateT>
534 inline _LIBCPP_INLINE_VISIBILITY
535 bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
536 {return streamoff(__x) == streamoff(__y);}
538 template <class _StateT>
539 inline _LIBCPP_INLINE_VISIBILITY
540 bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
541 {return streamoff(__x) != streamoff(__y);}
545 template<class _CharT, class _Traits, class _Allocator>
546 basic_string<_CharT, _Traits, _Allocator>
547 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
548 const basic_string<_CharT, _Traits, _Allocator>& __y);
550 template<class _CharT, class _Traits, class _Allocator>
551 basic_string<_CharT, _Traits, _Allocator>
552 operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
554 template<class _CharT, class _Traits, class _Allocator>
555 basic_string<_CharT, _Traits, _Allocator>
556 operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
558 template<class _CharT, class _Traits, class _Allocator>
559 basic_string<_CharT, _Traits, _Allocator>
560 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
562 template<class _CharT, class _Traits, class _Allocator>
563 basic_string<_CharT, _Traits, _Allocator>
564 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
566 _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
569 class _LIBCPP_TEMPLATE_VIS __basic_string_common
572 _LIBCPP_NORETURN void __throw_length_error() const;
573 _LIBCPP_NORETURN void __throw_out_of_range() const;
578 __basic_string_common<__b>::__throw_length_error() const
580 _VSTD::__throw_length_error("basic_string");
585 __basic_string_common<__b>::__throw_out_of_range() const
587 _VSTD::__throw_out_of_range("basic_string");
590 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
592 #ifdef _LIBCPP_NO_EXCEPTIONS
593 template <class _Iter>
594 struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
595 #elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
596 template <class _Iter>
597 struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
599 template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
600 struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
601 noexcept(++(declval<_Iter&>())) &&
602 is_nothrow_assignable<_Iter&, _Iter>::value &&
603 noexcept(declval<_Iter>() == declval<_Iter>()) &&
604 noexcept(*declval<_Iter>())
607 template <class _Iter>
608 struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
612 template <class _Iter>
613 struct __libcpp_string_gets_noexcept_iterator
614 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
616 template <class _CharT, class _Traits, class _Tp>
617 struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
618 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
619 !is_convertible<const _Tp&, const _CharT*>::value)) {};
621 #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
623 template <class _CharT, size_t = sizeof(_CharT)>
626 unsigned char __xx[sizeof(_CharT)-1];
629 template <class _CharT>
630 struct __padding<_CharT, 1>
634 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
636 template<class _CharT, class _Traits, class _Allocator>
637 class _LIBCPP_TEMPLATE_VIS basic_string
638 : private __basic_string_common<true>
641 typedef basic_string __self;
642 typedef basic_string_view<_CharT, _Traits> __self_view;
643 typedef _Traits traits_type;
644 typedef _CharT value_type;
645 typedef _Allocator allocator_type;
646 typedef allocator_traits<allocator_type> __alloc_traits;
647 typedef typename __alloc_traits::size_type size_type;
648 typedef typename __alloc_traits::difference_type difference_type;
649 typedef value_type& reference;
650 typedef const value_type& const_reference;
651 typedef typename __alloc_traits::pointer pointer;
652 typedef typename __alloc_traits::const_pointer const_pointer;
654 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
655 static_assert((is_same<_CharT, typename traits_type::char_type>::value),
656 "traits_type::char_type must be the same type as CharT");
657 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
658 "Allocator::value_type must be same type as value_type");
659 #if defined(_LIBCPP_RAW_ITERATORS)
660 typedef pointer iterator;
661 typedef const_pointer const_iterator;
662 #else // defined(_LIBCPP_RAW_ITERATORS)
663 typedef __wrap_iter<pointer> iterator;
664 typedef __wrap_iter<const_pointer> const_iterator;
665 #endif // defined(_LIBCPP_RAW_ITERATORS)
666 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
667 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
671 #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
680 #ifdef _LIBCPP_BIG_ENDIAN
681 static const size_type __short_mask = 0x01;
682 static const size_type __long_mask = 0x1ul;
683 #else // _LIBCPP_BIG_ENDIAN
684 static const size_type __short_mask = 0x80;
685 static const size_type __long_mask = ~(size_type(~0) >> 1);
686 #endif // _LIBCPP_BIG_ENDIAN
688 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
689 (sizeof(__long) - 1)/sizeof(value_type) : 2};
693 value_type __data_[__min_cap];
695 : __padding<value_type>
697 unsigned char __size_;
710 #ifdef _LIBCPP_BIG_ENDIAN
711 static const size_type __short_mask = 0x80;
712 static const size_type __long_mask = ~(size_type(~0) >> 1);
713 #else // _LIBCPP_BIG_ENDIAN
714 static const size_type __short_mask = 0x01;
715 static const size_type __long_mask = 0x1ul;
716 #endif // _LIBCPP_BIG_ENDIAN
718 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
719 (sizeof(__long) - 1)/sizeof(value_type) : 2};
725 unsigned char __size_;
728 value_type __data_[__min_cap];
731 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
733 union __ulx{__long __lx; __short __lxx;};
735 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
739 size_type __words[__n_words];
752 __compressed_pair<__rep, allocator_type> __r_;
755 static const size_type npos = -1;
757 _LIBCPP_INLINE_VISIBILITY basic_string()
758 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
760 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
761 #if _LIBCPP_STD_VER <= 14
762 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
767 basic_string(const basic_string& __str);
768 basic_string(const basic_string& __str, const allocator_type& __a);
770 #ifndef _LIBCPP_CXX03_LANG
771 _LIBCPP_INLINE_VISIBILITY
772 basic_string(basic_string&& __str)
773 #if _LIBCPP_STD_VER <= 14
774 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
779 _LIBCPP_INLINE_VISIBILITY
780 basic_string(basic_string&& __str, const allocator_type& __a);
781 #endif // _LIBCPP_CXX03_LANG
782 _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s);
783 _LIBCPP_INLINE_VISIBILITY
784 basic_string(const _CharT* __s, const _Allocator& __a);
785 _LIBCPP_INLINE_VISIBILITY
786 basic_string(const _CharT* __s, size_type __n);
787 _LIBCPP_INLINE_VISIBILITY
788 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
789 _LIBCPP_INLINE_VISIBILITY
790 basic_string(size_type __n, _CharT __c);
791 _LIBCPP_INLINE_VISIBILITY
792 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
793 basic_string(const basic_string& __str, size_type __pos, size_type __n,
794 const _Allocator& __a = _Allocator());
795 _LIBCPP_INLINE_VISIBILITY
796 basic_string(const basic_string& __str, size_type __pos,
797 const _Allocator& __a = _Allocator());
799 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
800 basic_string(const _Tp& __t, size_type __pos, size_type __n,
801 const allocator_type& __a = allocator_type(),
802 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
803 _LIBCPP_INLINE_VISIBILITY explicit
804 basic_string(__self_view __sv);
805 _LIBCPP_INLINE_VISIBILITY
806 basic_string(__self_view __sv, const _Allocator& __a);
807 template<class _InputIterator>
808 _LIBCPP_INLINE_VISIBILITY
809 basic_string(_InputIterator __first, _InputIterator __last);
810 template<class _InputIterator>
811 _LIBCPP_INLINE_VISIBILITY
812 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
813 #ifndef _LIBCPP_CXX03_LANG
814 _LIBCPP_INLINE_VISIBILITY
815 basic_string(initializer_list<_CharT> __il);
816 _LIBCPP_INLINE_VISIBILITY
817 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
818 #endif // _LIBCPP_CXX03_LANG
820 inline ~basic_string();
822 _LIBCPP_INLINE_VISIBILITY
823 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
825 basic_string& operator=(const basic_string& __str);
827 #ifndef _LIBCPP_CXX03_LANG
828 template <class = void>
830 _LIBCPP_INLINE_VISIBILITY
831 basic_string& operator=(__self_view __sv) {return assign(__sv);}
832 #ifndef _LIBCPP_CXX03_LANG
833 _LIBCPP_INLINE_VISIBILITY
834 basic_string& operator=(basic_string&& __str)
835 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
836 _LIBCPP_INLINE_VISIBILITY
837 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
839 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
840 basic_string& operator=(value_type __c);
842 #if _LIBCPP_DEBUG_LEVEL >= 2
843 _LIBCPP_INLINE_VISIBILITY
844 iterator begin() _NOEXCEPT
845 {return iterator(this, __get_pointer());}
846 _LIBCPP_INLINE_VISIBILITY
847 const_iterator begin() const _NOEXCEPT
848 {return const_iterator(this, __get_pointer());}
849 _LIBCPP_INLINE_VISIBILITY
850 iterator end() _NOEXCEPT
851 {return iterator(this, __get_pointer() + size());}
852 _LIBCPP_INLINE_VISIBILITY
853 const_iterator end() const _NOEXCEPT
854 {return const_iterator(this, __get_pointer() + size());}
856 _LIBCPP_INLINE_VISIBILITY
857 iterator begin() _NOEXCEPT
858 {return iterator(__get_pointer());}
859 _LIBCPP_INLINE_VISIBILITY
860 const_iterator begin() const _NOEXCEPT
861 {return const_iterator(__get_pointer());}
862 _LIBCPP_INLINE_VISIBILITY
863 iterator end() _NOEXCEPT
864 {return iterator(__get_pointer() + size());}
865 _LIBCPP_INLINE_VISIBILITY
866 const_iterator end() const _NOEXCEPT
867 {return const_iterator(__get_pointer() + size());}
868 #endif // _LIBCPP_DEBUG_LEVEL >= 2
869 _LIBCPP_INLINE_VISIBILITY
870 reverse_iterator rbegin() _NOEXCEPT
871 {return reverse_iterator(end());}
872 _LIBCPP_INLINE_VISIBILITY
873 const_reverse_iterator rbegin() const _NOEXCEPT
874 {return const_reverse_iterator(end());}
875 _LIBCPP_INLINE_VISIBILITY
876 reverse_iterator rend() _NOEXCEPT
877 {return reverse_iterator(begin());}
878 _LIBCPP_INLINE_VISIBILITY
879 const_reverse_iterator rend() const _NOEXCEPT
880 {return const_reverse_iterator(begin());}
882 _LIBCPP_INLINE_VISIBILITY
883 const_iterator cbegin() const _NOEXCEPT
885 _LIBCPP_INLINE_VISIBILITY
886 const_iterator cend() const _NOEXCEPT
888 _LIBCPP_INLINE_VISIBILITY
889 const_reverse_iterator crbegin() const _NOEXCEPT
891 _LIBCPP_INLINE_VISIBILITY
892 const_reverse_iterator crend() const _NOEXCEPT
895 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
896 {return __is_long() ? __get_long_size() : __get_short_size();}
897 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
898 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
899 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
900 {return (__is_long() ? __get_long_cap()
901 : static_cast<size_type>(__min_cap)) - 1;}
903 void resize(size_type __n, value_type __c);
904 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
906 void reserve(size_type __res_arg = 0);
907 _LIBCPP_INLINE_VISIBILITY
908 void shrink_to_fit() _NOEXCEPT {reserve();}
909 _LIBCPP_INLINE_VISIBILITY
910 void clear() _NOEXCEPT;
911 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
912 bool empty() const _NOEXCEPT {return size() == 0;}
914 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
915 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
917 const_reference at(size_type __n) const;
918 reference at(size_type __n);
920 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
921 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
922 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
923 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
924 #ifndef _LIBCPP_CXX03_LANG
925 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
926 #endif // _LIBCPP_CXX03_LANG
928 _LIBCPP_INLINE_VISIBILITY
929 basic_string& append(const basic_string& __str);
930 _LIBCPP_INLINE_VISIBILITY
931 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
932 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
934 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
937 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
940 append(const _Tp& __t, size_type __pos, size_type __n=npos);
941 basic_string& append(const value_type* __s, size_type __n);
942 basic_string& append(const value_type* __s);
943 basic_string& append(size_type __n, value_type __c);
944 template <class _ForwardIterator>
945 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
946 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
947 template<class _InputIterator>
948 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
951 __is_exactly_input_iterator<_InputIterator>::value
952 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
955 _LIBCPP_INLINE_VISIBILITY
956 append(_InputIterator __first, _InputIterator __last) {
957 const basic_string __temp (__first, __last, __alloc());
958 append(__temp.data(), __temp.size());
961 template<class _ForwardIterator>
962 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
965 __is_forward_iterator<_ForwardIterator>::value
966 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
969 _LIBCPP_INLINE_VISIBILITY
970 append(_ForwardIterator __first, _ForwardIterator __last) {
971 return __append_forward_unsafe(__first, __last);
974 #ifndef _LIBCPP_CXX03_LANG
975 _LIBCPP_INLINE_VISIBILITY
976 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
977 #endif // _LIBCPP_CXX03_LANG
979 void push_back(value_type __c);
980 _LIBCPP_INLINE_VISIBILITY
982 _LIBCPP_INLINE_VISIBILITY reference front();
983 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
984 _LIBCPP_INLINE_VISIBILITY reference back();
985 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
987 _LIBCPP_INLINE_VISIBILITY
988 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
989 _LIBCPP_INLINE_VISIBILITY
990 basic_string& assign(const basic_string& __str) { return *this = __str; }
991 #ifndef _LIBCPP_CXX03_LANG
992 _LIBCPP_INLINE_VISIBILITY
993 basic_string& assign(basic_string&& __str)
994 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
995 {*this = _VSTD::move(__str); return *this;}
997 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
999 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1002 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1005 assign(const _Tp & __t, size_type __pos, size_type __n=npos);
1006 basic_string& assign(const value_type* __s, size_type __n);
1007 basic_string& assign(const value_type* __s);
1008 basic_string& assign(size_type __n, value_type __c);
1009 template<class _InputIterator>
1010 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1013 __is_exactly_input_iterator<_InputIterator>::value
1014 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
1017 assign(_InputIterator __first, _InputIterator __last);
1018 template<class _ForwardIterator>
1019 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1022 __is_forward_iterator<_ForwardIterator>::value
1023 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
1026 assign(_ForwardIterator __first, _ForwardIterator __last);
1027 #ifndef _LIBCPP_CXX03_LANG
1028 _LIBCPP_INLINE_VISIBILITY
1029 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1030 #endif // _LIBCPP_CXX03_LANG
1032 _LIBCPP_INLINE_VISIBILITY
1033 basic_string& insert(size_type __pos1, const basic_string& __str);
1034 _LIBCPP_INLINE_VISIBILITY
1035 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
1036 template <class _Tp>
1037 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1040 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1043 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
1044 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
1045 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1046 basic_string& insert(size_type __pos, const value_type* __s);
1047 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1048 iterator insert(const_iterator __pos, value_type __c);
1049 _LIBCPP_INLINE_VISIBILITY
1050 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1051 template<class _InputIterator>
1052 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1055 __is_exactly_input_iterator<_InputIterator>::value
1056 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
1059 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1060 template<class _ForwardIterator>
1061 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1064 __is_forward_iterator<_ForwardIterator>::value
1065 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
1068 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1069 #ifndef _LIBCPP_CXX03_LANG
1070 _LIBCPP_INLINE_VISIBILITY
1071 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1072 {return insert(__pos, __il.begin(), __il.end());}
1073 #endif // _LIBCPP_CXX03_LANG
1075 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1076 _LIBCPP_INLINE_VISIBILITY
1077 iterator erase(const_iterator __pos);
1078 _LIBCPP_INLINE_VISIBILITY
1079 iterator erase(const_iterator __first, const_iterator __last);
1081 _LIBCPP_INLINE_VISIBILITY
1082 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1083 _LIBCPP_INLINE_VISIBILITY
1084 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
1085 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
1086 template <class _Tp>
1087 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1090 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1093 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
1094 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1095 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1096 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1097 _LIBCPP_INLINE_VISIBILITY
1098 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1099 _LIBCPP_INLINE_VISIBILITY
1100 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1101 _LIBCPP_INLINE_VISIBILITY
1102 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1103 _LIBCPP_INLINE_VISIBILITY
1104 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1105 _LIBCPP_INLINE_VISIBILITY
1106 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1107 template<class _InputIterator>
1108 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1111 __is_input_iterator<_InputIterator>::value,
1114 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1115 #ifndef _LIBCPP_CXX03_LANG
1116 _LIBCPP_INLINE_VISIBILITY
1117 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1118 {return replace(__i1, __i2, __il.begin(), __il.end());}
1119 #endif // _LIBCPP_CXX03_LANG
1121 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1122 _LIBCPP_INLINE_VISIBILITY
1123 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1125 _LIBCPP_INLINE_VISIBILITY
1126 void swap(basic_string& __str)
1127 #if _LIBCPP_STD_VER >= 14
1130 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
1131 __is_nothrow_swappable<allocator_type>::value);
1134 _LIBCPP_INLINE_VISIBILITY
1135 const value_type* c_str() const _NOEXCEPT {return data();}
1136 _LIBCPP_INLINE_VISIBILITY
1137 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1138 #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
1139 _LIBCPP_INLINE_VISIBILITY
1140 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1143 _LIBCPP_INLINE_VISIBILITY
1144 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
1146 _LIBCPP_INLINE_VISIBILITY
1147 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1148 _LIBCPP_INLINE_VISIBILITY
1149 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1150 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1151 _LIBCPP_INLINE_VISIBILITY
1152 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1153 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1155 _LIBCPP_INLINE_VISIBILITY
1156 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1157 _LIBCPP_INLINE_VISIBILITY
1158 size_type rfind(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
1159 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1160 _LIBCPP_INLINE_VISIBILITY
1161 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1162 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1164 _LIBCPP_INLINE_VISIBILITY
1165 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1166 _LIBCPP_INLINE_VISIBILITY
1167 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1168 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1169 _LIBCPP_INLINE_VISIBILITY
1170 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1171 _LIBCPP_INLINE_VISIBILITY
1172 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1174 _LIBCPP_INLINE_VISIBILITY
1175 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1176 _LIBCPP_INLINE_VISIBILITY
1177 size_type find_last_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
1178 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1179 _LIBCPP_INLINE_VISIBILITY
1180 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1181 _LIBCPP_INLINE_VISIBILITY
1182 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1184 _LIBCPP_INLINE_VISIBILITY
1185 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1186 _LIBCPP_INLINE_VISIBILITY
1187 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1188 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1189 _LIBCPP_INLINE_VISIBILITY
1190 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1191 _LIBCPP_INLINE_VISIBILITY
1192 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1194 _LIBCPP_INLINE_VISIBILITY
1195 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1196 _LIBCPP_INLINE_VISIBILITY
1197 size_type find_last_not_of(__self_view __sv, size_type __pos = npos) const _NOEXCEPT;
1198 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1199 _LIBCPP_INLINE_VISIBILITY
1200 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1201 _LIBCPP_INLINE_VISIBILITY
1202 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1204 _LIBCPP_INLINE_VISIBILITY
1205 int compare(const basic_string& __str) const _NOEXCEPT;
1206 _LIBCPP_INLINE_VISIBILITY
1207 int compare(__self_view __sv) const _NOEXCEPT;
1208 _LIBCPP_INLINE_VISIBILITY
1209 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1210 _LIBCPP_INLINE_VISIBILITY
1211 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1212 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
1213 template <class _Tp>
1214 inline _LIBCPP_INLINE_VISIBILITY
1217 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1220 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
1221 int compare(const value_type* __s) const _NOEXCEPT;
1222 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1223 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1225 #if _LIBCPP_STD_VER > 17
1226 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1227 bool starts_with(__self_view __sv) const _NOEXCEPT
1228 { return __self_view(data(), size()).starts_with(__sv); }
1230 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1231 bool starts_with(value_type __c) const _NOEXCEPT
1232 { return !empty() && _Traits::eq(front(), __c); }
1234 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1235 bool starts_with(const value_type* __s) const _NOEXCEPT
1236 { return starts_with(__self_view(__s)); }
1238 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1239 bool ends_with(__self_view __sv) const _NOEXCEPT
1240 { return __self_view(data(), size()).ends_with( __sv); }
1242 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1243 bool ends_with(value_type __c) const _NOEXCEPT
1244 { return !empty() && _Traits::eq(back(), __c); }
1246 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1247 bool ends_with(const value_type* __s) const _NOEXCEPT
1248 { return ends_with(__self_view(__s)); }
1251 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1253 _LIBCPP_INLINE_VISIBILITY
1254 bool __is_long() const _NOEXCEPT
1255 {return bool(__r_.first().__s.__size_ & __short_mask);}
1257 #if _LIBCPP_DEBUG_LEVEL >= 2
1259 bool __dereferenceable(const const_iterator* __i) const;
1260 bool __decrementable(const const_iterator* __i) const;
1261 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1262 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1264 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1267 _LIBCPP_INLINE_VISIBILITY
1268 allocator_type& __alloc() _NOEXCEPT
1269 {return __r_.second();}
1270 _LIBCPP_INLINE_VISIBILITY
1271 const allocator_type& __alloc() const _NOEXCEPT
1272 {return __r_.second();}
1274 #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1276 _LIBCPP_INLINE_VISIBILITY
1277 void __set_short_size(size_type __s) _NOEXCEPT
1278 # ifdef _LIBCPP_BIG_ENDIAN
1279 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1281 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1284 _LIBCPP_INLINE_VISIBILITY
1285 size_type __get_short_size() const _NOEXCEPT
1286 # ifdef _LIBCPP_BIG_ENDIAN
1287 {return __r_.first().__s.__size_ >> 1;}
1289 {return __r_.first().__s.__size_;}
1292 #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1294 _LIBCPP_INLINE_VISIBILITY
1295 void __set_short_size(size_type __s) _NOEXCEPT
1296 # ifdef _LIBCPP_BIG_ENDIAN
1297 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1299 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1302 _LIBCPP_INLINE_VISIBILITY
1303 size_type __get_short_size() const _NOEXCEPT
1304 # ifdef _LIBCPP_BIG_ENDIAN
1305 {return __r_.first().__s.__size_;}
1307 {return __r_.first().__s.__size_ >> 1;}
1310 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1312 _LIBCPP_INLINE_VISIBILITY
1313 void __set_long_size(size_type __s) _NOEXCEPT
1314 {__r_.first().__l.__size_ = __s;}
1315 _LIBCPP_INLINE_VISIBILITY
1316 size_type __get_long_size() const _NOEXCEPT
1317 {return __r_.first().__l.__size_;}
1318 _LIBCPP_INLINE_VISIBILITY
1319 void __set_size(size_type __s) _NOEXCEPT
1320 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1322 _LIBCPP_INLINE_VISIBILITY
1323 void __set_long_cap(size_type __s) _NOEXCEPT
1324 {__r_.first().__l.__cap_ = __long_mask | __s;}
1325 _LIBCPP_INLINE_VISIBILITY
1326 size_type __get_long_cap() const _NOEXCEPT
1327 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1329 _LIBCPP_INLINE_VISIBILITY
1330 void __set_long_pointer(pointer __p) _NOEXCEPT
1331 {__r_.first().__l.__data_ = __p;}
1332 _LIBCPP_INLINE_VISIBILITY
1333 pointer __get_long_pointer() _NOEXCEPT
1334 {return __r_.first().__l.__data_;}
1335 _LIBCPP_INLINE_VISIBILITY
1336 const_pointer __get_long_pointer() const _NOEXCEPT
1337 {return __r_.first().__l.__data_;}
1338 _LIBCPP_INLINE_VISIBILITY
1339 pointer __get_short_pointer() _NOEXCEPT
1340 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1341 _LIBCPP_INLINE_VISIBILITY
1342 const_pointer __get_short_pointer() const _NOEXCEPT
1343 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1344 _LIBCPP_INLINE_VISIBILITY
1345 pointer __get_pointer() _NOEXCEPT
1346 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1347 _LIBCPP_INLINE_VISIBILITY
1348 const_pointer __get_pointer() const _NOEXCEPT
1349 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1351 _LIBCPP_INLINE_VISIBILITY
1352 void __zero() _NOEXCEPT
1354 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1355 for (unsigned __i = 0; __i < __n_words; ++__i)
1359 template <size_type __a> static
1360 _LIBCPP_INLINE_VISIBILITY
1361 size_type __align_it(size_type __s) _NOEXCEPT
1362 {return (__s + (__a-1)) & ~(__a-1);}
1363 enum {__alignment = 16};
1364 static _LIBCPP_INLINE_VISIBILITY
1365 size_type __recommend(size_type __s) _NOEXCEPT
1366 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
1367 __align_it<sizeof(value_type) < __alignment ?
1368 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
1371 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1373 void __init(const value_type* __s, size_type __sz);
1375 void __init(size_type __n, value_type __c);
1377 template <class _InputIterator>
1381 __is_exactly_input_iterator<_InputIterator>::value,
1384 __init(_InputIterator __first, _InputIterator __last);
1386 template <class _ForwardIterator>
1390 __is_forward_iterator<_ForwardIterator>::value,
1393 __init(_ForwardIterator __first, _ForwardIterator __last);
1395 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1396 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1397 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1398 size_type __n_copy, size_type __n_del,
1399 size_type __n_add, const value_type* __p_new_stuff);
1401 _LIBCPP_INLINE_VISIBILITY
1402 void __erase_to_end(size_type __pos);
1404 _LIBCPP_INLINE_VISIBILITY
1405 void __copy_assign_alloc(const basic_string& __str)
1406 {__copy_assign_alloc(__str, integral_constant<bool,
1407 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1409 _LIBCPP_INLINE_VISIBILITY
1410 void __copy_assign_alloc(const basic_string& __str, true_type)
1412 if (__alloc() == __str.__alloc())
1413 __alloc() = __str.__alloc();
1416 if (!__str.__is_long())
1420 __alloc() = __str.__alloc();
1424 allocator_type __a = __str.__alloc();
1425 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1428 __alloc() = _VSTD::move(__a);
1429 __set_long_pointer(__p);
1430 __set_long_cap(__str.__get_long_cap());
1431 __set_long_size(__str.size());
1436 _LIBCPP_INLINE_VISIBILITY
1437 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
1440 #ifndef _LIBCPP_CXX03_LANG
1441 _LIBCPP_INLINE_VISIBILITY
1442 void __move_assign(basic_string& __str, false_type)
1443 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
1444 _LIBCPP_INLINE_VISIBILITY
1445 void __move_assign(basic_string& __str, true_type)
1446 #if _LIBCPP_STD_VER > 14
1449 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1453 _LIBCPP_INLINE_VISIBILITY
1455 __move_assign_alloc(basic_string& __str)
1457 !__alloc_traits::propagate_on_container_move_assignment::value ||
1458 is_nothrow_move_assignable<allocator_type>::value)
1459 {__move_assign_alloc(__str, integral_constant<bool,
1460 __alloc_traits::propagate_on_container_move_assignment::value>());}
1462 _LIBCPP_INLINE_VISIBILITY
1463 void __move_assign_alloc(basic_string& __c, true_type)
1464 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1466 __alloc() = _VSTD::move(__c.__alloc());
1469 _LIBCPP_INLINE_VISIBILITY
1470 void __move_assign_alloc(basic_string&, false_type)
1474 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1475 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
1477 friend basic_string operator+<>(const basic_string&, const basic_string&);
1478 friend basic_string operator+<>(const value_type*, const basic_string&);
1479 friend basic_string operator+<>(value_type, const basic_string&);
1480 friend basic_string operator+<>(const basic_string&, const value_type*);
1481 friend basic_string operator+<>(const basic_string&, value_type);
1484 template <class _CharT, class _Traits, class _Allocator>
1485 inline _LIBCPP_INLINE_VISIBILITY
1487 basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1489 #if _LIBCPP_DEBUG_LEVEL >= 2
1490 __get_db()->__invalidate_all(this);
1491 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1494 template <class _CharT, class _Traits, class _Allocator>
1495 inline _LIBCPP_INLINE_VISIBILITY
1497 basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1498 #if _LIBCPP_DEBUG_LEVEL >= 2
1503 #if _LIBCPP_DEBUG_LEVEL >= 2
1504 __c_node* __c = __get_db()->__find_c_and_lock(this);
1507 const_pointer __new_last = __get_pointer() + __pos;
1508 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1511 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1512 if (__i->base() > __new_last)
1514 (*__p)->__c_ = nullptr;
1515 if (--__c->end_ != __p)
1516 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1519 __get_db()->unlock();
1521 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1524 template <class _CharT, class _Traits, class _Allocator>
1525 inline _LIBCPP_INLINE_VISIBILITY
1526 basic_string<_CharT, _Traits, _Allocator>::basic_string()
1527 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1529 #if _LIBCPP_DEBUG_LEVEL >= 2
1530 __get_db()->__insert_c(this);
1535 template <class _CharT, class _Traits, class _Allocator>
1536 inline _LIBCPP_INLINE_VISIBILITY
1537 basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1538 #if _LIBCPP_STD_VER <= 14
1539 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1543 : __r_(__second_tag(), __a)
1545 #if _LIBCPP_DEBUG_LEVEL >= 2
1546 __get_db()->__insert_c(this);
1551 template <class _CharT, class _Traits, class _Allocator>
1552 void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1554 size_type __reserve)
1556 if (__reserve > max_size())
1557 this->__throw_length_error();
1559 if (__reserve < __min_cap)
1561 __set_short_size(__sz);
1562 __p = __get_short_pointer();
1566 size_type __cap = __recommend(__reserve);
1567 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1568 __set_long_pointer(__p);
1569 __set_long_cap(__cap+1);
1570 __set_long_size(__sz);
1572 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1573 traits_type::assign(__p[__sz], value_type());
1576 template <class _CharT, class _Traits, class _Allocator>
1578 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1580 if (__sz > max_size())
1581 this->__throw_length_error();
1583 if (__sz < __min_cap)
1585 __set_short_size(__sz);
1586 __p = __get_short_pointer();
1590 size_type __cap = __recommend(__sz);
1591 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1592 __set_long_pointer(__p);
1593 __set_long_cap(__cap+1);
1594 __set_long_size(__sz);
1596 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1597 traits_type::assign(__p[__sz], value_type());
1600 template <class _CharT, class _Traits, class _Allocator>
1601 inline _LIBCPP_INLINE_VISIBILITY
1602 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s)
1604 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
1605 __init(__s, traits_type::length(__s));
1606 #if _LIBCPP_DEBUG_LEVEL >= 2
1607 __get_db()->__insert_c(this);
1611 template <class _CharT, class _Traits, class _Allocator>
1612 inline _LIBCPP_INLINE_VISIBILITY
1613 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
1614 : __r_(__second_tag(), __a)
1616 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
1617 __init(__s, traits_type::length(__s));
1618 #if _LIBCPP_DEBUG_LEVEL >= 2
1619 __get_db()->__insert_c(this);
1623 template <class _CharT, class _Traits, class _Allocator>
1624 inline _LIBCPP_INLINE_VISIBILITY
1625 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
1627 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
1629 #if _LIBCPP_DEBUG_LEVEL >= 2
1630 __get_db()->__insert_c(this);
1634 template <class _CharT, class _Traits, class _Allocator>
1635 inline _LIBCPP_INLINE_VISIBILITY
1636 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1637 : __r_(__second_tag(), __a)
1639 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
1641 #if _LIBCPP_DEBUG_LEVEL >= 2
1642 __get_db()->__insert_c(this);
1646 template <class _CharT, class _Traits, class _Allocator>
1647 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1648 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
1650 if (!__str.__is_long())
1651 __r_.first().__r = __str.__r_.first().__r;
1653 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1654 #if _LIBCPP_DEBUG_LEVEL >= 2
1655 __get_db()->__insert_c(this);
1659 template <class _CharT, class _Traits, class _Allocator>
1660 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1661 const basic_string& __str, const allocator_type& __a)
1662 : __r_(__second_tag(), __a)
1664 if (!__str.__is_long())
1665 __r_.first().__r = __str.__r_.first().__r;
1667 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1668 #if _LIBCPP_DEBUG_LEVEL >= 2
1669 __get_db()->__insert_c(this);
1673 #ifndef _LIBCPP_CXX03_LANG
1675 template <class _CharT, class _Traits, class _Allocator>
1676 inline _LIBCPP_INLINE_VISIBILITY
1677 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1678 #if _LIBCPP_STD_VER <= 14
1679 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1683 : __r_(_VSTD::move(__str.__r_))
1686 #if _LIBCPP_DEBUG_LEVEL >= 2
1687 __get_db()->__insert_c(this);
1689 __get_db()->swap(this, &__str);
1693 template <class _CharT, class _Traits, class _Allocator>
1694 inline _LIBCPP_INLINE_VISIBILITY
1695 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1696 : __r_(__second_tag(), __a)
1698 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
1699 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1702 __r_.first().__r = __str.__r_.first().__r;
1705 #if _LIBCPP_DEBUG_LEVEL >= 2
1706 __get_db()->__insert_c(this);
1708 __get_db()->swap(this, &__str);
1712 #endif // _LIBCPP_CXX03_LANG
1714 template <class _CharT, class _Traits, class _Allocator>
1716 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1718 if (__n > max_size())
1719 this->__throw_length_error();
1721 if (__n < __min_cap)
1723 __set_short_size(__n);
1724 __p = __get_short_pointer();
1728 size_type __cap = __recommend(__n);
1729 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1730 __set_long_pointer(__p);
1731 __set_long_cap(__cap+1);
1732 __set_long_size(__n);
1734 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
1735 traits_type::assign(__p[__n], value_type());
1738 template <class _CharT, class _Traits, class _Allocator>
1739 inline _LIBCPP_INLINE_VISIBILITY
1740 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
1743 #if _LIBCPP_DEBUG_LEVEL >= 2
1744 __get_db()->__insert_c(this);
1748 template <class _CharT, class _Traits, class _Allocator>
1749 inline _LIBCPP_INLINE_VISIBILITY
1750 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
1751 : __r_(__second_tag(), __a)
1754 #if _LIBCPP_DEBUG_LEVEL >= 2
1755 __get_db()->__insert_c(this);
1759 template <class _CharT, class _Traits, class _Allocator>
1760 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1761 size_type __pos, size_type __n,
1762 const _Allocator& __a)
1763 : __r_(__second_tag(), __a)
1765 size_type __str_sz = __str.size();
1766 if (__pos > __str_sz)
1767 this->__throw_out_of_range();
1768 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
1769 #if _LIBCPP_DEBUG_LEVEL >= 2
1770 __get_db()->__insert_c(this);
1774 template <class _CharT, class _Traits, class _Allocator>
1775 inline _LIBCPP_INLINE_VISIBILITY
1776 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1777 const _Allocator& __a)
1778 : __r_(__second_tag(), __a)
1780 size_type __str_sz = __str.size();
1781 if (__pos > __str_sz)
1782 this->__throw_out_of_range();
1783 __init(__str.data() + __pos, __str_sz - __pos);
1784 #if _LIBCPP_DEBUG_LEVEL >= 2
1785 __get_db()->__insert_c(this);
1789 template <class _CharT, class _Traits, class _Allocator>
1790 template <class _Tp>
1791 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1792 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
1793 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
1794 : __r_(__second_tag(), __a)
1796 __self_view __sv = __self_view(__t).substr(__pos, __n);
1797 __init(__sv.data(), __sv.size());
1798 #if _LIBCPP_DEBUG_LEVEL >= 2
1799 __get_db()->__insert_c(this);
1803 template <class _CharT, class _Traits, class _Allocator>
1804 inline _LIBCPP_INLINE_VISIBILITY
1805 basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1807 __init(__sv.data(), __sv.size());
1808 #if _LIBCPP_DEBUG_LEVEL >= 2
1809 __get_db()->__insert_c(this);
1813 template <class _CharT, class _Traits, class _Allocator>
1814 inline _LIBCPP_INLINE_VISIBILITY
1815 basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a)
1816 : __r_(__second_tag(), __a)
1818 __init(__sv.data(), __sv.size());
1819 #if _LIBCPP_DEBUG_LEVEL >= 2
1820 __get_db()->__insert_c(this);
1824 template <class _CharT, class _Traits, class _Allocator>
1825 template <class _InputIterator>
1828 __is_exactly_input_iterator<_InputIterator>::value,
1831 basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1834 #ifndef _LIBCPP_NO_EXCEPTIONS
1837 #endif // _LIBCPP_NO_EXCEPTIONS
1838 for (; __first != __last; ++__first)
1839 push_back(*__first);
1840 #ifndef _LIBCPP_NO_EXCEPTIONS
1845 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
1848 #endif // _LIBCPP_NO_EXCEPTIONS
1851 template <class _CharT, class _Traits, class _Allocator>
1852 template <class _ForwardIterator>
1855 __is_forward_iterator<_ForwardIterator>::value,
1858 basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1860 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
1861 if (__sz > max_size())
1862 this->__throw_length_error();
1864 if (__sz < __min_cap)
1866 __set_short_size(__sz);
1867 __p = __get_short_pointer();
1871 size_type __cap = __recommend(__sz);
1872 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1873 __set_long_pointer(__p);
1874 __set_long_cap(__cap+1);
1875 __set_long_size(__sz);
1877 for (; __first != __last; ++__first, (void) ++__p)
1878 traits_type::assign(*__p, *__first);
1879 traits_type::assign(*__p, value_type());
1882 template <class _CharT, class _Traits, class _Allocator>
1883 template<class _InputIterator>
1884 inline _LIBCPP_INLINE_VISIBILITY
1885 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1887 __init(__first, __last);
1888 #if _LIBCPP_DEBUG_LEVEL >= 2
1889 __get_db()->__insert_c(this);
1893 template <class _CharT, class _Traits, class _Allocator>
1894 template<class _InputIterator>
1895 inline _LIBCPP_INLINE_VISIBILITY
1896 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1897 const allocator_type& __a)
1898 : __r_(__second_tag(), __a)
1900 __init(__first, __last);
1901 #if _LIBCPP_DEBUG_LEVEL >= 2
1902 __get_db()->__insert_c(this);
1906 #ifndef _LIBCPP_CXX03_LANG
1908 template <class _CharT, class _Traits, class _Allocator>
1909 inline _LIBCPP_INLINE_VISIBILITY
1910 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1911 initializer_list<_CharT> __il)
1913 __init(__il.begin(), __il.end());
1914 #if _LIBCPP_DEBUG_LEVEL >= 2
1915 __get_db()->__insert_c(this);
1919 template <class _CharT, class _Traits, class _Allocator>
1920 inline _LIBCPP_INLINE_VISIBILITY
1922 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1923 initializer_list<_CharT> __il, const _Allocator& __a)
1924 : __r_(__second_tag(), __a)
1926 __init(__il.begin(), __il.end());
1927 #if _LIBCPP_DEBUG_LEVEL >= 2
1928 __get_db()->__insert_c(this);
1932 #endif // _LIBCPP_CXX03_LANG
1934 template <class _CharT, class _Traits, class _Allocator>
1935 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1937 #if _LIBCPP_DEBUG_LEVEL >= 2
1938 __get_db()->__erase_c(this);
1941 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
1944 template <class _CharT, class _Traits, class _Allocator>
1946 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1947 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1948 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
1950 size_type __ms = max_size();
1951 if (__delta_cap > __ms - __old_cap - 1)
1952 this->__throw_length_error();
1953 pointer __old_p = __get_pointer();
1954 size_type __cap = __old_cap < __ms / 2 - __alignment ?
1955 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
1957 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
1958 __invalidate_all_iterators();
1960 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1961 _VSTD::__to_raw_pointer(__old_p), __n_copy);
1963 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
1964 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1965 if (__sec_cp_sz != 0)
1966 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1967 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
1968 if (__old_cap+1 != __min_cap)
1969 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
1970 __set_long_pointer(__p);
1971 __set_long_cap(__cap+1);
1972 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1973 __set_long_size(__old_sz);
1974 traits_type::assign(__p[__old_sz], value_type());
1977 template <class _CharT, class _Traits, class _Allocator>
1979 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1980 size_type __n_copy, size_type __n_del, size_type __n_add)
1982 size_type __ms = max_size();
1983 if (__delta_cap > __ms - __old_cap)
1984 this->__throw_length_error();
1985 pointer __old_p = __get_pointer();
1986 size_type __cap = __old_cap < __ms / 2 - __alignment ?
1987 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
1989 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
1990 __invalidate_all_iterators();
1992 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1993 _VSTD::__to_raw_pointer(__old_p), __n_copy);
1994 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1995 if (__sec_cp_sz != 0)
1996 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1997 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
1999 if (__old_cap+1 != __min_cap)
2000 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2001 __set_long_pointer(__p);
2002 __set_long_cap(__cap+1);
2007 template <class _CharT, class _Traits, class _Allocator>
2008 basic_string<_CharT, _Traits, _Allocator>&
2009 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2011 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2012 size_type __cap = capacity();
2015 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2016 traits_type::move(__p, __s, __n);
2017 traits_type::assign(__p[__n], value_type());
2019 __invalidate_iterators_past(__n);
2023 size_type __sz = size();
2024 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2029 template <class _CharT, class _Traits, class _Allocator>
2030 basic_string<_CharT, _Traits, _Allocator>&
2031 basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2033 size_type __cap = capacity();
2036 size_type __sz = size();
2037 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2040 __invalidate_iterators_past(__n);
2041 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2042 traits_type::assign(__p, __n, __c);
2043 traits_type::assign(__p[__n], value_type());
2048 template <class _CharT, class _Traits, class _Allocator>
2049 basic_string<_CharT, _Traits, _Allocator>&
2050 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2055 __p = __get_long_pointer();
2060 __p = __get_short_pointer();
2061 __set_short_size(1);
2063 traits_type::assign(*__p, __c);
2064 traits_type::assign(*++__p, value_type());
2065 __invalidate_iterators_past(1);
2069 template <class _CharT, class _Traits, class _Allocator>
2070 basic_string<_CharT, _Traits, _Allocator>&
2071 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2075 __copy_assign_alloc(__str);
2076 assign(__str.data(), __str.size());
2081 #ifndef _LIBCPP_CXX03_LANG
2083 template <class _CharT, class _Traits, class _Allocator>
2084 inline _LIBCPP_INLINE_VISIBILITY
2086 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2087 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
2089 if (__alloc() != __str.__alloc())
2092 __move_assign(__str, true_type());
2095 template <class _CharT, class _Traits, class _Allocator>
2096 inline _LIBCPP_INLINE_VISIBILITY
2098 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2099 #if _LIBCPP_STD_VER > 14
2102 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2107 __r_.first() = __str.__r_.first();
2108 __move_assign_alloc(__str);
2112 template <class _CharT, class _Traits, class _Allocator>
2113 inline _LIBCPP_INLINE_VISIBILITY
2114 basic_string<_CharT, _Traits, _Allocator>&
2115 basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2116 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2118 __move_assign(__str, integral_constant<bool,
2119 __alloc_traits::propagate_on_container_move_assignment::value>());
2125 template <class _CharT, class _Traits, class _Allocator>
2126 template<class _InputIterator>
2129 __is_exactly_input_iterator <_InputIterator>::value
2130 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2131 basic_string<_CharT, _Traits, _Allocator>&
2133 basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2135 const basic_string __temp(__first, __last, __alloc());
2136 assign(__temp.data(), __temp.size());
2140 template <class _CharT, class _Traits, class _Allocator>
2141 template<class _ForwardIterator>
2144 __is_forward_iterator<_ForwardIterator>::value
2145 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
2146 basic_string<_CharT, _Traits, _Allocator>&
2148 basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2150 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2151 size_type __cap = capacity();
2154 size_type __sz = size();
2155 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2158 __invalidate_iterators_past(__n);
2159 pointer __p = __get_pointer();
2160 for (; __first != __last; ++__first, ++__p)
2161 traits_type::assign(*__p, *__first);
2162 traits_type::assign(*__p, value_type());
2167 template <class _CharT, class _Traits, class _Allocator>
2168 basic_string<_CharT, _Traits, _Allocator>&
2169 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2171 size_type __sz = __str.size();
2173 this->__throw_out_of_range();
2174 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2177 template <class _CharT, class _Traits, class _Allocator>
2178 template <class _Tp>
2181 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2182 basic_string<_CharT, _Traits, _Allocator>&
2184 basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
2186 __self_view __sv = __t;
2187 size_type __sz = __sv.size();
2189 this->__throw_out_of_range();
2190 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2194 template <class _CharT, class _Traits, class _Allocator>
2195 basic_string<_CharT, _Traits, _Allocator>&
2196 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2198 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2199 return assign(__s, traits_type::length(__s));
2204 template <class _CharT, class _Traits, class _Allocator>
2205 basic_string<_CharT, _Traits, _Allocator>&
2206 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2208 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
2209 size_type __cap = capacity();
2210 size_type __sz = size();
2211 if (__cap - __sz >= __n)
2215 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2216 traits_type::copy(__p + __sz, __s, __n);
2219 traits_type::assign(__p[__sz], value_type());
2223 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2227 template <class _CharT, class _Traits, class _Allocator>
2228 basic_string<_CharT, _Traits, _Allocator>&
2229 basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2233 size_type __cap = capacity();
2234 size_type __sz = size();
2235 if (__cap - __sz < __n)
2236 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2237 pointer __p = __get_pointer();
2238 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
2241 traits_type::assign(__p[__sz], value_type());
2246 template <class _CharT, class _Traits, class _Allocator>
2248 basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2250 bool __is_short = !__is_long();
2255 __cap = __min_cap - 1;
2256 __sz = __get_short_size();
2260 __cap = __get_long_cap() - 1;
2261 __sz = __get_long_size();
2265 __grow_by(__cap, 1, __sz, __sz, 0);
2266 __is_short = !__is_long();
2271 __p = __get_short_pointer() + __sz;
2272 __set_short_size(__sz+1);
2276 __p = __get_long_pointer() + __sz;
2277 __set_long_size(__sz+1);
2279 traits_type::assign(*__p, __c);
2280 traits_type::assign(*++__p, value_type());
2283 template <class _Tp>
2284 bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2286 return __first <= __p && __p < __last;
2289 template <class _Tp1, class _Tp2>
2290 bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
2295 template <class _CharT, class _Traits, class _Allocator>
2296 template<class _ForwardIterator>
2297 basic_string<_CharT, _Traits, _Allocator>&
2298 basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2299 _ForwardIterator __first, _ForwardIterator __last)
2301 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2302 "function requires a ForwardIterator");
2303 size_type __sz = size();
2304 size_type __cap = capacity();
2305 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2308 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2309 _CharRef __tmp_ref = *__first;
2310 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
2312 const basic_string __temp (__first, __last, __alloc());
2313 append(__temp.data(), __temp.size());
2317 if (__cap - __sz < __n)
2318 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2319 pointer __p = __get_pointer() + __sz;
2320 for (; __first != __last; ++__p, ++__first)
2321 traits_type::assign(*__p, *__first);
2322 traits_type::assign(*__p, value_type());
2323 __set_size(__sz + __n);
2329 template <class _CharT, class _Traits, class _Allocator>
2330 inline _LIBCPP_INLINE_VISIBILITY
2331 basic_string<_CharT, _Traits, _Allocator>&
2332 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2334 return append(__str.data(), __str.size());
2337 template <class _CharT, class _Traits, class _Allocator>
2338 basic_string<_CharT, _Traits, _Allocator>&
2339 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2341 size_type __sz = __str.size();
2343 this->__throw_out_of_range();
2344 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2347 template <class _CharT, class _Traits, class _Allocator>
2348 template <class _Tp>
2351 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2352 basic_string<_CharT, _Traits, _Allocator>&
2354 basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
2356 __self_view __sv = __t;
2357 size_type __sz = __sv.size();
2359 this->__throw_out_of_range();
2360 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2363 template <class _CharT, class _Traits, class _Allocator>
2364 basic_string<_CharT, _Traits, _Allocator>&
2365 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2367 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
2368 return append(__s, traits_type::length(__s));
2373 template <class _CharT, class _Traits, class _Allocator>
2374 basic_string<_CharT, _Traits, _Allocator>&
2375 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2377 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
2378 size_type __sz = size();
2380 this->__throw_out_of_range();
2381 size_type __cap = capacity();
2382 if (__cap - __sz >= __n)
2386 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2387 size_type __n_move = __sz - __pos;
2390 if (__p + __pos <= __s && __s < __p + __sz)
2392 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2394 traits_type::move(__p + __pos, __s, __n);
2397 traits_type::assign(__p[__sz], value_type());
2401 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2405 template <class _CharT, class _Traits, class _Allocator>
2406 basic_string<_CharT, _Traits, _Allocator>&
2407 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2409 size_type __sz = size();
2411 this->__throw_out_of_range();
2414 size_type __cap = capacity();
2416 if (__cap - __sz >= __n)
2418 __p = _VSTD::__to_raw_pointer(__get_pointer());
2419 size_type __n_move = __sz - __pos;
2421 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2425 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2426 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2428 traits_type::assign(__p + __pos, __n, __c);
2431 traits_type::assign(__p[__sz], value_type());
2436 template <class _CharT, class _Traits, class _Allocator>
2437 template<class _InputIterator>
2440 __is_exactly_input_iterator<_InputIterator>::value
2441 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2442 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2444 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2446 #if _LIBCPP_DEBUG_LEVEL >= 2
2447 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2448 "string::insert(iterator, range) called with an iterator not"
2449 " referring to this string");
2451 const basic_string __temp(__first, __last, __alloc());
2452 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2455 template <class _CharT, class _Traits, class _Allocator>
2456 template<class _ForwardIterator>
2459 __is_forward_iterator<_ForwardIterator>::value
2460 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
2461 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2463 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2465 #if _LIBCPP_DEBUG_LEVEL >= 2
2466 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2467 "string::insert(iterator, range) called with an iterator not"
2468 " referring to this string");
2470 size_type __ip = static_cast<size_type>(__pos - begin());
2471 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2474 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2475 _CharRef __tmp_char = *__first;
2476 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
2478 const basic_string __temp(__first, __last, __alloc());
2479 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2482 size_type __sz = size();
2483 size_type __cap = capacity();
2485 if (__cap - __sz >= __n)
2487 __p = _VSTD::__to_raw_pointer(__get_pointer());
2488 size_type __n_move = __sz - __ip;
2490 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2494 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2495 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2499 traits_type::assign(__p[__sz], value_type());
2500 for (__p += __ip; __first != __last; ++__p, ++__first)
2501 traits_type::assign(*__p, *__first);
2503 return begin() + __ip;
2506 template <class _CharT, class _Traits, class _Allocator>
2507 inline _LIBCPP_INLINE_VISIBILITY
2508 basic_string<_CharT, _Traits, _Allocator>&
2509 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2511 return insert(__pos1, __str.data(), __str.size());
2514 template <class _CharT, class _Traits, class _Allocator>
2515 basic_string<_CharT, _Traits, _Allocator>&
2516 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2517 size_type __pos2, size_type __n)
2519 size_type __str_sz = __str.size();
2520 if (__pos2 > __str_sz)
2521 this->__throw_out_of_range();
2522 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2525 template <class _CharT, class _Traits, class _Allocator>
2526 template <class _Tp>
2529 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2530 basic_string<_CharT, _Traits, _Allocator>&
2532 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
2533 size_type __pos2, size_type __n)
2535 __self_view __sv = __t;
2536 size_type __str_sz = __sv.size();
2537 if (__pos2 > __str_sz)
2538 this->__throw_out_of_range();
2539 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2542 template <class _CharT, class _Traits, class _Allocator>
2543 basic_string<_CharT, _Traits, _Allocator>&
2544 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2546 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
2547 return insert(__pos, __s, traits_type::length(__s));
2550 template <class _CharT, class _Traits, class _Allocator>
2551 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2552 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2554 size_type __ip = static_cast<size_type>(__pos - begin());
2555 size_type __sz = size();
2556 size_type __cap = capacity();
2560 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2561 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2565 __p = _VSTD::__to_raw_pointer(__get_pointer());
2566 size_type __n_move = __sz - __ip;
2568 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2570 traits_type::assign(__p[__ip], __c);
2571 traits_type::assign(__p[++__sz], value_type());
2573 return begin() + static_cast<difference_type>(__ip);
2576 template <class _CharT, class _Traits, class _Allocator>
2577 inline _LIBCPP_INLINE_VISIBILITY
2578 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2579 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2581 #if _LIBCPP_DEBUG_LEVEL >= 2
2582 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2583 "string::insert(iterator, n, value) called with an iterator not"
2584 " referring to this string");
2586 difference_type __p = __pos - begin();
2587 insert(static_cast<size_type>(__p), __n, __c);
2588 return begin() + __p;
2593 template <class _CharT, class _Traits, class _Allocator>
2594 basic_string<_CharT, _Traits, _Allocator>&
2595 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2596 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
2598 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
2599 size_type __sz = size();
2601 this->__throw_out_of_range();
2602 __n1 = _VSTD::min(__n1, __sz - __pos);
2603 size_type __cap = capacity();
2604 if (__cap - __sz + __n1 >= __n2)
2606 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2609 size_type __n_move = __sz - __pos - __n1;
2614 traits_type::move(__p + __pos, __s, __n2);
2615 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2618 if (__p + __pos < __s && __s < __p + __sz)
2620 if (__p + __pos + __n1 <= __s)
2622 else // __p + __pos < __s < __p + __pos + __n1
2624 traits_type::move(__p + __pos, __s, __n1);
2631 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2634 traits_type::move(__p + __pos, __s, __n2);
2636 // __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2637 // but this is a safe operation, so we disable the check.
2638 __sz += __n2 - __n1;
2640 __invalidate_iterators_past(__sz);
2641 traits_type::assign(__p[__sz], value_type());
2644 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2648 template <class _CharT, class _Traits, class _Allocator>
2649 basic_string<_CharT, _Traits, _Allocator>&
2650 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2651 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
2653 size_type __sz = size();
2655 this->__throw_out_of_range();
2656 __n1 = _VSTD::min(__n1, __sz - __pos);
2657 size_type __cap = capacity();
2659 if (__cap - __sz + __n1 >= __n2)
2661 __p = _VSTD::__to_raw_pointer(__get_pointer());
2664 size_type __n_move = __sz - __pos - __n1;
2666 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2671 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2672 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2674 traits_type::assign(__p + __pos, __n2, __c);
2675 __sz += __n2 - __n1;
2677 __invalidate_iterators_past(__sz);
2678 traits_type::assign(__p[__sz], value_type());
2682 template <class _CharT, class _Traits, class _Allocator>
2683 template<class _InputIterator>
2686 __is_input_iterator<_InputIterator>::value,
2687 basic_string<_CharT, _Traits, _Allocator>&
2689 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
2690 _InputIterator __j1, _InputIterator __j2)
2692 const basic_string __temp(__j1, __j2, __alloc());
2693 return this->replace(__i1, __i2, __temp);
2696 template <class _CharT, class _Traits, class _Allocator>
2697 inline _LIBCPP_INLINE_VISIBILITY
2698 basic_string<_CharT, _Traits, _Allocator>&
2699 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2701 return replace(__pos1, __n1, __str.data(), __str.size());
2704 template <class _CharT, class _Traits, class _Allocator>
2705 basic_string<_CharT, _Traits, _Allocator>&
2706 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2707 size_type __pos2, size_type __n2)
2709 size_type __str_sz = __str.size();
2710 if (__pos2 > __str_sz)
2711 this->__throw_out_of_range();
2712 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2715 template <class _CharT, class _Traits, class _Allocator>
2716 template <class _Tp>
2719 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2720 basic_string<_CharT, _Traits, _Allocator>&
2722 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
2723 size_type __pos2, size_type __n2)
2725 __self_view __sv = __t;
2726 size_type __str_sz = __sv.size();
2727 if (__pos2 > __str_sz)
2728 this->__throw_out_of_range();
2729 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2732 template <class _CharT, class _Traits, class _Allocator>
2733 basic_string<_CharT, _Traits, _Allocator>&
2734 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
2736 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
2737 return replace(__pos, __n1, __s, traits_type::length(__s));
2740 template <class _CharT, class _Traits, class _Allocator>
2741 inline _LIBCPP_INLINE_VISIBILITY
2742 basic_string<_CharT, _Traits, _Allocator>&
2743 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
2745 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2746 __str.data(), __str.size());
2749 template <class _CharT, class _Traits, class _Allocator>
2750 inline _LIBCPP_INLINE_VISIBILITY
2751 basic_string<_CharT, _Traits, _Allocator>&
2752 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
2754 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2757 template <class _CharT, class _Traits, class _Allocator>
2758 inline _LIBCPP_INLINE_VISIBILITY
2759 basic_string<_CharT, _Traits, _Allocator>&
2760 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
2762 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2765 template <class _CharT, class _Traits, class _Allocator>
2766 inline _LIBCPP_INLINE_VISIBILITY
2767 basic_string<_CharT, _Traits, _Allocator>&
2768 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
2770 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2775 template <class _CharT, class _Traits, class _Allocator>
2776 basic_string<_CharT, _Traits, _Allocator>&
2777 basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2779 size_type __sz = size();
2781 this->__throw_out_of_range();
2784 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2785 __n = _VSTD::min(__n, __sz - __pos);
2786 size_type __n_move = __sz - __pos - __n;
2788 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2791 __invalidate_iterators_past(__sz);
2792 traits_type::assign(__p[__sz], value_type());
2797 template <class _CharT, class _Traits, class _Allocator>
2798 inline _LIBCPP_INLINE_VISIBILITY
2799 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2800 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2802 #if _LIBCPP_DEBUG_LEVEL >= 2
2803 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2804 "string::erase(iterator) called with an iterator not"
2805 " referring to this string");
2807 _LIBCPP_ASSERT(__pos != end(),
2808 "string::erase(iterator) called with a non-dereferenceable iterator");
2809 iterator __b = begin();
2810 size_type __r = static_cast<size_type>(__pos - __b);
2812 return __b + static_cast<difference_type>(__r);
2815 template <class _CharT, class _Traits, class _Allocator>
2816 inline _LIBCPP_INLINE_VISIBILITY
2817 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2818 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2820 #if _LIBCPP_DEBUG_LEVEL >= 2
2821 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2822 "string::erase(iterator, iterator) called with an iterator not"
2823 " referring to this string");
2825 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
2826 iterator __b = begin();
2827 size_type __r = static_cast<size_type>(__first - __b);
2828 erase(__r, static_cast<size_type>(__last - __first));
2829 return __b + static_cast<difference_type>(__r);
2832 template <class _CharT, class _Traits, class _Allocator>
2833 inline _LIBCPP_INLINE_VISIBILITY
2835 basic_string<_CharT, _Traits, _Allocator>::pop_back()
2837 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
2841 __sz = __get_long_size() - 1;
2842 __set_long_size(__sz);
2843 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2847 __sz = __get_short_size() - 1;
2848 __set_short_size(__sz);
2849 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2851 __invalidate_iterators_past(__sz);
2854 template <class _CharT, class _Traits, class _Allocator>
2855 inline _LIBCPP_INLINE_VISIBILITY
2857 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
2859 __invalidate_all_iterators();
2862 traits_type::assign(*__get_long_pointer(), value_type());
2867 traits_type::assign(*__get_short_pointer(), value_type());
2868 __set_short_size(0);
2872 template <class _CharT, class _Traits, class _Allocator>
2873 inline _LIBCPP_INLINE_VISIBILITY
2875 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2879 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2880 __set_long_size(__pos);
2884 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2885 __set_short_size(__pos);
2887 __invalidate_iterators_past(__pos);
2890 template <class _CharT, class _Traits, class _Allocator>
2892 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2894 size_type __sz = size();
2896 append(__n - __sz, __c);
2898 __erase_to_end(__n);
2901 template <class _CharT, class _Traits, class _Allocator>
2902 inline _LIBCPP_INLINE_VISIBILITY
2903 typename basic_string<_CharT, _Traits, _Allocator>::size_type
2904 basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
2906 size_type __m = __alloc_traits::max_size(__alloc());
2907 #ifdef _LIBCPP_BIG_ENDIAN
2908 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
2910 return __m - __alignment;
2914 template <class _CharT, class _Traits, class _Allocator>
2916 basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2918 if (__res_arg > max_size())
2919 this->__throw_length_error();
2920 size_type __cap = capacity();
2921 size_type __sz = size();
2922 __res_arg = _VSTD::max(__res_arg, __sz);
2923 __res_arg = __recommend(__res_arg);
2924 if (__res_arg != __cap)
2926 pointer __new_data, __p;
2927 bool __was_long, __now_long;
2928 if (__res_arg == __min_cap - 1)
2932 __new_data = __get_short_pointer();
2933 __p = __get_long_pointer();
2937 if (__res_arg > __cap)
2938 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
2941 #ifndef _LIBCPP_NO_EXCEPTIONS
2944 #endif // _LIBCPP_NO_EXCEPTIONS
2945 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
2946 #ifndef _LIBCPP_NO_EXCEPTIONS
2952 #else // _LIBCPP_NO_EXCEPTIONS
2953 if (__new_data == nullptr)
2955 #endif // _LIBCPP_NO_EXCEPTIONS
2958 __was_long = __is_long();
2959 __p = __get_pointer();
2961 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2962 _VSTD::__to_raw_pointer(__p), size()+1);
2964 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
2967 __set_long_cap(__res_arg+1);
2968 __set_long_size(__sz);
2969 __set_long_pointer(__new_data);
2972 __set_short_size(__sz);
2973 __invalidate_all_iterators();
2977 template <class _CharT, class _Traits, class _Allocator>
2978 inline _LIBCPP_INLINE_VISIBILITY
2979 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2980 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
2982 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
2983 return *(data() + __pos);
2986 template <class _CharT, class _Traits, class _Allocator>
2987 inline _LIBCPP_INLINE_VISIBILITY
2988 typename basic_string<_CharT, _Traits, _Allocator>::reference
2989 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
2991 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
2992 return *(__get_pointer() + __pos);
2995 template <class _CharT, class _Traits, class _Allocator>
2996 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2997 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3000 this->__throw_out_of_range();
3001 return (*this)[__n];
3004 template <class _CharT, class _Traits, class _Allocator>
3005 typename basic_string<_CharT, _Traits, _Allocator>::reference
3006 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3009 this->__throw_out_of_range();
3010 return (*this)[__n];
3013 template <class _CharT, class _Traits, class _Allocator>
3014 inline _LIBCPP_INLINE_VISIBILITY
3015 typename basic_string<_CharT, _Traits, _Allocator>::reference
3016 basic_string<_CharT, _Traits, _Allocator>::front()
3018 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3019 return *__get_pointer();
3022 template <class _CharT, class _Traits, class _Allocator>
3023 inline _LIBCPP_INLINE_VISIBILITY
3024 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3025 basic_string<_CharT, _Traits, _Allocator>::front() const
3027 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3031 template <class _CharT, class _Traits, class _Allocator>
3032 inline _LIBCPP_INLINE_VISIBILITY
3033 typename basic_string<_CharT, _Traits, _Allocator>::reference
3034 basic_string<_CharT, _Traits, _Allocator>::back()
3036 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3037 return *(__get_pointer() + size() - 1);
3040 template <class _CharT, class _Traits, class _Allocator>
3041 inline _LIBCPP_INLINE_VISIBILITY
3042 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3043 basic_string<_CharT, _Traits, _Allocator>::back() const
3045 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3046 return *(data() + size() - 1);
3049 template <class _CharT, class _Traits, class _Allocator>
3050 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3051 basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3053 size_type __sz = size();
3055 this->__throw_out_of_range();
3056 size_type __rlen = _VSTD::min(__n, __sz - __pos);
3057 traits_type::copy(__s, data() + __pos, __rlen);
3061 template <class _CharT, class _Traits, class _Allocator>
3062 inline _LIBCPP_INLINE_VISIBILITY
3063 basic_string<_CharT, _Traits, _Allocator>
3064 basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3066 return basic_string(*this, __pos, __n, __alloc());
3069 template <class _CharT, class _Traits, class _Allocator>
3070 inline _LIBCPP_INLINE_VISIBILITY
3072 basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3073 #if _LIBCPP_STD_VER >= 14
3076 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
3077 __is_nothrow_swappable<allocator_type>::value)
3080 #if _LIBCPP_DEBUG_LEVEL >= 2
3082 __get_db()->__invalidate_all(this);
3083 if (!__str.__is_long())
3084 __get_db()->__invalidate_all(&__str);
3085 __get_db()->swap(this, &__str);
3088 __alloc_traits::propagate_on_container_swap::value ||
3089 __alloc_traits::is_always_equal::value ||
3090 __alloc() == __str.__alloc(), "swapping non-equal allocators");
3091 _VSTD::swap(__r_.first(), __str.__r_.first());
3092 __swap_allocator(__alloc(), __str.__alloc());
3097 template <class _Traits>
3098 struct _LIBCPP_HIDDEN __traits_eq
3100 typedef typename _Traits::char_type char_type;
3101 _LIBCPP_INLINE_VISIBILITY
3102 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3103 {return _Traits::eq(__x, __y);}
3106 template<class _CharT, class _Traits, class _Allocator>
3107 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3108 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3110 size_type __n) const _NOEXCEPT
3112 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
3113 return __str_find<value_type, size_type, traits_type, npos>
3114 (data(), size(), __s, __pos, __n);
3117 template<class _CharT, class _Traits, class _Allocator>
3118 inline _LIBCPP_INLINE_VISIBILITY
3119 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3120 basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3121 size_type __pos) const _NOEXCEPT
3123 return __str_find<value_type, size_type, traits_type, npos>
3124 (data(), size(), __str.data(), __pos, __str.size());
3127 template<class _CharT, class _Traits, class _Allocator>
3128 inline _LIBCPP_INLINE_VISIBILITY
3129 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3130 basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3131 size_type __pos) const _NOEXCEPT
3133 return __str_find<value_type, size_type, traits_type, npos>
3134 (data(), size(), __sv.data(), __pos, __sv.size());
3137 template<class _CharT, class _Traits, class _Allocator>
3138 inline _LIBCPP_INLINE_VISIBILITY
3139 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3140 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3141 size_type __pos) const _NOEXCEPT
3143 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
3144 return __str_find<value_type, size_type, traits_type, npos>
3145 (data(), size(), __s, __pos, traits_type::length(__s));
3148 template<class _CharT, class _Traits, class _Allocator>
3149 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3150 basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3151 size_type __pos) const _NOEXCEPT
3153 return __str_find<value_type, size_type, traits_type, npos>
3154 (data(), size(), __c, __pos);
3159 template<class _CharT, class _Traits, class _Allocator>
3160 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3161 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3163 size_type __n) const _NOEXCEPT
3165 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
3166 return __str_rfind<value_type, size_type, traits_type, npos>
3167 (data(), size(), __s, __pos, __n);
3170 template<class _CharT, class _Traits, class _Allocator>
3171 inline _LIBCPP_INLINE_VISIBILITY
3172 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3173 basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3174 size_type __pos) const _NOEXCEPT
3176 return __str_rfind<value_type, size_type, traits_type, npos>
3177 (data(), size(), __str.data(), __pos, __str.size());
3180 template<class _CharT, class _Traits, class _Allocator>
3181 inline _LIBCPP_INLINE_VISIBILITY
3182 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3183 basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3184 size_type __pos) const _NOEXCEPT
3186 return __str_rfind<value_type, size_type, traits_type, npos>
3187 (data(), size(), __sv.data(), __pos, __sv.size());
3190 template<class _CharT, class _Traits, class _Allocator>
3191 inline _LIBCPP_INLINE_VISIBILITY
3192 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3193 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3194 size_type __pos) const _NOEXCEPT
3196 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
3197 return __str_rfind<value_type, size_type, traits_type, npos>
3198 (data(), size(), __s, __pos, traits_type::length(__s));
3201 template<class _CharT, class _Traits, class _Allocator>
3202 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3203 basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3204 size_type __pos) const _NOEXCEPT
3206 return __str_rfind<value_type, size_type, traits_type, npos>
3207 (data(), size(), __c, __pos);
3212 template<class _CharT, class _Traits, class _Allocator>
3213 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3214 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3216 size_type __n) const _NOEXCEPT
3218 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
3219 return __str_find_first_of<value_type, size_type, traits_type, npos>
3220 (data(), size(), __s, __pos, __n);
3223 template<class _CharT, class _Traits, class _Allocator>
3224 inline _LIBCPP_INLINE_VISIBILITY
3225 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3226 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3227 size_type __pos) const _NOEXCEPT
3229 return __str_find_first_of<value_type, size_type, traits_type, npos>
3230 (data(), size(), __str.data(), __pos, __str.size());
3233 template<class _CharT, class _Traits, class _Allocator>
3234 inline _LIBCPP_INLINE_VISIBILITY
3235 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3236 basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3237 size_type __pos) const _NOEXCEPT
3239 return __str_find_first_of<value_type, size_type, traits_type, npos>
3240 (data(), size(), __sv.data(), __pos, __sv.size());
3243 template<class _CharT, class _Traits, class _Allocator>
3244 inline _LIBCPP_INLINE_VISIBILITY
3245 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3246 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3247 size_type __pos) const _NOEXCEPT
3249 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
3250 return __str_find_first_of<value_type, size_type, traits_type, npos>
3251 (data(), size(), __s, __pos, traits_type::length(__s));
3254 template<class _CharT, class _Traits, class _Allocator>
3255 inline _LIBCPP_INLINE_VISIBILITY
3256 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3257 basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3258 size_type __pos) const _NOEXCEPT
3260 return find(__c, __pos);
3265 template<class _CharT, class _Traits, class _Allocator>
3266 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3267 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3269 size_type __n) const _NOEXCEPT
3271 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
3272 return __str_find_last_of<value_type, size_type, traits_type, npos>
3273 (data(), size(), __s, __pos, __n);
3276 template<class _CharT, class _Traits, class _Allocator>
3277 inline _LIBCPP_INLINE_VISIBILITY
3278 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3279 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3280 size_type __pos) const _NOEXCEPT
3282 return __str_find_last_of<value_type, size_type, traits_type, npos>
3283 (data(), size(), __str.data(), __pos, __str.size());
3286 template<class _CharT, class _Traits, class _Allocator>
3287 inline _LIBCPP_INLINE_VISIBILITY
3288 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3289 basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3290 size_type __pos) const _NOEXCEPT
3292 return __str_find_last_of<value_type, size_type, traits_type, npos>
3293 (data(), size(), __sv.data(), __pos, __sv.size());
3296 template<class _CharT, class _Traits, class _Allocator>
3297 inline _LIBCPP_INLINE_VISIBILITY
3298 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3299 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3300 size_type __pos) const _NOEXCEPT
3302 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
3303 return __str_find_last_of<value_type, size_type, traits_type, npos>
3304 (data(), size(), __s, __pos, traits_type::length(__s));
3307 template<class _CharT, class _Traits, class _Allocator>
3308 inline _LIBCPP_INLINE_VISIBILITY
3309 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3310 basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3311 size_type __pos) const _NOEXCEPT
3313 return rfind(__c, __pos);
3316 // find_first_not_of
3318 template<class _CharT, class _Traits, class _Allocator>
3319 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3320 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3322 size_type __n) const _NOEXCEPT
3324 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
3325 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3326 (data(), size(), __s, __pos, __n);
3329 template<class _CharT, class _Traits, class _Allocator>
3330 inline _LIBCPP_INLINE_VISIBILITY
3331 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3332 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3333 size_type __pos) const _NOEXCEPT
3335 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3336 (data(), size(), __str.data(), __pos, __str.size());
3339 template<class _CharT, class _Traits, class _Allocator>
3340 inline _LIBCPP_INLINE_VISIBILITY
3341 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3342 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3343 size_type __pos) const _NOEXCEPT
3345 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3346 (data(), size(), __sv.data(), __pos, __sv.size());
3349 template<class _CharT, class _Traits, class _Allocator>
3350 inline _LIBCPP_INLINE_VISIBILITY
3351 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3352 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3353 size_type __pos) const _NOEXCEPT
3355 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
3356 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3357 (data(), size(), __s, __pos, traits_type::length(__s));
3360 template<class _CharT, class _Traits, class _Allocator>
3361 inline _LIBCPP_INLINE_VISIBILITY
3362 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3363 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3364 size_type __pos) const _NOEXCEPT
3366 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3367 (data(), size(), __c, __pos);
3372 template<class _CharT, class _Traits, class _Allocator>
3373 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3374 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3376 size_type __n) const _NOEXCEPT
3378 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
3379 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3380 (data(), size(), __s, __pos, __n);
3383 template<class _CharT, class _Traits, class _Allocator>
3384 inline _LIBCPP_INLINE_VISIBILITY
3385 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3386 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3387 size_type __pos) const _NOEXCEPT
3389 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3390 (data(), size(), __str.data(), __pos, __str.size());
3393 template<class _CharT, class _Traits, class _Allocator>
3394 inline _LIBCPP_INLINE_VISIBILITY
3395 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3396 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3397 size_type __pos) const _NOEXCEPT
3399 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3400 (data(), size(), __sv.data(), __pos, __sv.size());
3403 template<class _CharT, class _Traits, class _Allocator>
3404 inline _LIBCPP_INLINE_VISIBILITY
3405 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3406 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3407 size_type __pos) const _NOEXCEPT
3409 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
3410 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3411 (data(), size(), __s, __pos, traits_type::length(__s));
3414 template<class _CharT, class _Traits, class _Allocator>
3415 inline _LIBCPP_INLINE_VISIBILITY
3416 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3417 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3418 size_type __pos) const _NOEXCEPT
3420 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3421 (data(), size(), __c, __pos);
3426 template <class _CharT, class _Traits, class _Allocator>
3427 inline _LIBCPP_INLINE_VISIBILITY
3429 basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
3431 size_t __lhs_sz = size();
3432 size_t __rhs_sz = __sv.size();
3433 int __result = traits_type::compare(data(), __sv.data(),
3434 _VSTD::min(__lhs_sz, __rhs_sz));
3437 if (__lhs_sz < __rhs_sz)
3439 if (__lhs_sz > __rhs_sz)
3444 template <class _CharT, class _Traits, class _Allocator>
3445 inline _LIBCPP_INLINE_VISIBILITY
3447 basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3449 return compare(__self_view(__str));
3452 template <class _CharT, class _Traits, class _Allocator>
3454 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3456 const value_type* __s,
3457 size_type __n2) const
3459 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
3460 size_type __sz = size();
3461 if (__pos1 > __sz || __n2 == npos)
3462 this->__throw_out_of_range();
3463 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3464 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
3469 else if (__rlen > __n2)
3475 template <class _CharT, class _Traits, class _Allocator>
3476 inline _LIBCPP_INLINE_VISIBILITY
3478 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3480 __self_view __sv) const
3482 return compare(__pos1, __n1, __sv.data(), __sv.size());
3485 template <class _CharT, class _Traits, class _Allocator>
3486 inline _LIBCPP_INLINE_VISIBILITY
3488 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3490 const basic_string& __str) const
3492 return compare(__pos1, __n1, __str.data(), __str.size());
3495 template <class _CharT, class _Traits, class _Allocator>
3496 template <class _Tp>
3499 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3502 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3506 size_type __n2) const
3508 __self_view __sv = __t;
3509 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3512 template <class _CharT, class _Traits, class _Allocator>
3514 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3516 const basic_string& __str,
3518 size_type __n2) const
3520 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3523 template <class _CharT, class _Traits, class _Allocator>
3525 basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3527 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3528 return compare(0, npos, __s, traits_type::length(__s));
3531 template <class _CharT, class _Traits, class _Allocator>
3533 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3535 const value_type* __s) const
3537 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3538 return compare(__pos1, __n1, __s, traits_type::length(__s));
3543 template<class _CharT, class _Traits, class _Allocator>
3544 inline _LIBCPP_INLINE_VISIBILITY
3546 basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3548 if (size() > capacity())
3550 if (capacity() < __min_cap - 1)
3554 if (data()[size()] != value_type(0))
3561 template<class _CharT, class _Traits, class _Allocator>
3562 inline _LIBCPP_INLINE_VISIBILITY
3564 operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3565 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3567 size_t __lhs_sz = __lhs.size();
3568 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3573 template<class _Allocator>
3574 inline _LIBCPP_INLINE_VISIBILITY
3576 operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3577 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3579 size_t __lhs_sz = __lhs.size();
3580 if (__lhs_sz != __rhs.size())
3582 const char* __lp = __lhs.data();
3583 const char* __rp = __rhs.data();
3584 if (__lhs.__is_long())
3585 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3586 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3592 template<class _CharT, class _Traits, class _Allocator>
3593 inline _LIBCPP_INLINE_VISIBILITY
3595 operator==(const _CharT* __lhs,
3596 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3598 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3599 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3600 size_t __lhs_len = _Traits::length(__lhs);
3601 if (__lhs_len != __rhs.size()) return false;
3602 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
3605 template<class _CharT, class _Traits, class _Allocator>
3606 inline _LIBCPP_INLINE_VISIBILITY
3608 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3609 const _CharT* __rhs) _NOEXCEPT
3611 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3612 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3613 size_t __rhs_len = _Traits::length(__rhs);
3614 if (__rhs_len != __lhs.size()) return false;
3615 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
3618 template<class _CharT, class _Traits, class _Allocator>
3619 inline _LIBCPP_INLINE_VISIBILITY
3621 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3622 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3624 return !(__lhs == __rhs);
3627 template<class _CharT, class _Traits, class _Allocator>
3628 inline _LIBCPP_INLINE_VISIBILITY
3630 operator!=(const _CharT* __lhs,
3631 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3633 return !(__lhs == __rhs);
3636 template<class _CharT, class _Traits, class _Allocator>
3637 inline _LIBCPP_INLINE_VISIBILITY
3639 operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3640 const _CharT* __rhs) _NOEXCEPT
3642 return !(__lhs == __rhs);
3647 template<class _CharT, class _Traits, class _Allocator>
3648 inline _LIBCPP_INLINE_VISIBILITY
3650 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3651 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3653 return __lhs.compare(__rhs) < 0;
3656 template<class _CharT, class _Traits, class _Allocator>
3657 inline _LIBCPP_INLINE_VISIBILITY
3659 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3660 const _CharT* __rhs) _NOEXCEPT
3662 return __lhs.compare(__rhs) < 0;
3665 template<class _CharT, class _Traits, class _Allocator>
3666 inline _LIBCPP_INLINE_VISIBILITY
3668 operator< (const _CharT* __lhs,
3669 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3671 return __rhs.compare(__lhs) > 0;
3676 template<class _CharT, class _Traits, class _Allocator>
3677 inline _LIBCPP_INLINE_VISIBILITY
3679 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3680 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3682 return __rhs < __lhs;
3685 template<class _CharT, class _Traits, class _Allocator>
3686 inline _LIBCPP_INLINE_VISIBILITY
3688 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3689 const _CharT* __rhs) _NOEXCEPT
3691 return __rhs < __lhs;
3694 template<class _CharT, class _Traits, class _Allocator>
3695 inline _LIBCPP_INLINE_VISIBILITY
3697 operator> (const _CharT* __lhs,
3698 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3700 return __rhs < __lhs;
3705 template<class _CharT, class _Traits, class _Allocator>
3706 inline _LIBCPP_INLINE_VISIBILITY
3708 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3709 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3711 return !(__rhs < __lhs);
3714 template<class _CharT, class _Traits, class _Allocator>
3715 inline _LIBCPP_INLINE_VISIBILITY
3717 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3718 const _CharT* __rhs) _NOEXCEPT
3720 return !(__rhs < __lhs);
3723 template<class _CharT, class _Traits, class _Allocator>
3724 inline _LIBCPP_INLINE_VISIBILITY
3726 operator<=(const _CharT* __lhs,
3727 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3729 return !(__rhs < __lhs);
3734 template<class _CharT, class _Traits, class _Allocator>
3735 inline _LIBCPP_INLINE_VISIBILITY
3737 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3738 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3740 return !(__lhs < __rhs);
3743 template<class _CharT, class _Traits, class _Allocator>
3744 inline _LIBCPP_INLINE_VISIBILITY
3746 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3747 const _CharT* __rhs) _NOEXCEPT
3749 return !(__lhs < __rhs);
3752 template<class _CharT, class _Traits, class _Allocator>
3753 inline _LIBCPP_INLINE_VISIBILITY
3755 operator>=(const _CharT* __lhs,
3756 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3758 return !(__lhs < __rhs);
3763 template<class _CharT, class _Traits, class _Allocator>
3764 basic_string<_CharT, _Traits, _Allocator>
3765 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3766 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3768 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3769 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3770 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3771 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3772 __r.append(__rhs.data(), __rhs_sz);
3776 template<class _CharT, class _Traits, class _Allocator>
3777 basic_string<_CharT, _Traits, _Allocator>
3778 operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3780 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3781 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3782 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3783 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3784 __r.append(__rhs.data(), __rhs_sz);
3788 template<class _CharT, class _Traits, class _Allocator>
3789 basic_string<_CharT, _Traits, _Allocator>
3790 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3792 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3793 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3794 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3795 __r.append(__rhs.data(), __rhs_sz);
3799 template<class _CharT, class _Traits, class _Allocator>
3800 basic_string<_CharT, _Traits, _Allocator>
3801 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3803 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3804 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3805 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3806 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3807 __r.append(__rhs, __rhs_sz);
3811 template<class _CharT, class _Traits, class _Allocator>
3812 basic_string<_CharT, _Traits, _Allocator>
3813 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3815 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3816 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3817 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3818 __r.push_back(__rhs);
3822 #ifndef _LIBCPP_CXX03_LANG
3824 template<class _CharT, class _Traits, class _Allocator>
3825 inline _LIBCPP_INLINE_VISIBILITY
3826 basic_string<_CharT, _Traits, _Allocator>
3827 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3829 return _VSTD::move(__lhs.append(__rhs));
3832 template<class _CharT, class _Traits, class _Allocator>
3833 inline _LIBCPP_INLINE_VISIBILITY
3834 basic_string<_CharT, _Traits, _Allocator>
3835 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3837 return _VSTD::move(__rhs.insert(0, __lhs));
3840 template<class _CharT, class _Traits, class _Allocator>
3841 inline _LIBCPP_INLINE_VISIBILITY
3842 basic_string<_CharT, _Traits, _Allocator>
3843 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3845 return _VSTD::move(__lhs.append(__rhs));
3848 template<class _CharT, class _Traits, class _Allocator>
3849 inline _LIBCPP_INLINE_VISIBILITY
3850 basic_string<_CharT, _Traits, _Allocator>
3851 operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3853 return _VSTD::move(__rhs.insert(0, __lhs));
3856 template<class _CharT, class _Traits, class _Allocator>
3857 inline _LIBCPP_INLINE_VISIBILITY
3858 basic_string<_CharT, _Traits, _Allocator>
3859 operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3861 __rhs.insert(__rhs.begin(), __lhs);
3862 return _VSTD::move(__rhs);
3865 template<class _CharT, class _Traits, class _Allocator>
3866 inline _LIBCPP_INLINE_VISIBILITY
3867 basic_string<_CharT, _Traits, _Allocator>
3868 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3870 return _VSTD::move(__lhs.append(__rhs));
3873 template<class _CharT, class _Traits, class _Allocator>
3874 inline _LIBCPP_INLINE_VISIBILITY
3875 basic_string<_CharT, _Traits, _Allocator>
3876 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3878 __lhs.push_back(__rhs);
3879 return _VSTD::move(__lhs);
3882 #endif // _LIBCPP_CXX03_LANG
3886 template<class _CharT, class _Traits, class _Allocator>
3887 inline _LIBCPP_INLINE_VISIBILITY
3889 swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
3890 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3891 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
3896 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3898 typedef basic_string<char16_t> u16string;
3899 typedef basic_string<char32_t> u32string;
3901 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
3903 _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3904 _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3905 _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3906 _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3907 _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
3909 _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3910 _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3911 _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
3913 _LIBCPP_FUNC_VIS string to_string(int __val);
3914 _LIBCPP_FUNC_VIS string to_string(unsigned __val);
3915 _LIBCPP_FUNC_VIS string to_string(long __val);
3916 _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3917 _LIBCPP_FUNC_VIS string to_string(long long __val);
3918 _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3919 _LIBCPP_FUNC_VIS string to_string(float __val);
3920 _LIBCPP_FUNC_VIS string to_string(double __val);
3921 _LIBCPP_FUNC_VIS string to_string(long double __val);
3923 _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3924 _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3925 _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3926 _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3927 _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
3929 _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3930 _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3931 _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
3933 _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3934 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3935 _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3936 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3937 _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3938 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3939 _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3940 _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3941 _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
3943 template<class _CharT, class _Traits, class _Allocator>
3944 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3945 basic_string<_CharT, _Traits, _Allocator>::npos;
3947 template<class _CharT, class _Traits, class _Allocator>
3948 struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
3949 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3952 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
3955 template<class _CharT, class _Traits, class _Allocator>
3957 hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
3958 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
3960 return __do_string_hash(__val.data(), __val.data() + __val.size());
3963 template<class _CharT, class _Traits, class _Allocator>
3964 basic_ostream<_CharT, _Traits>&
3965 operator<<(basic_ostream<_CharT, _Traits>& __os,
3966 const basic_string<_CharT, _Traits, _Allocator>& __str);
3968 template<class _CharT, class _Traits, class _Allocator>
3969 basic_istream<_CharT, _Traits>&
3970 operator>>(basic_istream<_CharT, _Traits>& __is,
3971 basic_string<_CharT, _Traits, _Allocator>& __str);
3973 template<class _CharT, class _Traits, class _Allocator>
3974 basic_istream<_CharT, _Traits>&
3975 getline(basic_istream<_CharT, _Traits>& __is,
3976 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3978 template<class _CharT, class _Traits, class _Allocator>
3979 inline _LIBCPP_INLINE_VISIBILITY
3980 basic_istream<_CharT, _Traits>&
3981 getline(basic_istream<_CharT, _Traits>& __is,
3982 basic_string<_CharT, _Traits, _Allocator>& __str);
3984 #ifndef _LIBCPP_CXX03_LANG
3986 template<class _CharT, class _Traits, class _Allocator>
3987 inline _LIBCPP_INLINE_VISIBILITY
3988 basic_istream<_CharT, _Traits>&
3989 getline(basic_istream<_CharT, _Traits>&& __is,
3990 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3992 template<class _CharT, class _Traits, class _Allocator>
3993 inline _LIBCPP_INLINE_VISIBILITY
3994 basic_istream<_CharT, _Traits>&
3995 getline(basic_istream<_CharT, _Traits>&& __is,
3996 basic_string<_CharT, _Traits, _Allocator>& __str);
3998 #endif // _LIBCPP_CXX03_LANG
4000 #if _LIBCPP_DEBUG_LEVEL >= 2
4002 template<class _CharT, class _Traits, class _Allocator>
4004 basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4006 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4007 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4010 template<class _CharT, class _Traits, class _Allocator>
4012 basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4014 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4015 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4018 template<class _CharT, class _Traits, class _Allocator>
4020 basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4022 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4023 return this->data() <= __p && __p <= this->data() + this->size();
4026 template<class _CharT, class _Traits, class _Allocator>
4028 basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4030 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4031 return this->data() <= __p && __p < this->data() + this->size();
4034 #endif // _LIBCPP_DEBUG_LEVEL >= 2
4036 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4037 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
4039 #if _LIBCPP_STD_VER > 11
4040 // Literal suffixes for basic_string [basic.string.literals]
4041 inline namespace literals
4043 inline namespace string_literals
4045 inline _LIBCPP_INLINE_VISIBILITY
4046 basic_string<char> operator "" s( const char *__str, size_t __len )
4048 return basic_string<char> (__str, __len);
4051 inline _LIBCPP_INLINE_VISIBILITY
4052 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4054 return basic_string<wchar_t> (__str, __len);
4057 inline _LIBCPP_INLINE_VISIBILITY
4058 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4060 return basic_string<char16_t> (__str, __len);
4063 inline _LIBCPP_INLINE_VISIBILITY
4064 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4066 return basic_string<char32_t> (__str, __len);
4072 _LIBCPP_END_NAMESPACE_STD
4076 #endif // _LIBCPP_STRING