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 ffind(basic_string_view<charT, traits> sv, size_type pos = 0) 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 = 0) 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 = 0) 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 __invariants() const;
307 template<class charT, class traits, class Allocator>
308 basic_string<charT, traits, Allocator>
309 operator+(const basic_string<charT, traits, Allocator>& lhs,
310 const basic_string<charT, traits, Allocator>& rhs);
312 template<class charT, class traits, class Allocator>
313 basic_string<charT, traits, Allocator>
314 operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
316 template<class charT, class traits, class Allocator>
317 basic_string<charT, traits, Allocator>
318 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
320 template<class charT, class traits, class Allocator>
321 basic_string<charT, traits, Allocator>
322 operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
324 template<class charT, class traits, class Allocator>
325 basic_string<charT, traits, Allocator>
326 operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
328 template<class charT, class traits, class Allocator>
329 bool operator==(const basic_string<charT, traits, Allocator>& lhs,
330 const basic_string<charT, traits, Allocator>& rhs) noexcept;
332 template<class charT, class traits, class Allocator>
333 bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
335 template<class charT, class traits, class Allocator>
336 bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
338 template<class charT, class traits, class Allocator>
339 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
340 const basic_string<charT, traits, Allocator>& rhs) noexcept;
342 template<class charT, class traits, class Allocator>
343 bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
345 template<class charT, class traits, class Allocator>
346 bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
348 template<class charT, class traits, class Allocator>
349 bool operator< (const basic_string<charT, traits, Allocator>& lhs,
350 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 charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
358 template<class charT, class traits, class Allocator>
359 bool operator> (const basic_string<charT, traits, Allocator>& lhs,
360 const basic_string<charT, traits, Allocator>& rhs) noexcept;
362 template<class charT, class traits, class Allocator>
363 bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
365 template<class charT, class traits, class Allocator>
366 bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
368 template<class charT, class traits, class Allocator>
369 bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
370 const basic_string<charT, traits, Allocator>& rhs) noexcept;
372 template<class charT, class traits, class Allocator>
373 bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
375 template<class charT, class traits, class Allocator>
376 bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
378 template<class charT, class traits, class Allocator>
379 bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
380 const basic_string<charT, traits, Allocator>& rhs) noexcept;
382 template<class charT, class traits, class Allocator>
383 bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
385 template<class charT, class traits, class Allocator>
386 bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
388 template<class charT, class traits, class Allocator>
389 void swap(basic_string<charT, traits, Allocator>& lhs,
390 basic_string<charT, traits, Allocator>& rhs)
391 noexcept(noexcept(lhs.swap(rhs)));
393 template<class charT, class traits, class Allocator>
394 basic_istream<charT, traits>&
395 operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
397 template<class charT, class traits, class Allocator>
398 basic_ostream<charT, traits>&
399 operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
401 template<class charT, class traits, class Allocator>
402 basic_istream<charT, traits>&
403 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
406 template<class charT, class traits, class Allocator>
407 basic_istream<charT, traits>&
408 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
410 typedef basic_string<char> string;
411 typedef basic_string<wchar_t> wstring;
412 typedef basic_string<char16_t> u16string;
413 typedef basic_string<char32_t> u32string;
415 int stoi (const string& str, size_t* idx = 0, int base = 10);
416 long stol (const string& str, size_t* idx = 0, int base = 10);
417 unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
418 long long stoll (const string& str, size_t* idx = 0, int base = 10);
419 unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
421 float stof (const string& str, size_t* idx = 0);
422 double stod (const string& str, size_t* idx = 0);
423 long double stold(const string& str, size_t* idx = 0);
425 string to_string(int val);
426 string to_string(unsigned val);
427 string to_string(long val);
428 string to_string(unsigned long val);
429 string to_string(long long val);
430 string to_string(unsigned long long val);
431 string to_string(float val);
432 string to_string(double val);
433 string to_string(long double val);
435 int stoi (const wstring& str, size_t* idx = 0, int base = 10);
436 long stol (const wstring& str, size_t* idx = 0, int base = 10);
437 unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
438 long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
439 unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
441 float stof (const wstring& str, size_t* idx = 0);
442 double stod (const wstring& str, size_t* idx = 0);
443 long double stold(const wstring& str, size_t* idx = 0);
445 wstring to_wstring(int val);
446 wstring to_wstring(unsigned val);
447 wstring to_wstring(long val);
448 wstring to_wstring(unsigned long val);
449 wstring to_wstring(long long val);
450 wstring to_wstring(unsigned long long val);
451 wstring to_wstring(float val);
452 wstring to_wstring(double val);
453 wstring to_wstring(long double val);
455 template <> struct hash<string>;
456 template <> struct hash<u16string>;
457 template <> struct hash<u32string>;
458 template <> struct hash<wstring>;
460 basic_string<char> operator "" s( const char *str, size_t len ); // C++14
461 basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
462 basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
463 basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
470 #include <string_view>
473 #include <cstdio> // For EOF.
480 #include <type_traits>
481 #include <initializer_list>
482 #include <__functional_base>
483 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
487 #include <__undef_min_max>
491 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
492 #pragma GCC system_header
495 _LIBCPP_BEGIN_NAMESPACE_STD
499 template <class _StateT>
500 class _LIBCPP_TEMPLATE_VIS fpos
506 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
508 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
510 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
511 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
513 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
514 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
515 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
516 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
519 template <class _StateT>
520 inline _LIBCPP_INLINE_VISIBILITY
521 streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
522 {return streamoff(__x) - streamoff(__y);}
524 template <class _StateT>
525 inline _LIBCPP_INLINE_VISIBILITY
526 bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
527 {return streamoff(__x) == streamoff(__y);}
529 template <class _StateT>
530 inline _LIBCPP_INLINE_VISIBILITY
531 bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
532 {return streamoff(__x) != streamoff(__y);}
536 template<class _CharT, class _Traits, class _Allocator>
537 basic_string<_CharT, _Traits, _Allocator>
538 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
539 const basic_string<_CharT, _Traits, _Allocator>& __y);
541 template<class _CharT, class _Traits, class _Allocator>
542 basic_string<_CharT, _Traits, _Allocator>
543 operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
545 template<class _CharT, class _Traits, class _Allocator>
546 basic_string<_CharT, _Traits, _Allocator>
547 operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
549 template<class _CharT, class _Traits, class _Allocator>
550 basic_string<_CharT, _Traits, _Allocator>
551 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
553 template<class _CharT, class _Traits, class _Allocator>
554 basic_string<_CharT, _Traits, _Allocator>
555 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
558 class _LIBCPP_TEMPLATE_VIS __basic_string_common
561 _LIBCPP_NORETURN void __throw_length_error() const;
562 _LIBCPP_NORETURN void __throw_out_of_range() const;
567 __basic_string_common<__b>::__throw_length_error() const
569 _VSTD::__throw_length_error("basic_string");
574 __basic_string_common<__b>::__throw_out_of_range() const
576 _VSTD::__throw_out_of_range("basic_string");
580 #pragma warning( push )
581 #pragma warning( disable: 4231 )
582 #endif // _LIBCPP_MSVC
583 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
585 #pragma warning( pop )
586 #endif // _LIBCPP_MSVC
588 #ifdef _LIBCPP_NO_EXCEPTIONS
589 template <class _Iter>
590 struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
591 #elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
592 template <class _Iter>
593 struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
595 template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
596 struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
597 noexcept(++(declval<_Iter&>())) &&
598 is_nothrow_assignable<_Iter&, _Iter>::value &&
599 noexcept(declval<_Iter>() == declval<_Iter>()) &&
600 noexcept(*declval<_Iter>())
603 template <class _Iter>
604 struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
608 template <class _Iter>
609 struct __libcpp_string_gets_noexcept_iterator
610 : public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
612 template <class _CharT, class _Traits, class _Tp>
613 struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
614 ( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
615 !is_convertible<const _Tp&, const _CharT*>::value)) {};
617 #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
619 template <class _CharT, size_t = sizeof(_CharT)>
622 unsigned char __xx[sizeof(_CharT)-1];
625 template <class _CharT>
626 struct __padding<_CharT, 1>
630 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
632 template<class _CharT, class _Traits, class _Allocator>
633 class _LIBCPP_TEMPLATE_VIS basic_string
634 : private __basic_string_common<true>
637 typedef basic_string __self;
638 typedef basic_string_view<_CharT, _Traits> __self_view;
639 typedef _Traits traits_type;
640 typedef _CharT value_type;
641 typedef _Allocator allocator_type;
642 typedef allocator_traits<allocator_type> __alloc_traits;
643 typedef typename __alloc_traits::size_type size_type;
644 typedef typename __alloc_traits::difference_type difference_type;
645 typedef value_type& reference;
646 typedef const value_type& const_reference;
647 typedef typename __alloc_traits::pointer pointer;
648 typedef typename __alloc_traits::const_pointer const_pointer;
650 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
651 static_assert((is_same<_CharT, typename traits_type::char_type>::value),
652 "traits_type::char_type must be the same type as CharT");
653 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
654 "Allocator::value_type must be same type as value_type");
655 #if defined(_LIBCPP_RAW_ITERATORS)
656 typedef pointer iterator;
657 typedef const_pointer const_iterator;
658 #else // defined(_LIBCPP_RAW_ITERATORS)
659 typedef __wrap_iter<pointer> iterator;
660 typedef __wrap_iter<const_pointer> const_iterator;
661 #endif // defined(_LIBCPP_RAW_ITERATORS)
662 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
663 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
667 #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
676 #if _LIBCPP_BIG_ENDIAN
677 enum {__short_mask = 0x01};
678 enum {__long_mask = 0x1ul};
679 #else // _LIBCPP_BIG_ENDIAN
680 enum {__short_mask = 0x80};
681 enum {__long_mask = ~(size_type(~0) >> 1)};
682 #endif // _LIBCPP_BIG_ENDIAN
684 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
685 (sizeof(__long) - 1)/sizeof(value_type) : 2};
689 value_type __data_[__min_cap];
691 : __padding<value_type>
693 unsigned char __size_;
706 #if _LIBCPP_BIG_ENDIAN
707 enum {__short_mask = 0x80};
708 enum {__long_mask = ~(size_type(~0) >> 1)};
709 #else // _LIBCPP_BIG_ENDIAN
710 enum {__short_mask = 0x01};
711 enum {__long_mask = 0x1ul};
712 #endif // _LIBCPP_BIG_ENDIAN
714 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
715 (sizeof(__long) - 1)/sizeof(value_type) : 2};
721 unsigned char __size_;
724 value_type __data_[__min_cap];
727 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
729 union __ulx{__long __lx; __short __lxx;};
731 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
735 size_type __words[__n_words];
748 __compressed_pair<__rep, allocator_type> __r_;
751 static const size_type npos = -1;
753 _LIBCPP_INLINE_VISIBILITY basic_string()
754 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
756 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
757 #if _LIBCPP_STD_VER <= 14
758 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
763 basic_string(const basic_string& __str);
764 basic_string(const basic_string& __str, const allocator_type& __a);
766 #ifndef _LIBCPP_CXX03_LANG
767 _LIBCPP_INLINE_VISIBILITY
768 basic_string(basic_string&& __str)
769 #if _LIBCPP_STD_VER <= 14
770 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
775 _LIBCPP_INLINE_VISIBILITY
776 basic_string(basic_string&& __str, const allocator_type& __a);
777 #endif // _LIBCPP_CXX03_LANG
778 _LIBCPP_INLINE_VISIBILITY basic_string(const _CharT* __s);
779 _LIBCPP_INLINE_VISIBILITY
780 basic_string(const _CharT* __s, const _Allocator& __a);
781 _LIBCPP_INLINE_VISIBILITY
782 basic_string(const _CharT* __s, size_type __n);
783 _LIBCPP_INLINE_VISIBILITY
784 basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
785 _LIBCPP_INLINE_VISIBILITY
786 basic_string(size_type __n, _CharT __c);
787 _LIBCPP_INLINE_VISIBILITY
788 basic_string(size_type __n, _CharT __c, const _Allocator& __a);
789 basic_string(const basic_string& __str, size_type __pos, size_type __n,
790 const _Allocator& __a = _Allocator());
791 _LIBCPP_INLINE_VISIBILITY
792 basic_string(const basic_string& __str, size_type __pos,
793 const _Allocator& __a = _Allocator());
795 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
796 basic_string(const _Tp& __t, size_type __pos, size_type __n,
797 const allocator_type& __a = allocator_type(),
798 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type* = 0);
799 _LIBCPP_INLINE_VISIBILITY explicit
800 basic_string(__self_view __sv);
801 _LIBCPP_INLINE_VISIBILITY
802 basic_string(__self_view __sv, const _Allocator& __a);
803 template<class _InputIterator>
804 _LIBCPP_INLINE_VISIBILITY
805 basic_string(_InputIterator __first, _InputIterator __last);
806 template<class _InputIterator>
807 _LIBCPP_INLINE_VISIBILITY
808 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
809 #ifndef _LIBCPP_CXX03_LANG
810 _LIBCPP_INLINE_VISIBILITY
811 basic_string(initializer_list<_CharT> __il);
812 _LIBCPP_INLINE_VISIBILITY
813 basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
814 #endif // _LIBCPP_CXX03_LANG
816 inline ~basic_string();
818 _LIBCPP_INLINE_VISIBILITY
819 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
821 basic_string& operator=(const basic_string& __str);
823 #ifndef _LIBCPP_CXX03_LANG
824 template <class = void>
826 _LIBCPP_INLINE_VISIBILITY
827 basic_string& operator=(__self_view __sv) {return assign(__sv);}
828 #ifndef _LIBCPP_CXX03_LANG
829 _LIBCPP_INLINE_VISIBILITY
830 basic_string& operator=(basic_string&& __str)
831 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
832 _LIBCPP_INLINE_VISIBILITY
833 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
835 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
836 basic_string& operator=(value_type __c);
838 #if _LIBCPP_DEBUG_LEVEL >= 2
839 _LIBCPP_INLINE_VISIBILITY
840 iterator begin() _NOEXCEPT
841 {return iterator(this, __get_pointer());}
842 _LIBCPP_INLINE_VISIBILITY
843 const_iterator begin() const _NOEXCEPT
844 {return const_iterator(this, __get_pointer());}
845 _LIBCPP_INLINE_VISIBILITY
846 iterator end() _NOEXCEPT
847 {return iterator(this, __get_pointer() + size());}
848 _LIBCPP_INLINE_VISIBILITY
849 const_iterator end() const _NOEXCEPT
850 {return const_iterator(this, __get_pointer() + size());}
852 _LIBCPP_INLINE_VISIBILITY
853 iterator begin() _NOEXCEPT
854 {return iterator(__get_pointer());}
855 _LIBCPP_INLINE_VISIBILITY
856 const_iterator begin() const _NOEXCEPT
857 {return const_iterator(__get_pointer());}
858 _LIBCPP_INLINE_VISIBILITY
859 iterator end() _NOEXCEPT
860 {return iterator(__get_pointer() + size());}
861 _LIBCPP_INLINE_VISIBILITY
862 const_iterator end() const _NOEXCEPT
863 {return const_iterator(__get_pointer() + size());}
864 #endif // _LIBCPP_DEBUG_LEVEL >= 2
865 _LIBCPP_INLINE_VISIBILITY
866 reverse_iterator rbegin() _NOEXCEPT
867 {return reverse_iterator(end());}
868 _LIBCPP_INLINE_VISIBILITY
869 const_reverse_iterator rbegin() const _NOEXCEPT
870 {return const_reverse_iterator(end());}
871 _LIBCPP_INLINE_VISIBILITY
872 reverse_iterator rend() _NOEXCEPT
873 {return reverse_iterator(begin());}
874 _LIBCPP_INLINE_VISIBILITY
875 const_reverse_iterator rend() const _NOEXCEPT
876 {return const_reverse_iterator(begin());}
878 _LIBCPP_INLINE_VISIBILITY
879 const_iterator cbegin() const _NOEXCEPT
881 _LIBCPP_INLINE_VISIBILITY
882 const_iterator cend() const _NOEXCEPT
884 _LIBCPP_INLINE_VISIBILITY
885 const_reverse_iterator crbegin() const _NOEXCEPT
887 _LIBCPP_INLINE_VISIBILITY
888 const_reverse_iterator crend() const _NOEXCEPT
891 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
892 {return __is_long() ? __get_long_size() : __get_short_size();}
893 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
894 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
895 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
896 {return (__is_long() ? __get_long_cap()
897 : static_cast<size_type>(__min_cap)) - 1;}
899 void resize(size_type __n, value_type __c);
900 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
902 void reserve(size_type res_arg = 0);
903 _LIBCPP_INLINE_VISIBILITY
904 void shrink_to_fit() _NOEXCEPT {reserve();}
905 _LIBCPP_INLINE_VISIBILITY
906 void clear() _NOEXCEPT;
907 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
909 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
910 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
912 const_reference at(size_type __n) const;
913 reference at(size_type __n);
915 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
916 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(__self_view __sv) {return append(__sv);}
917 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
918 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
919 #ifndef _LIBCPP_CXX03_LANG
920 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
921 #endif // _LIBCPP_CXX03_LANG
923 _LIBCPP_INLINE_VISIBILITY
924 basic_string& append(const basic_string& __str);
925 _LIBCPP_INLINE_VISIBILITY
926 basic_string& append(__self_view __sv) { return append(__sv.data(), __sv.size()); }
927 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
929 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
932 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
935 append(const _Tp& __t, size_type __pos, size_type __n=npos);
936 basic_string& append(const value_type* __s, size_type __n);
937 basic_string& append(const value_type* __s);
938 basic_string& append(size_type __n, value_type __c);
939 template <class _ForwardIterator>
940 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
941 basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
942 template<class _InputIterator>
943 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
946 __is_exactly_input_iterator<_InputIterator>::value
947 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
950 _LIBCPP_INLINE_VISIBILITY
951 append(_InputIterator __first, _InputIterator __last) {
952 const basic_string __temp (__first, __last, __alloc());
953 append(__temp.data(), __temp.size());
956 template<class _ForwardIterator>
957 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
960 __is_forward_iterator<_ForwardIterator>::value
961 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
964 _LIBCPP_INLINE_VISIBILITY
965 append(_ForwardIterator __first, _ForwardIterator __last) {
966 return __append_forward_unsafe(__first, __last);
969 #ifndef _LIBCPP_CXX03_LANG
970 _LIBCPP_INLINE_VISIBILITY
971 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
972 #endif // _LIBCPP_CXX03_LANG
974 void push_back(value_type __c);
975 _LIBCPP_INLINE_VISIBILITY
977 _LIBCPP_INLINE_VISIBILITY reference front();
978 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
979 _LIBCPP_INLINE_VISIBILITY reference back();
980 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
982 _LIBCPP_INLINE_VISIBILITY
983 basic_string& assign(__self_view __sv) { return assign(__sv.data(), __sv.size()); }
984 _LIBCPP_INLINE_VISIBILITY
985 basic_string& assign(const basic_string& __str) { return *this = __str; }
986 #ifndef _LIBCPP_CXX03_LANG
987 _LIBCPP_INLINE_VISIBILITY
988 basic_string& assign(basic_string&& str)
989 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
990 {*this = _VSTD::move(str); return *this;}
992 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
994 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
997 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1000 assign(const _Tp & __t, size_type pos, size_type n=npos);
1001 basic_string& assign(const value_type* __s, size_type __n);
1002 basic_string& assign(const value_type* __s);
1003 basic_string& assign(size_type __n, value_type __c);
1004 template<class _InputIterator>
1005 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1008 __is_exactly_input_iterator<_InputIterator>::value
1009 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
1012 assign(_InputIterator __first, _InputIterator __last);
1013 template<class _ForwardIterator>
1014 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1017 __is_forward_iterator<_ForwardIterator>::value
1018 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
1021 assign(_ForwardIterator __first, _ForwardIterator __last);
1022 #ifndef _LIBCPP_CXX03_LANG
1023 _LIBCPP_INLINE_VISIBILITY
1024 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1025 #endif // _LIBCPP_CXX03_LANG
1027 _LIBCPP_INLINE_VISIBILITY
1028 basic_string& insert(size_type __pos1, const basic_string& __str);
1029 _LIBCPP_INLINE_VISIBILITY
1030 basic_string& insert(size_type __pos1, __self_view __sv) { return insert(__pos1, __sv.data(), __sv.size()); }
1031 template <class _Tp>
1032 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1035 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1038 insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
1039 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
1040 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1041 basic_string& insert(size_type __pos, const value_type* __s);
1042 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1043 iterator insert(const_iterator __pos, value_type __c);
1044 _LIBCPP_INLINE_VISIBILITY
1045 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1046 template<class _InputIterator>
1047 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1050 __is_exactly_input_iterator<_InputIterator>::value
1051 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
1054 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1055 template<class _ForwardIterator>
1056 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1059 __is_forward_iterator<_ForwardIterator>::value
1060 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
1063 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1064 #ifndef _LIBCPP_CXX03_LANG
1065 _LIBCPP_INLINE_VISIBILITY
1066 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1067 {return insert(__pos, __il.begin(), __il.end());}
1068 #endif // _LIBCPP_CXX03_LANG
1070 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1071 _LIBCPP_INLINE_VISIBILITY
1072 iterator erase(const_iterator __pos);
1073 _LIBCPP_INLINE_VISIBILITY
1074 iterator erase(const_iterator __first, const_iterator __last);
1076 _LIBCPP_INLINE_VISIBILITY
1077 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1078 _LIBCPP_INLINE_VISIBILITY
1079 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
1080 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
1081 template <class _Tp>
1082 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1085 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1088 replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
1089 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1090 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1091 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1092 _LIBCPP_INLINE_VISIBILITY
1093 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1094 _LIBCPP_INLINE_VISIBILITY
1095 basic_string& replace(const_iterator __i1, const_iterator __i2, __self_view __sv) { return replace(__i1 - begin(), __i2 - __i1, __sv); }
1096 _LIBCPP_INLINE_VISIBILITY
1097 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1098 _LIBCPP_INLINE_VISIBILITY
1099 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1100 _LIBCPP_INLINE_VISIBILITY
1101 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1102 template<class _InputIterator>
1103 _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
1106 __is_input_iterator<_InputIterator>::value,
1109 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1110 #ifndef _LIBCPP_CXX03_LANG
1111 _LIBCPP_INLINE_VISIBILITY
1112 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1113 {return replace(__i1, __i2, __il.begin(), __il.end());}
1114 #endif // _LIBCPP_CXX03_LANG
1116 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1117 _LIBCPP_INLINE_VISIBILITY
1118 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1120 _LIBCPP_INLINE_VISIBILITY
1121 void swap(basic_string& __str)
1122 #if _LIBCPP_STD_VER >= 14
1125 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
1126 __is_nothrow_swappable<allocator_type>::value);
1129 _LIBCPP_INLINE_VISIBILITY
1130 const value_type* c_str() const _NOEXCEPT {return data();}
1131 _LIBCPP_INLINE_VISIBILITY
1132 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1133 #if _LIBCPP_STD_VER > 14
1134 _LIBCPP_INLINE_VISIBILITY
1135 value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1138 _LIBCPP_INLINE_VISIBILITY
1139 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
1141 _LIBCPP_INLINE_VISIBILITY
1142 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1143 _LIBCPP_INLINE_VISIBILITY
1144 size_type find(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1145 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1146 _LIBCPP_INLINE_VISIBILITY
1147 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1148 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1150 _LIBCPP_INLINE_VISIBILITY
1151 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1152 _LIBCPP_INLINE_VISIBILITY
1153 size_type rfind(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1154 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1155 _LIBCPP_INLINE_VISIBILITY
1156 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1157 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1159 _LIBCPP_INLINE_VISIBILITY
1160 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1161 _LIBCPP_INLINE_VISIBILITY
1162 size_type find_first_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1163 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1164 _LIBCPP_INLINE_VISIBILITY
1165 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1166 _LIBCPP_INLINE_VISIBILITY
1167 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1169 _LIBCPP_INLINE_VISIBILITY
1170 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1171 _LIBCPP_INLINE_VISIBILITY
1172 size_type find_last_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1173 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1174 _LIBCPP_INLINE_VISIBILITY
1175 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1176 _LIBCPP_INLINE_VISIBILITY
1177 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1179 _LIBCPP_INLINE_VISIBILITY
1180 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1181 _LIBCPP_INLINE_VISIBILITY
1182 size_type find_first_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1183 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1184 _LIBCPP_INLINE_VISIBILITY
1185 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1186 _LIBCPP_INLINE_VISIBILITY
1187 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1189 _LIBCPP_INLINE_VISIBILITY
1190 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1191 _LIBCPP_INLINE_VISIBILITY
1192 size_type find_last_not_of(__self_view __sv, size_type __pos = 0) const _NOEXCEPT;
1193 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1194 _LIBCPP_INLINE_VISIBILITY
1195 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1196 _LIBCPP_INLINE_VISIBILITY
1197 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1199 _LIBCPP_INLINE_VISIBILITY
1200 int compare(const basic_string& __str) const _NOEXCEPT;
1201 _LIBCPP_INLINE_VISIBILITY
1202 int compare(__self_view __sv) const _NOEXCEPT;
1203 _LIBCPP_INLINE_VISIBILITY
1204 int compare(size_type __pos1, size_type __n1, __self_view __sv) const;
1205 _LIBCPP_INLINE_VISIBILITY
1206 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1207 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
1208 template <class _Tp>
1209 inline _LIBCPP_INLINE_VISIBILITY
1212 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
1215 compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
1216 int compare(const value_type* __s) const _NOEXCEPT;
1217 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1218 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1220 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1222 _LIBCPP_INLINE_VISIBILITY
1223 bool __is_long() const _NOEXCEPT
1224 {return bool(__r_.first().__s.__size_ & __short_mask);}
1226 #if _LIBCPP_DEBUG_LEVEL >= 2
1228 bool __dereferenceable(const const_iterator* __i) const;
1229 bool __decrementable(const const_iterator* __i) const;
1230 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1231 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1233 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1236 _LIBCPP_INLINE_VISIBILITY
1237 allocator_type& __alloc() _NOEXCEPT
1238 {return __r_.second();}
1239 _LIBCPP_INLINE_VISIBILITY
1240 const allocator_type& __alloc() const _NOEXCEPT
1241 {return __r_.second();}
1243 #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1245 _LIBCPP_INLINE_VISIBILITY
1246 void __set_short_size(size_type __s) _NOEXCEPT
1247 # if _LIBCPP_BIG_ENDIAN
1248 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1250 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1253 _LIBCPP_INLINE_VISIBILITY
1254 size_type __get_short_size() const _NOEXCEPT
1255 # if _LIBCPP_BIG_ENDIAN
1256 {return __r_.first().__s.__size_ >> 1;}
1258 {return __r_.first().__s.__size_;}
1261 #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1263 _LIBCPP_INLINE_VISIBILITY
1264 void __set_short_size(size_type __s) _NOEXCEPT
1265 # if _LIBCPP_BIG_ENDIAN
1266 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1268 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1271 _LIBCPP_INLINE_VISIBILITY
1272 size_type __get_short_size() const _NOEXCEPT
1273 # if _LIBCPP_BIG_ENDIAN
1274 {return __r_.first().__s.__size_;}
1276 {return __r_.first().__s.__size_ >> 1;}
1279 #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
1281 _LIBCPP_INLINE_VISIBILITY
1282 void __set_long_size(size_type __s) _NOEXCEPT
1283 {__r_.first().__l.__size_ = __s;}
1284 _LIBCPP_INLINE_VISIBILITY
1285 size_type __get_long_size() const _NOEXCEPT
1286 {return __r_.first().__l.__size_;}
1287 _LIBCPP_INLINE_VISIBILITY
1288 void __set_size(size_type __s) _NOEXCEPT
1289 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1291 _LIBCPP_INLINE_VISIBILITY
1292 void __set_long_cap(size_type __s) _NOEXCEPT
1293 {__r_.first().__l.__cap_ = __long_mask | __s;}
1294 _LIBCPP_INLINE_VISIBILITY
1295 size_type __get_long_cap() const _NOEXCEPT
1296 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1298 _LIBCPP_INLINE_VISIBILITY
1299 void __set_long_pointer(pointer __p) _NOEXCEPT
1300 {__r_.first().__l.__data_ = __p;}
1301 _LIBCPP_INLINE_VISIBILITY
1302 pointer __get_long_pointer() _NOEXCEPT
1303 {return __r_.first().__l.__data_;}
1304 _LIBCPP_INLINE_VISIBILITY
1305 const_pointer __get_long_pointer() const _NOEXCEPT
1306 {return __r_.first().__l.__data_;}
1307 _LIBCPP_INLINE_VISIBILITY
1308 pointer __get_short_pointer() _NOEXCEPT
1309 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1310 _LIBCPP_INLINE_VISIBILITY
1311 const_pointer __get_short_pointer() const _NOEXCEPT
1312 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1313 _LIBCPP_INLINE_VISIBILITY
1314 pointer __get_pointer() _NOEXCEPT
1315 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1316 _LIBCPP_INLINE_VISIBILITY
1317 const_pointer __get_pointer() const _NOEXCEPT
1318 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1320 _LIBCPP_INLINE_VISIBILITY
1321 void __zero() _NOEXCEPT
1323 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1324 for (unsigned __i = 0; __i < __n_words; ++__i)
1328 template <size_type __a> static
1329 _LIBCPP_INLINE_VISIBILITY
1330 size_type __align_it(size_type __s) _NOEXCEPT
1331 {return (__s + (__a-1)) & ~(__a-1);}
1332 enum {__alignment = 16};
1333 static _LIBCPP_INLINE_VISIBILITY
1334 size_type __recommend(size_type __s) _NOEXCEPT
1335 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
1336 __align_it<sizeof(value_type) < __alignment ?
1337 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
1340 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1342 void __init(const value_type* __s, size_type __sz);
1344 void __init(size_type __n, value_type __c);
1346 template <class _InputIterator>
1350 __is_exactly_input_iterator<_InputIterator>::value,
1353 __init(_InputIterator __first, _InputIterator __last);
1355 template <class _ForwardIterator>
1359 __is_forward_iterator<_ForwardIterator>::value,
1362 __init(_ForwardIterator __first, _ForwardIterator __last);
1364 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1365 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1366 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1367 size_type __n_copy, size_type __n_del,
1368 size_type __n_add, const value_type* __p_new_stuff);
1370 _LIBCPP_INLINE_VISIBILITY
1371 void __erase_to_end(size_type __pos);
1373 _LIBCPP_INLINE_VISIBILITY
1374 void __copy_assign_alloc(const basic_string& __str)
1375 {__copy_assign_alloc(__str, integral_constant<bool,
1376 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1378 _LIBCPP_INLINE_VISIBILITY
1379 void __copy_assign_alloc(const basic_string& __str, true_type)
1381 if (__alloc() == __str.__alloc())
1382 __alloc() = __str.__alloc();
1385 if (!__str.__is_long())
1389 __alloc() = __str.__alloc();
1393 allocator_type __a = __str.__alloc();
1394 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
1397 __alloc() = _VSTD::move(__a);
1398 __set_long_pointer(__p);
1399 __set_long_cap(__str.__get_long_cap());
1400 __set_long_size(__str.size());
1405 _LIBCPP_INLINE_VISIBILITY
1406 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
1409 #ifndef _LIBCPP_CXX03_LANG
1410 _LIBCPP_INLINE_VISIBILITY
1411 void __move_assign(basic_string& __str, false_type)
1412 _NOEXCEPT_(__alloc_traits::is_always_equal::value);
1413 _LIBCPP_INLINE_VISIBILITY
1414 void __move_assign(basic_string& __str, true_type)
1415 #if _LIBCPP_STD_VER > 14
1418 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1422 _LIBCPP_INLINE_VISIBILITY
1424 __move_assign_alloc(basic_string& __str)
1426 !__alloc_traits::propagate_on_container_move_assignment::value ||
1427 is_nothrow_move_assignable<allocator_type>::value)
1428 {__move_assign_alloc(__str, integral_constant<bool,
1429 __alloc_traits::propagate_on_container_move_assignment::value>());}
1431 _LIBCPP_INLINE_VISIBILITY
1432 void __move_assign_alloc(basic_string& __c, true_type)
1433 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1435 __alloc() = _VSTD::move(__c.__alloc());
1438 _LIBCPP_INLINE_VISIBILITY
1439 void __move_assign_alloc(basic_string&, false_type)
1443 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1444 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
1446 friend basic_string operator+<>(const basic_string&, const basic_string&);
1447 friend basic_string operator+<>(const value_type*, const basic_string&);
1448 friend basic_string operator+<>(value_type, const basic_string&);
1449 friend basic_string operator+<>(const basic_string&, const value_type*);
1450 friend basic_string operator+<>(const basic_string&, value_type);
1453 template <class _CharT, class _Traits, class _Allocator>
1454 inline _LIBCPP_INLINE_VISIBILITY
1456 basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1458 #if _LIBCPP_DEBUG_LEVEL >= 2
1459 __get_db()->__invalidate_all(this);
1460 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1463 template <class _CharT, class _Traits, class _Allocator>
1464 inline _LIBCPP_INLINE_VISIBILITY
1466 basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1467 #if _LIBCPP_DEBUG_LEVEL >= 2
1472 #if _LIBCPP_DEBUG_LEVEL >= 2
1473 __c_node* __c = __get_db()->__find_c_and_lock(this);
1476 const_pointer __new_last = __get_pointer() + __pos;
1477 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1480 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1481 if (__i->base() > __new_last)
1483 (*__p)->__c_ = nullptr;
1484 if (--__c->end_ != __p)
1485 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1488 __get_db()->unlock();
1490 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1493 template <class _CharT, class _Traits, class _Allocator>
1494 inline _LIBCPP_INLINE_VISIBILITY
1495 basic_string<_CharT, _Traits, _Allocator>::basic_string()
1496 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1498 #if _LIBCPP_DEBUG_LEVEL >= 2
1499 __get_db()->__insert_c(this);
1504 template <class _CharT, class _Traits, class _Allocator>
1505 inline _LIBCPP_INLINE_VISIBILITY
1506 basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1507 #if _LIBCPP_STD_VER <= 14
1508 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1512 : __r_(__second_tag(), __a)
1514 #if _LIBCPP_DEBUG_LEVEL >= 2
1515 __get_db()->__insert_c(this);
1520 template <class _CharT, class _Traits, class _Allocator>
1521 void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
1523 size_type __reserve)
1525 if (__reserve > max_size())
1526 this->__throw_length_error();
1528 if (__reserve < __min_cap)
1530 __set_short_size(__sz);
1531 __p = __get_short_pointer();
1535 size_type __cap = __recommend(__reserve);
1536 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1537 __set_long_pointer(__p);
1538 __set_long_cap(__cap+1);
1539 __set_long_size(__sz);
1541 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1542 traits_type::assign(__p[__sz], value_type());
1545 template <class _CharT, class _Traits, class _Allocator>
1547 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1549 if (__sz > max_size())
1550 this->__throw_length_error();
1552 if (__sz < __min_cap)
1554 __set_short_size(__sz);
1555 __p = __get_short_pointer();
1559 size_type __cap = __recommend(__sz);
1560 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1561 __set_long_pointer(__p);
1562 __set_long_cap(__cap+1);
1563 __set_long_size(__sz);
1565 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1566 traits_type::assign(__p[__sz], value_type());
1569 template <class _CharT, class _Traits, class _Allocator>
1570 inline _LIBCPP_INLINE_VISIBILITY
1571 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s)
1573 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
1574 __init(__s, traits_type::length(__s));
1575 #if _LIBCPP_DEBUG_LEVEL >= 2
1576 __get_db()->__insert_c(this);
1580 template <class _CharT, class _Traits, class _Allocator>
1581 inline _LIBCPP_INLINE_VISIBILITY
1582 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
1583 : __r_(__second_tag(), __a)
1585 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
1586 __init(__s, traits_type::length(__s));
1587 #if _LIBCPP_DEBUG_LEVEL >= 2
1588 __get_db()->__insert_c(this);
1592 template <class _CharT, class _Traits, class _Allocator>
1593 inline _LIBCPP_INLINE_VISIBILITY
1594 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
1596 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
1598 #if _LIBCPP_DEBUG_LEVEL >= 2
1599 __get_db()->__insert_c(this);
1603 template <class _CharT, class _Traits, class _Allocator>
1604 inline _LIBCPP_INLINE_VISIBILITY
1605 basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
1606 : __r_(__second_tag(), __a)
1608 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
1610 #if _LIBCPP_DEBUG_LEVEL >= 2
1611 __get_db()->__insert_c(this);
1615 template <class _CharT, class _Traits, class _Allocator>
1616 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1617 : __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
1619 if (!__str.__is_long())
1620 __r_.first().__r = __str.__r_.first().__r;
1622 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1623 #if _LIBCPP_DEBUG_LEVEL >= 2
1624 __get_db()->__insert_c(this);
1628 template <class _CharT, class _Traits, class _Allocator>
1629 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1630 const basic_string& __str, const allocator_type& __a)
1631 : __r_(__second_tag(), __a)
1633 if (!__str.__is_long())
1634 __r_.first().__r = __str.__r_.first().__r;
1636 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1637 #if _LIBCPP_DEBUG_LEVEL >= 2
1638 __get_db()->__insert_c(this);
1642 #ifndef _LIBCPP_CXX03_LANG
1644 template <class _CharT, class _Traits, class _Allocator>
1645 inline _LIBCPP_INLINE_VISIBILITY
1646 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1647 #if _LIBCPP_STD_VER <= 14
1648 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1652 : __r_(_VSTD::move(__str.__r_))
1655 #if _LIBCPP_DEBUG_LEVEL >= 2
1656 __get_db()->__insert_c(this);
1658 __get_db()->swap(this, &__str);
1662 template <class _CharT, class _Traits, class _Allocator>
1663 inline _LIBCPP_INLINE_VISIBILITY
1664 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1665 : __r_(__second_tag(), __a)
1667 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
1668 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1671 __r_.first().__r = __str.__r_.first().__r;
1674 #if _LIBCPP_DEBUG_LEVEL >= 2
1675 __get_db()->__insert_c(this);
1677 __get_db()->swap(this, &__str);
1681 #endif // _LIBCPP_CXX03_LANG
1683 template <class _CharT, class _Traits, class _Allocator>
1685 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1687 if (__n > max_size())
1688 this->__throw_length_error();
1690 if (__n < __min_cap)
1692 __set_short_size(__n);
1693 __p = __get_short_pointer();
1697 size_type __cap = __recommend(__n);
1698 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1699 __set_long_pointer(__p);
1700 __set_long_cap(__cap+1);
1701 __set_long_size(__n);
1703 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
1704 traits_type::assign(__p[__n], value_type());
1707 template <class _CharT, class _Traits, class _Allocator>
1708 inline _LIBCPP_INLINE_VISIBILITY
1709 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
1712 #if _LIBCPP_DEBUG_LEVEL >= 2
1713 __get_db()->__insert_c(this);
1717 template <class _CharT, class _Traits, class _Allocator>
1718 inline _LIBCPP_INLINE_VISIBILITY
1719 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
1720 : __r_(__second_tag(), __a)
1723 #if _LIBCPP_DEBUG_LEVEL >= 2
1724 __get_db()->__insert_c(this);
1728 template <class _CharT, class _Traits, class _Allocator>
1729 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
1730 size_type __pos, size_type __n,
1731 const _Allocator& __a)
1732 : __r_(__second_tag(), __a)
1734 size_type __str_sz = __str.size();
1735 if (__pos > __str_sz)
1736 this->__throw_out_of_range();
1737 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
1738 #if _LIBCPP_DEBUG_LEVEL >= 2
1739 __get_db()->__insert_c(this);
1743 template <class _CharT, class _Traits, class _Allocator>
1744 inline _LIBCPP_INLINE_VISIBILITY
1745 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
1746 const _Allocator& __a)
1747 : __r_(__second_tag(), __a)
1749 size_type __str_sz = __str.size();
1750 if (__pos > __str_sz)
1751 this->__throw_out_of_range();
1752 __init(__str.data() + __pos, __str_sz - __pos);
1753 #if _LIBCPP_DEBUG_LEVEL >= 2
1754 __get_db()->__insert_c(this);
1758 template <class _CharT, class _Traits, class _Allocator>
1759 template <class _Tp>
1760 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1761 const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a,
1762 typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type *)
1763 : __r_(__second_tag(), __a)
1765 __self_view __sv = __self_view(__t).substr(__pos, __n);
1766 __init(__sv.data(), __sv.size());
1767 #if _LIBCPP_DEBUG_LEVEL >= 2
1768 __get_db()->__insert_c(this);
1772 template <class _CharT, class _Traits, class _Allocator>
1773 inline _LIBCPP_INLINE_VISIBILITY
1774 basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv)
1776 __init(__sv.data(), __sv.size());
1777 #if _LIBCPP_DEBUG_LEVEL >= 2
1778 __get_db()->__insert_c(this);
1782 template <class _CharT, class _Traits, class _Allocator>
1783 inline _LIBCPP_INLINE_VISIBILITY
1784 basic_string<_CharT, _Traits, _Allocator>::basic_string(__self_view __sv, const _Allocator& __a)
1785 : __r_(__second_tag(), __a)
1787 __init(__sv.data(), __sv.size());
1788 #if _LIBCPP_DEBUG_LEVEL >= 2
1789 __get_db()->__insert_c(this);
1793 template <class _CharT, class _Traits, class _Allocator>
1794 template <class _InputIterator>
1797 __is_exactly_input_iterator<_InputIterator>::value,
1800 basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
1803 #ifndef _LIBCPP_NO_EXCEPTIONS
1806 #endif // _LIBCPP_NO_EXCEPTIONS
1807 for (; __first != __last; ++__first)
1808 push_back(*__first);
1809 #ifndef _LIBCPP_NO_EXCEPTIONS
1814 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
1817 #endif // _LIBCPP_NO_EXCEPTIONS
1820 template <class _CharT, class _Traits, class _Allocator>
1821 template <class _ForwardIterator>
1824 __is_forward_iterator<_ForwardIterator>::value,
1827 basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
1829 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
1830 if (__sz > max_size())
1831 this->__throw_length_error();
1833 if (__sz < __min_cap)
1835 __set_short_size(__sz);
1836 __p = __get_short_pointer();
1840 size_type __cap = __recommend(__sz);
1841 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1842 __set_long_pointer(__p);
1843 __set_long_cap(__cap+1);
1844 __set_long_size(__sz);
1846 for (; __first != __last; ++__first, (void) ++__p)
1847 traits_type::assign(*__p, *__first);
1848 traits_type::assign(*__p, value_type());
1851 template <class _CharT, class _Traits, class _Allocator>
1852 template<class _InputIterator>
1853 inline _LIBCPP_INLINE_VISIBILITY
1854 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
1856 __init(__first, __last);
1857 #if _LIBCPP_DEBUG_LEVEL >= 2
1858 __get_db()->__insert_c(this);
1862 template <class _CharT, class _Traits, class _Allocator>
1863 template<class _InputIterator>
1864 inline _LIBCPP_INLINE_VISIBILITY
1865 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
1866 const allocator_type& __a)
1867 : __r_(__second_tag(), __a)
1869 __init(__first, __last);
1870 #if _LIBCPP_DEBUG_LEVEL >= 2
1871 __get_db()->__insert_c(this);
1875 #ifndef _LIBCPP_CXX03_LANG
1877 template <class _CharT, class _Traits, class _Allocator>
1878 inline _LIBCPP_INLINE_VISIBILITY
1879 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1880 initializer_list<_CharT> __il)
1882 __init(__il.begin(), __il.end());
1883 #if _LIBCPP_DEBUG_LEVEL >= 2
1884 __get_db()->__insert_c(this);
1888 template <class _CharT, class _Traits, class _Allocator>
1889 inline _LIBCPP_INLINE_VISIBILITY
1891 basic_string<_CharT, _Traits, _Allocator>::basic_string(
1892 initializer_list<_CharT> __il, const _Allocator& __a)
1893 : __r_(__second_tag(), __a)
1895 __init(__il.begin(), __il.end());
1896 #if _LIBCPP_DEBUG_LEVEL >= 2
1897 __get_db()->__insert_c(this);
1901 #endif // _LIBCPP_CXX03_LANG
1903 template <class _CharT, class _Traits, class _Allocator>
1904 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
1906 #if _LIBCPP_DEBUG_LEVEL >= 2
1907 __get_db()->__erase_c(this);
1910 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
1913 template <class _CharT, class _Traits, class _Allocator>
1915 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
1916 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1917 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
1919 size_type __ms = max_size();
1920 if (__delta_cap > __ms - __old_cap - 1)
1921 this->__throw_length_error();
1922 pointer __old_p = __get_pointer();
1923 size_type __cap = __old_cap < __ms / 2 - __alignment ?
1924 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
1926 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
1927 __invalidate_all_iterators();
1929 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1930 _VSTD::__to_raw_pointer(__old_p), __n_copy);
1932 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
1933 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1934 if (__sec_cp_sz != 0)
1935 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1936 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
1937 if (__old_cap+1 != __min_cap)
1938 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
1939 __set_long_pointer(__p);
1940 __set_long_cap(__cap+1);
1941 __old_sz = __n_copy + __n_add + __sec_cp_sz;
1942 __set_long_size(__old_sz);
1943 traits_type::assign(__p[__old_sz], value_type());
1946 template <class _CharT, class _Traits, class _Allocator>
1948 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1949 size_type __n_copy, size_type __n_del, size_type __n_add)
1951 size_type __ms = max_size();
1952 if (__delta_cap > __ms - __old_cap)
1953 this->__throw_length_error();
1954 pointer __old_p = __get_pointer();
1955 size_type __cap = __old_cap < __ms / 2 - __alignment ?
1956 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
1958 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
1959 __invalidate_all_iterators();
1961 traits_type::copy(_VSTD::__to_raw_pointer(__p),
1962 _VSTD::__to_raw_pointer(__old_p), __n_copy);
1963 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
1964 if (__sec_cp_sz != 0)
1965 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
1966 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
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);
1976 template <class _CharT, class _Traits, class _Allocator>
1977 basic_string<_CharT, _Traits, _Allocator>&
1978 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
1980 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
1981 size_type __cap = capacity();
1984 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
1985 traits_type::move(__p, __s, __n);
1986 traits_type::assign(__p[__n], value_type());
1988 __invalidate_iterators_past(__n);
1992 size_type __sz = size();
1993 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
1998 template <class _CharT, class _Traits, class _Allocator>
1999 basic_string<_CharT, _Traits, _Allocator>&
2000 basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2002 size_type __cap = capacity();
2005 size_type __sz = size();
2006 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2009 __invalidate_iterators_past(__n);
2010 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2011 traits_type::assign(__p, __n, __c);
2012 traits_type::assign(__p[__n], value_type());
2017 template <class _CharT, class _Traits, class _Allocator>
2018 basic_string<_CharT, _Traits, _Allocator>&
2019 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2024 __p = __get_long_pointer();
2029 __p = __get_short_pointer();
2030 __set_short_size(1);
2032 traits_type::assign(*__p, __c);
2033 traits_type::assign(*++__p, value_type());
2034 __invalidate_iterators_past(1);
2038 template <class _CharT, class _Traits, class _Allocator>
2039 basic_string<_CharT, _Traits, _Allocator>&
2040 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2044 __copy_assign_alloc(__str);
2045 assign(__str.data(), __str.size());
2050 #ifndef _LIBCPP_CXX03_LANG
2052 template <class _CharT, class _Traits, class _Allocator>
2053 inline _LIBCPP_INLINE_VISIBILITY
2055 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2056 _NOEXCEPT_(__alloc_traits::is_always_equal::value)
2058 if (__alloc() != __str.__alloc())
2061 __move_assign(__str, true_type());
2064 template <class _CharT, class _Traits, class _Allocator>
2065 inline _LIBCPP_INLINE_VISIBILITY
2067 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2068 #if _LIBCPP_STD_VER > 14
2071 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2076 __r_.first() = __str.__r_.first();
2077 __move_assign_alloc(__str);
2081 template <class _CharT, class _Traits, class _Allocator>
2082 inline _LIBCPP_INLINE_VISIBILITY
2083 basic_string<_CharT, _Traits, _Allocator>&
2084 basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2085 _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
2087 __move_assign(__str, integral_constant<bool,
2088 __alloc_traits::propagate_on_container_move_assignment::value>());
2094 template <class _CharT, class _Traits, class _Allocator>
2095 template<class _InputIterator>
2098 __is_exactly_input_iterator <_InputIterator>::value
2099 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2100 basic_string<_CharT, _Traits, _Allocator>&
2102 basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2104 const basic_string __temp(__first, __last, __alloc());
2105 assign(__temp.data(), __temp.size());
2109 template <class _CharT, class _Traits, class _Allocator>
2110 template<class _ForwardIterator>
2113 __is_forward_iterator<_ForwardIterator>::value
2114 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
2115 basic_string<_CharT, _Traits, _Allocator>&
2117 basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2119 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2120 size_type __cap = capacity();
2123 size_type __sz = size();
2124 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2127 __invalidate_iterators_past(__n);
2128 pointer __p = __get_pointer();
2129 for (; __first != __last; ++__first, ++__p)
2130 traits_type::assign(*__p, *__first);
2131 traits_type::assign(*__p, value_type());
2136 template <class _CharT, class _Traits, class _Allocator>
2137 basic_string<_CharT, _Traits, _Allocator>&
2138 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2140 size_type __sz = __str.size();
2142 this->__throw_out_of_range();
2143 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2146 template <class _CharT, class _Traits, class _Allocator>
2147 template <class _Tp>
2150 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2151 basic_string<_CharT, _Traits, _Allocator>&
2153 basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
2155 __self_view __sv = __t;
2156 size_type __sz = __sv.size();
2158 this->__throw_out_of_range();
2159 return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2163 template <class _CharT, class _Traits, class _Allocator>
2164 basic_string<_CharT, _Traits, _Allocator>&
2165 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2167 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2168 return assign(__s, traits_type::length(__s));
2173 template <class _CharT, class _Traits, class _Allocator>
2174 basic_string<_CharT, _Traits, _Allocator>&
2175 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2177 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
2178 size_type __cap = capacity();
2179 size_type __sz = size();
2180 if (__cap - __sz >= __n)
2184 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2185 traits_type::copy(__p + __sz, __s, __n);
2188 traits_type::assign(__p[__sz], value_type());
2192 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2196 template <class _CharT, class _Traits, class _Allocator>
2197 basic_string<_CharT, _Traits, _Allocator>&
2198 basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2202 size_type __cap = capacity();
2203 size_type __sz = size();
2204 if (__cap - __sz < __n)
2205 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2206 pointer __p = __get_pointer();
2207 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
2210 traits_type::assign(__p[__sz], value_type());
2215 template <class _CharT, class _Traits, class _Allocator>
2217 basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2219 bool __is_short = !__is_long();
2224 __cap = __min_cap - 1;
2225 __sz = __get_short_size();
2229 __cap = __get_long_cap() - 1;
2230 __sz = __get_long_size();
2234 __grow_by(__cap, 1, __sz, __sz, 0);
2235 __is_short = !__is_long();
2240 __p = __get_short_pointer() + __sz;
2241 __set_short_size(__sz+1);
2245 __p = __get_long_pointer() + __sz;
2246 __set_long_size(__sz+1);
2248 traits_type::assign(*__p, __c);
2249 traits_type::assign(*++__p, value_type());
2252 template <class _Tp>
2253 bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
2255 return __first <= __p && __p < __last;
2258 template <class _Tp1, class _Tp2>
2259 bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
2264 template <class _CharT, class _Traits, class _Allocator>
2265 template<class _ForwardIterator>
2266 basic_string<_CharT, _Traits, _Allocator>&
2267 basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
2268 _ForwardIterator __first, _ForwardIterator __last)
2270 static_assert(__is_forward_iterator<_ForwardIterator>::value,
2271 "function requires a ForwardIterator");
2272 size_type __sz = size();
2273 size_type __cap = capacity();
2274 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2277 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2278 _CharRef __tmp_ref = *__first;
2279 if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
2281 const basic_string __temp (__first, __last, __alloc());
2282 append(__temp.data(), __temp.size());
2286 if (__cap - __sz < __n)
2287 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2288 pointer __p = __get_pointer() + __sz;
2289 for (; __first != __last; ++__p, ++__first)
2290 traits_type::assign(*__p, *__first);
2291 traits_type::assign(*__p, value_type());
2292 __set_size(__sz + __n);
2298 template <class _CharT, class _Traits, class _Allocator>
2299 inline _LIBCPP_INLINE_VISIBILITY
2300 basic_string<_CharT, _Traits, _Allocator>&
2301 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2303 return append(__str.data(), __str.size());
2306 template <class _CharT, class _Traits, class _Allocator>
2307 basic_string<_CharT, _Traits, _Allocator>&
2308 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2310 size_type __sz = __str.size();
2312 this->__throw_out_of_range();
2313 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2316 template <class _CharT, class _Traits, class _Allocator>
2317 template <class _Tp>
2320 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2321 basic_string<_CharT, _Traits, _Allocator>&
2323 basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
2325 __self_view __sv = __t;
2326 size_type __sz = __sv.size();
2328 this->__throw_out_of_range();
2329 return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
2332 template <class _CharT, class _Traits, class _Allocator>
2333 basic_string<_CharT, _Traits, _Allocator>&
2334 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2336 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
2337 return append(__s, traits_type::length(__s));
2342 template <class _CharT, class _Traits, class _Allocator>
2343 basic_string<_CharT, _Traits, _Allocator>&
2344 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2346 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
2347 size_type __sz = size();
2349 this->__throw_out_of_range();
2350 size_type __cap = capacity();
2351 if (__cap - __sz >= __n)
2355 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2356 size_type __n_move = __sz - __pos;
2359 if (__p + __pos <= __s && __s < __p + __sz)
2361 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2363 traits_type::move(__p + __pos, __s, __n);
2366 traits_type::assign(__p[__sz], value_type());
2370 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2374 template <class _CharT, class _Traits, class _Allocator>
2375 basic_string<_CharT, _Traits, _Allocator>&
2376 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2378 size_type __sz = size();
2380 this->__throw_out_of_range();
2383 size_type __cap = capacity();
2385 if (__cap - __sz >= __n)
2387 __p = _VSTD::__to_raw_pointer(__get_pointer());
2388 size_type __n_move = __sz - __pos;
2390 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2394 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2395 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2397 traits_type::assign(__p + __pos, __n, __c);
2400 traits_type::assign(__p[__sz], value_type());
2405 template <class _CharT, class _Traits, class _Allocator>
2406 template<class _InputIterator>
2409 __is_exactly_input_iterator<_InputIterator>::value
2410 || !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
2411 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2413 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2415 #if _LIBCPP_DEBUG_LEVEL >= 2
2416 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2417 "string::insert(iterator, range) called with an iterator not"
2418 " referring to this string");
2420 const basic_string __temp(__first, __last, __alloc());
2421 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2424 template <class _CharT, class _Traits, class _Allocator>
2425 template<class _ForwardIterator>
2428 __is_forward_iterator<_ForwardIterator>::value
2429 && __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
2430 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2432 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2434 #if _LIBCPP_DEBUG_LEVEL >= 2
2435 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2436 "string::insert(iterator, range) called with an iterator not"
2437 " referring to this string");
2439 size_type __ip = static_cast<size_type>(__pos - begin());
2440 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2443 typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
2444 _CharRef __tmp_char = *__first;
2445 if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
2447 const basic_string __temp(__first, __last, __alloc());
2448 return insert(__pos, __temp.data(), __temp.data() + __temp.size());
2451 size_type __sz = size();
2452 size_type __cap = capacity();
2454 if (__cap - __sz >= __n)
2456 __p = _VSTD::__to_raw_pointer(__get_pointer());
2457 size_type __n_move = __sz - __ip;
2459 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2463 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2464 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2468 traits_type::assign(__p[__sz], value_type());
2469 for (__p += __ip; __first != __last; ++__p, ++__first)
2470 traits_type::assign(*__p, *__first);
2472 return begin() + __ip;
2475 template <class _CharT, class _Traits, class _Allocator>
2476 inline _LIBCPP_INLINE_VISIBILITY
2477 basic_string<_CharT, _Traits, _Allocator>&
2478 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2480 return insert(__pos1, __str.data(), __str.size());
2483 template <class _CharT, class _Traits, class _Allocator>
2484 basic_string<_CharT, _Traits, _Allocator>&
2485 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2486 size_type __pos2, size_type __n)
2488 size_type __str_sz = __str.size();
2489 if (__pos2 > __str_sz)
2490 this->__throw_out_of_range();
2491 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2494 template <class _CharT, class _Traits, class _Allocator>
2495 template <class _Tp>
2498 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2499 basic_string<_CharT, _Traits, _Allocator>&
2501 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
2502 size_type __pos2, size_type __n)
2504 __self_view __sv = __t;
2505 size_type __str_sz = __sv.size();
2506 if (__pos2 > __str_sz)
2507 this->__throw_out_of_range();
2508 return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2511 template <class _CharT, class _Traits, class _Allocator>
2512 basic_string<_CharT, _Traits, _Allocator>&
2513 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2515 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
2516 return insert(__pos, __s, traits_type::length(__s));
2519 template <class _CharT, class _Traits, class _Allocator>
2520 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2521 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2523 size_type __ip = static_cast<size_type>(__pos - begin());
2524 size_type __sz = size();
2525 size_type __cap = capacity();
2529 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2530 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2534 __p = _VSTD::__to_raw_pointer(__get_pointer());
2535 size_type __n_move = __sz - __ip;
2537 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2539 traits_type::assign(__p[__ip], __c);
2540 traits_type::assign(__p[++__sz], value_type());
2542 return begin() + static_cast<difference_type>(__ip);
2545 template <class _CharT, class _Traits, class _Allocator>
2546 inline _LIBCPP_INLINE_VISIBILITY
2547 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2548 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2550 #if _LIBCPP_DEBUG_LEVEL >= 2
2551 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2552 "string::insert(iterator, n, value) called with an iterator not"
2553 " referring to this string");
2555 difference_type __p = __pos - begin();
2556 insert(static_cast<size_type>(__p), __n, __c);
2557 return begin() + __p;
2562 template <class _CharT, class _Traits, class _Allocator>
2563 basic_string<_CharT, _Traits, _Allocator>&
2564 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2565 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
2567 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
2568 size_type __sz = size();
2570 this->__throw_out_of_range();
2571 __n1 = _VSTD::min(__n1, __sz - __pos);
2572 size_type __cap = capacity();
2573 if (__cap - __sz + __n1 >= __n2)
2575 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2578 size_type __n_move = __sz - __pos - __n1;
2583 traits_type::move(__p + __pos, __s, __n2);
2584 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2587 if (__p + __pos < __s && __s < __p + __sz)
2589 if (__p + __pos + __n1 <= __s)
2591 else // __p + __pos < __s < __p + __pos + __n1
2593 traits_type::move(__p + __pos, __s, __n1);
2600 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2603 traits_type::move(__p + __pos, __s, __n2);
2605 // __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
2606 // but this is a safe operation, so we disable the check.
2607 __sz += __n2 - __n1;
2609 __invalidate_iterators_past(__sz);
2610 traits_type::assign(__p[__sz], value_type());
2613 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2617 template <class _CharT, class _Traits, class _Allocator>
2618 basic_string<_CharT, _Traits, _Allocator>&
2619 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2620 _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
2622 size_type __sz = size();
2624 this->__throw_out_of_range();
2625 __n1 = _VSTD::min(__n1, __sz - __pos);
2626 size_type __cap = capacity();
2628 if (__cap - __sz + __n1 >= __n2)
2630 __p = _VSTD::__to_raw_pointer(__get_pointer());
2633 size_type __n_move = __sz - __pos - __n1;
2635 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2640 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2641 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2643 traits_type::assign(__p + __pos, __n2, __c);
2644 __sz += __n2 - __n1;
2646 __invalidate_iterators_past(__sz);
2647 traits_type::assign(__p[__sz], value_type());
2651 template <class _CharT, class _Traits, class _Allocator>
2652 template<class _InputIterator>
2655 __is_input_iterator<_InputIterator>::value,
2656 basic_string<_CharT, _Traits, _Allocator>&
2658 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
2659 _InputIterator __j1, _InputIterator __j2)
2661 const basic_string __temp(__j1, __j2, __alloc());
2662 return this->replace(__i1, __i2, __temp);
2665 template <class _CharT, class _Traits, class _Allocator>
2666 inline _LIBCPP_INLINE_VISIBILITY
2667 basic_string<_CharT, _Traits, _Allocator>&
2668 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2670 return replace(__pos1, __n1, __str.data(), __str.size());
2673 template <class _CharT, class _Traits, class _Allocator>
2674 basic_string<_CharT, _Traits, _Allocator>&
2675 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2676 size_type __pos2, size_type __n2)
2678 size_type __str_sz = __str.size();
2679 if (__pos2 > __str_sz)
2680 this->__throw_out_of_range();
2681 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2684 template <class _CharT, class _Traits, class _Allocator>
2685 template <class _Tp>
2688 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
2689 basic_string<_CharT, _Traits, _Allocator>&
2691 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
2692 size_type __pos2, size_type __n2)
2694 __self_view __sv = __t;
2695 size_type __str_sz = __sv.size();
2696 if (__pos2 > __str_sz)
2697 this->__throw_out_of_range();
2698 return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2701 template <class _CharT, class _Traits, class _Allocator>
2702 basic_string<_CharT, _Traits, _Allocator>&
2703 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
2705 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
2706 return replace(__pos, __n1, __s, traits_type::length(__s));
2709 template <class _CharT, class _Traits, class _Allocator>
2710 inline _LIBCPP_INLINE_VISIBILITY
2711 basic_string<_CharT, _Traits, _Allocator>&
2712 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
2714 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2715 __str.data(), __str.size());
2718 template <class _CharT, class _Traits, class _Allocator>
2719 inline _LIBCPP_INLINE_VISIBILITY
2720 basic_string<_CharT, _Traits, _Allocator>&
2721 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
2723 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2726 template <class _CharT, class _Traits, class _Allocator>
2727 inline _LIBCPP_INLINE_VISIBILITY
2728 basic_string<_CharT, _Traits, _Allocator>&
2729 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
2731 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2734 template <class _CharT, class _Traits, class _Allocator>
2735 inline _LIBCPP_INLINE_VISIBILITY
2736 basic_string<_CharT, _Traits, _Allocator>&
2737 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
2739 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2744 template <class _CharT, class _Traits, class _Allocator>
2745 basic_string<_CharT, _Traits, _Allocator>&
2746 basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2748 size_type __sz = size();
2750 this->__throw_out_of_range();
2753 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2754 __n = _VSTD::min(__n, __sz - __pos);
2755 size_type __n_move = __sz - __pos - __n;
2757 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2760 __invalidate_iterators_past(__sz);
2761 traits_type::assign(__p[__sz], value_type());
2766 template <class _CharT, class _Traits, class _Allocator>
2767 inline _LIBCPP_INLINE_VISIBILITY
2768 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2769 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2771 #if _LIBCPP_DEBUG_LEVEL >= 2
2772 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2773 "string::erase(iterator) called with an iterator not"
2774 " referring to this string");
2776 _LIBCPP_ASSERT(__pos != end(),
2777 "string::erase(iterator) called with a non-dereferenceable iterator");
2778 iterator __b = begin();
2779 size_type __r = static_cast<size_type>(__pos - __b);
2781 return __b + static_cast<difference_type>(__r);
2784 template <class _CharT, class _Traits, class _Allocator>
2785 inline _LIBCPP_INLINE_VISIBILITY
2786 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2787 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2789 #if _LIBCPP_DEBUG_LEVEL >= 2
2790 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2791 "string::erase(iterator, iterator) called with an iterator not"
2792 " referring to this string");
2794 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
2795 iterator __b = begin();
2796 size_type __r = static_cast<size_type>(__first - __b);
2797 erase(__r, static_cast<size_type>(__last - __first));
2798 return __b + static_cast<difference_type>(__r);
2801 template <class _CharT, class _Traits, class _Allocator>
2802 inline _LIBCPP_INLINE_VISIBILITY
2804 basic_string<_CharT, _Traits, _Allocator>::pop_back()
2806 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
2810 __sz = __get_long_size() - 1;
2811 __set_long_size(__sz);
2812 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2816 __sz = __get_short_size() - 1;
2817 __set_short_size(__sz);
2818 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2820 __invalidate_iterators_past(__sz);
2823 template <class _CharT, class _Traits, class _Allocator>
2824 inline _LIBCPP_INLINE_VISIBILITY
2826 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
2828 __invalidate_all_iterators();
2831 traits_type::assign(*__get_long_pointer(), value_type());
2836 traits_type::assign(*__get_short_pointer(), value_type());
2837 __set_short_size(0);
2841 template <class _CharT, class _Traits, class _Allocator>
2842 inline _LIBCPP_INLINE_VISIBILITY
2844 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2848 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2849 __set_long_size(__pos);
2853 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2854 __set_short_size(__pos);
2856 __invalidate_iterators_past(__pos);
2859 template <class _CharT, class _Traits, class _Allocator>
2861 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2863 size_type __sz = size();
2865 append(__n - __sz, __c);
2867 __erase_to_end(__n);
2870 template <class _CharT, class _Traits, class _Allocator>
2871 inline _LIBCPP_INLINE_VISIBILITY
2872 typename basic_string<_CharT, _Traits, _Allocator>::size_type
2873 basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
2875 size_type __m = __alloc_traits::max_size(__alloc());
2876 #if _LIBCPP_BIG_ENDIAN
2877 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
2879 return __m - __alignment;
2883 template <class _CharT, class _Traits, class _Allocator>
2885 basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2887 if (__res_arg > max_size())
2888 this->__throw_length_error();
2889 size_type __cap = capacity();
2890 size_type __sz = size();
2891 __res_arg = _VSTD::max(__res_arg, __sz);
2892 __res_arg = __recommend(__res_arg);
2893 if (__res_arg != __cap)
2895 pointer __new_data, __p;
2896 bool __was_long, __now_long;
2897 if (__res_arg == __min_cap - 1)
2901 __new_data = __get_short_pointer();
2902 __p = __get_long_pointer();
2906 if (__res_arg > __cap)
2907 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
2910 #ifndef _LIBCPP_NO_EXCEPTIONS
2913 #endif // _LIBCPP_NO_EXCEPTIONS
2914 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
2915 #ifndef _LIBCPP_NO_EXCEPTIONS
2921 #else // _LIBCPP_NO_EXCEPTIONS
2922 if (__new_data == nullptr)
2924 #endif // _LIBCPP_NO_EXCEPTIONS
2927 __was_long = __is_long();
2928 __p = __get_pointer();
2930 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
2931 _VSTD::__to_raw_pointer(__p), size()+1);
2933 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
2936 __set_long_cap(__res_arg+1);
2937 __set_long_size(__sz);
2938 __set_long_pointer(__new_data);
2941 __set_short_size(__sz);
2942 __invalidate_all_iterators();
2946 template <class _CharT, class _Traits, class _Allocator>
2947 inline _LIBCPP_INLINE_VISIBILITY
2948 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2949 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
2951 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
2952 return *(data() + __pos);
2955 template <class _CharT, class _Traits, class _Allocator>
2956 inline _LIBCPP_INLINE_VISIBILITY
2957 typename basic_string<_CharT, _Traits, _Allocator>::reference
2958 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
2960 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
2961 return *(__get_pointer() + __pos);
2964 template <class _CharT, class _Traits, class _Allocator>
2965 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2966 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
2969 this->__throw_out_of_range();
2970 return (*this)[__n];
2973 template <class _CharT, class _Traits, class _Allocator>
2974 typename basic_string<_CharT, _Traits, _Allocator>::reference
2975 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
2978 this->__throw_out_of_range();
2979 return (*this)[__n];
2982 template <class _CharT, class _Traits, class _Allocator>
2983 inline _LIBCPP_INLINE_VISIBILITY
2984 typename basic_string<_CharT, _Traits, _Allocator>::reference
2985 basic_string<_CharT, _Traits, _Allocator>::front()
2987 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
2988 return *__get_pointer();
2991 template <class _CharT, class _Traits, class _Allocator>
2992 inline _LIBCPP_INLINE_VISIBILITY
2993 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
2994 basic_string<_CharT, _Traits, _Allocator>::front() const
2996 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3000 template <class _CharT, class _Traits, class _Allocator>
3001 inline _LIBCPP_INLINE_VISIBILITY
3002 typename basic_string<_CharT, _Traits, _Allocator>::reference
3003 basic_string<_CharT, _Traits, _Allocator>::back()
3005 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3006 return *(__get_pointer() + size() - 1);
3009 template <class _CharT, class _Traits, class _Allocator>
3010 inline _LIBCPP_INLINE_VISIBILITY
3011 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3012 basic_string<_CharT, _Traits, _Allocator>::back() const
3014 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3015 return *(data() + size() - 1);
3018 template <class _CharT, class _Traits, class _Allocator>
3019 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3020 basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3022 size_type __sz = size();
3024 this->__throw_out_of_range();
3025 size_type __rlen = _VSTD::min(__n, __sz - __pos);
3026 traits_type::copy(__s, data() + __pos, __rlen);
3030 template <class _CharT, class _Traits, class _Allocator>
3031 inline _LIBCPP_INLINE_VISIBILITY
3032 basic_string<_CharT, _Traits, _Allocator>
3033 basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3035 return basic_string(*this, __pos, __n, __alloc());
3038 template <class _CharT, class _Traits, class _Allocator>
3039 inline _LIBCPP_INLINE_VISIBILITY
3041 basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3042 #if _LIBCPP_STD_VER >= 14
3045 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
3046 __is_nothrow_swappable<allocator_type>::value)
3049 #if _LIBCPP_DEBUG_LEVEL >= 2
3051 __get_db()->__invalidate_all(this);
3052 if (!__str.__is_long())
3053 __get_db()->__invalidate_all(&__str);
3054 __get_db()->swap(this, &__str);
3057 __alloc_traits::propagate_on_container_swap::value ||
3058 __alloc_traits::is_always_equal::value ||
3059 __alloc() == __str.__alloc(), "swapping non-equal allocators");
3060 _VSTD::swap(__r_.first(), __str.__r_.first());
3061 __swap_allocator(__alloc(), __str.__alloc());
3066 template <class _Traits>
3067 struct _LIBCPP_HIDDEN __traits_eq
3069 typedef typename _Traits::char_type char_type;
3070 _LIBCPP_INLINE_VISIBILITY
3071 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3072 {return _Traits::eq(__x, __y);}
3075 template<class _CharT, class _Traits, class _Allocator>
3076 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3077 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3079 size_type __n) const _NOEXCEPT
3081 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
3082 return __str_find<value_type, size_type, traits_type, npos>
3083 (data(), size(), __s, __pos, __n);
3086 template<class _CharT, class _Traits, class _Allocator>
3087 inline _LIBCPP_INLINE_VISIBILITY
3088 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3089 basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3090 size_type __pos) const _NOEXCEPT
3092 return __str_find<value_type, size_type, traits_type, npos>
3093 (data(), size(), __str.data(), __pos, __str.size());
3096 template<class _CharT, class _Traits, class _Allocator>
3097 inline _LIBCPP_INLINE_VISIBILITY
3098 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3099 basic_string<_CharT, _Traits, _Allocator>::find(__self_view __sv,
3100 size_type __pos) const _NOEXCEPT
3102 return __str_find<value_type, size_type, traits_type, npos>
3103 (data(), size(), __sv.data(), __pos, __sv.size());
3106 template<class _CharT, class _Traits, class _Allocator>
3107 inline _LIBCPP_INLINE_VISIBILITY
3108 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3109 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3110 size_type __pos) const _NOEXCEPT
3112 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
3113 return __str_find<value_type, size_type, traits_type, npos>
3114 (data(), size(), __s, __pos, traits_type::length(__s));
3117 template<class _CharT, class _Traits, class _Allocator>
3118 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3119 basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3120 size_type __pos) const _NOEXCEPT
3122 return __str_find<value_type, size_type, traits_type, npos>
3123 (data(), size(), __c, __pos);
3128 template<class _CharT, class _Traits, class _Allocator>
3129 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3130 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3132 size_type __n) const _NOEXCEPT
3134 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
3135 return __str_rfind<value_type, size_type, traits_type, npos>
3136 (data(), size(), __s, __pos, __n);
3139 template<class _CharT, class _Traits, class _Allocator>
3140 inline _LIBCPP_INLINE_VISIBILITY
3141 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3142 basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3143 size_type __pos) const _NOEXCEPT
3145 return __str_rfind<value_type, size_type, traits_type, npos>
3146 (data(), size(), __str.data(), __pos, __str.size());
3149 template<class _CharT, class _Traits, class _Allocator>
3150 inline _LIBCPP_INLINE_VISIBILITY
3151 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3152 basic_string<_CharT, _Traits, _Allocator>::rfind(__self_view __sv,
3153 size_type __pos) const _NOEXCEPT
3155 return __str_rfind<value_type, size_type, traits_type, npos>
3156 (data(), size(), __sv.data(), __pos, __sv.size());
3159 template<class _CharT, class _Traits, class _Allocator>
3160 inline _LIBCPP_INLINE_VISIBILITY
3161 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3162 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3163 size_type __pos) const _NOEXCEPT
3165 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
3166 return __str_rfind<value_type, size_type, traits_type, npos>
3167 (data(), size(), __s, __pos, traits_type::length(__s));
3170 template<class _CharT, class _Traits, class _Allocator>
3171 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3172 basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3173 size_type __pos) const _NOEXCEPT
3175 return __str_rfind<value_type, size_type, traits_type, npos>
3176 (data(), size(), __c, __pos);
3181 template<class _CharT, class _Traits, class _Allocator>
3182 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3183 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3185 size_type __n) const _NOEXCEPT
3187 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
3188 return __str_find_first_of<value_type, size_type, traits_type, npos>
3189 (data(), size(), __s, __pos, __n);
3192 template<class _CharT, class _Traits, class _Allocator>
3193 inline _LIBCPP_INLINE_VISIBILITY
3194 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3195 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3196 size_type __pos) const _NOEXCEPT
3198 return __str_find_first_of<value_type, size_type, traits_type, npos>
3199 (data(), size(), __str.data(), __pos, __str.size());
3202 template<class _CharT, class _Traits, class _Allocator>
3203 inline _LIBCPP_INLINE_VISIBILITY
3204 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3205 basic_string<_CharT, _Traits, _Allocator>::find_first_of(__self_view __sv,
3206 size_type __pos) const _NOEXCEPT
3208 return __str_find_first_of<value_type, size_type, traits_type, npos>
3209 (data(), size(), __sv.data(), __pos, __sv.size());
3212 template<class _CharT, class _Traits, class _Allocator>
3213 inline _LIBCPP_INLINE_VISIBILITY
3214 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3215 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3216 size_type __pos) const _NOEXCEPT
3218 _LIBCPP_ASSERT(__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, traits_type::length(__s));
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(value_type __c,
3227 size_type __pos) const _NOEXCEPT
3229 return find(__c, __pos);
3234 template<class _CharT, class _Traits, class _Allocator>
3235 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3236 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3238 size_type __n) const _NOEXCEPT
3240 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
3241 return __str_find_last_of<value_type, size_type, traits_type, npos>
3242 (data(), size(), __s, __pos, __n);
3245 template<class _CharT, class _Traits, class _Allocator>
3246 inline _LIBCPP_INLINE_VISIBILITY
3247 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3248 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3249 size_type __pos) const _NOEXCEPT
3251 return __str_find_last_of<value_type, size_type, traits_type, npos>
3252 (data(), size(), __str.data(), __pos, __str.size());
3255 template<class _CharT, class _Traits, class _Allocator>
3256 inline _LIBCPP_INLINE_VISIBILITY
3257 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3258 basic_string<_CharT, _Traits, _Allocator>::find_last_of(__self_view __sv,
3259 size_type __pos) const _NOEXCEPT
3261 return __str_find_last_of<value_type, size_type, traits_type, npos>
3262 (data(), size(), __sv.data(), __pos, __sv.size());
3265 template<class _CharT, class _Traits, class _Allocator>
3266 inline _LIBCPP_INLINE_VISIBILITY
3267 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3268 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3269 size_type __pos) const _NOEXCEPT
3271 _LIBCPP_ASSERT(__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, traits_type::length(__s));
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(value_type __c,
3280 size_type __pos) const _NOEXCEPT
3282 return rfind(__c, __pos);
3285 // find_first_not_of
3287 template<class _CharT, class _Traits, class _Allocator>
3288 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3289 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3291 size_type __n) const _NOEXCEPT
3293 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
3294 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3295 (data(), size(), __s, __pos, __n);
3298 template<class _CharT, class _Traits, class _Allocator>
3299 inline _LIBCPP_INLINE_VISIBILITY
3300 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3301 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3302 size_type __pos) const _NOEXCEPT
3304 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3305 (data(), size(), __str.data(), __pos, __str.size());
3308 template<class _CharT, class _Traits, class _Allocator>
3309 inline _LIBCPP_INLINE_VISIBILITY
3310 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3311 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(__self_view __sv,
3312 size_type __pos) const _NOEXCEPT
3314 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3315 (data(), size(), __sv.data(), __pos, __sv.size());
3318 template<class _CharT, class _Traits, class _Allocator>
3319 inline _LIBCPP_INLINE_VISIBILITY
3320 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3321 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3322 size_type __pos) const _NOEXCEPT
3324 _LIBCPP_ASSERT(__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, traits_type::length(__s));
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(value_type __c,
3333 size_type __pos) const _NOEXCEPT
3335 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
3336 (data(), size(), __c, __pos);
3341 template<class _CharT, class _Traits, class _Allocator>
3342 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3343 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3345 size_type __n) const _NOEXCEPT
3347 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
3348 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3349 (data(), size(), __s, __pos, __n);
3352 template<class _CharT, class _Traits, class _Allocator>
3353 inline _LIBCPP_INLINE_VISIBILITY
3354 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3355 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3356 size_type __pos) const _NOEXCEPT
3358 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3359 (data(), size(), __str.data(), __pos, __str.size());
3362 template<class _CharT, class _Traits, class _Allocator>
3363 inline _LIBCPP_INLINE_VISIBILITY
3364 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3365 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(__self_view __sv,
3366 size_type __pos) const _NOEXCEPT
3368 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3369 (data(), size(), __sv.data(), __pos, __sv.size());
3372 template<class _CharT, class _Traits, class _Allocator>
3373 inline _LIBCPP_INLINE_VISIBILITY
3374 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3375 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3376 size_type __pos) const _NOEXCEPT
3378 _LIBCPP_ASSERT(__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, traits_type::length(__s));
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(value_type __c,
3387 size_type __pos) const _NOEXCEPT
3389 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
3390 (data(), size(), __c, __pos);
3395 template <class _CharT, class _Traits, class _Allocator>
3396 inline _LIBCPP_INLINE_VISIBILITY
3398 basic_string<_CharT, _Traits, _Allocator>::compare(__self_view __sv) const _NOEXCEPT
3400 size_t __lhs_sz = size();
3401 size_t __rhs_sz = __sv.size();
3402 int __result = traits_type::compare(data(), __sv.data(),
3403 _VSTD::min(__lhs_sz, __rhs_sz));
3406 if (__lhs_sz < __rhs_sz)
3408 if (__lhs_sz > __rhs_sz)
3413 template <class _CharT, class _Traits, class _Allocator>
3414 inline _LIBCPP_INLINE_VISIBILITY
3416 basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3418 return compare(__self_view(__str));
3421 template <class _CharT, class _Traits, class _Allocator>
3423 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3425 const value_type* __s,
3426 size_type __n2) const
3428 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
3429 size_type __sz = size();
3430 if (__pos1 > __sz || __n2 == npos)
3431 this->__throw_out_of_range();
3432 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3433 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
3438 else if (__rlen > __n2)
3444 template <class _CharT, class _Traits, class _Allocator>
3445 inline _LIBCPP_INLINE_VISIBILITY
3447 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3449 __self_view __sv) const
3451 return compare(__pos1, __n1, __sv.data(), __sv.size());
3454 template <class _CharT, class _Traits, class _Allocator>
3455 inline _LIBCPP_INLINE_VISIBILITY
3457 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3459 const basic_string& __str) const
3461 return compare(__pos1, __n1, __str.data(), __str.size());
3464 template <class _CharT, class _Traits, class _Allocator>
3465 template <class _Tp>
3468 __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
3471 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3475 size_type __n2) const
3477 __self_view __sv = __t;
3478 return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3481 template <class _CharT, class _Traits, class _Allocator>
3483 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3485 const basic_string& __str,
3487 size_type __n2) const
3489 return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
3492 template <class _CharT, class _Traits, class _Allocator>
3494 basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3496 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3497 return compare(0, npos, __s, traits_type::length(__s));
3500 template <class _CharT, class _Traits, class _Allocator>
3502 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3504 const value_type* __s) const
3506 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3507 return compare(__pos1, __n1, __s, traits_type::length(__s));
3512 template<class _CharT, class _Traits, class _Allocator>
3513 inline _LIBCPP_INLINE_VISIBILITY
3515 basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3517 if (size() > capacity())
3519 if (capacity() < __min_cap - 1)
3523 if (data()[size()] != value_type(0))
3530 template<class _CharT, class _Traits, class _Allocator>
3531 inline _LIBCPP_INLINE_VISIBILITY
3533 operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3534 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3536 size_t __lhs_sz = __lhs.size();
3537 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3542 template<class _Allocator>
3543 inline _LIBCPP_INLINE_VISIBILITY
3545 operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3546 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3548 size_t __lhs_sz = __lhs.size();
3549 if (__lhs_sz != __rhs.size())
3551 const char* __lp = __lhs.data();
3552 const char* __rp = __rhs.data();
3553 if (__lhs.__is_long())
3554 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3555 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3561 template<class _CharT, class _Traits, class _Allocator>
3562 inline _LIBCPP_INLINE_VISIBILITY
3564 operator==(const _CharT* __lhs,
3565 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3567 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3568 _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
3569 size_t __lhs_len = _Traits::length(__lhs);
3570 if (__lhs_len != __rhs.size()) return false;
3571 return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
3574 template<class _CharT, class _Traits, class _Allocator>
3575 inline _LIBCPP_INLINE_VISIBILITY
3577 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3578 const _CharT* __rhs) _NOEXCEPT
3580 typedef basic_string<_CharT, _Traits, _Allocator> _String;
3581 _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
3582 size_t __rhs_len = _Traits::length(__rhs);
3583 if (__rhs_len != __lhs.size()) return false;
3584 return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
3587 template<class _CharT, class _Traits, class _Allocator>
3588 inline _LIBCPP_INLINE_VISIBILITY
3590 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3591 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3593 return !(__lhs == __rhs);
3596 template<class _CharT, class _Traits, class _Allocator>
3597 inline _LIBCPP_INLINE_VISIBILITY
3599 operator!=(const _CharT* __lhs,
3600 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3602 return !(__lhs == __rhs);
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 return !(__lhs == __rhs);
3616 template<class _CharT, class _Traits, class _Allocator>
3617 inline _LIBCPP_INLINE_VISIBILITY
3619 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3620 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3622 return __lhs.compare(__rhs) < 0;
3625 template<class _CharT, class _Traits, class _Allocator>
3626 inline _LIBCPP_INLINE_VISIBILITY
3628 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3629 const _CharT* __rhs) _NOEXCEPT
3631 return __lhs.compare(__rhs) < 0;
3634 template<class _CharT, class _Traits, class _Allocator>
3635 inline _LIBCPP_INLINE_VISIBILITY
3637 operator< (const _CharT* __lhs,
3638 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3640 return __rhs.compare(__lhs) > 0;
3645 template<class _CharT, class _Traits, class _Allocator>
3646 inline _LIBCPP_INLINE_VISIBILITY
3648 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3649 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3651 return __rhs < __lhs;
3654 template<class _CharT, class _Traits, class _Allocator>
3655 inline _LIBCPP_INLINE_VISIBILITY
3657 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3658 const _CharT* __rhs) _NOEXCEPT
3660 return __rhs < __lhs;
3663 template<class _CharT, class _Traits, class _Allocator>
3664 inline _LIBCPP_INLINE_VISIBILITY
3666 operator> (const _CharT* __lhs,
3667 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3669 return __rhs < __lhs;
3674 template<class _CharT, class _Traits, class _Allocator>
3675 inline _LIBCPP_INLINE_VISIBILITY
3677 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3678 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3680 return !(__rhs < __lhs);
3683 template<class _CharT, class _Traits, class _Allocator>
3684 inline _LIBCPP_INLINE_VISIBILITY
3686 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3687 const _CharT* __rhs) _NOEXCEPT
3689 return !(__rhs < __lhs);
3692 template<class _CharT, class _Traits, class _Allocator>
3693 inline _LIBCPP_INLINE_VISIBILITY
3695 operator<=(const _CharT* __lhs,
3696 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3698 return !(__rhs < __lhs);
3703 template<class _CharT, class _Traits, class _Allocator>
3704 inline _LIBCPP_INLINE_VISIBILITY
3706 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3707 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3709 return !(__lhs < __rhs);
3712 template<class _CharT, class _Traits, class _Allocator>
3713 inline _LIBCPP_INLINE_VISIBILITY
3715 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3716 const _CharT* __rhs) _NOEXCEPT
3718 return !(__lhs < __rhs);
3721 template<class _CharT, class _Traits, class _Allocator>
3722 inline _LIBCPP_INLINE_VISIBILITY
3724 operator>=(const _CharT* __lhs,
3725 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3727 return !(__lhs < __rhs);
3732 template<class _CharT, class _Traits, class _Allocator>
3733 basic_string<_CharT, _Traits, _Allocator>
3734 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3735 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3737 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3738 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3739 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3740 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3741 __r.append(__rhs.data(), __rhs_sz);
3745 template<class _CharT, class _Traits, class _Allocator>
3746 basic_string<_CharT, _Traits, _Allocator>
3747 operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3749 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3750 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3751 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3752 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3753 __r.append(__rhs.data(), __rhs_sz);
3757 template<class _CharT, class _Traits, class _Allocator>
3758 basic_string<_CharT, _Traits, _Allocator>
3759 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3761 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3762 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3763 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3764 __r.append(__rhs.data(), __rhs_sz);
3768 template<class _CharT, class _Traits, class _Allocator>
3769 basic_string<_CharT, _Traits, _Allocator>
3770 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3772 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3773 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3774 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3775 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3776 __r.append(__rhs, __rhs_sz);
3780 template<class _CharT, class _Traits, class _Allocator>
3781 basic_string<_CharT, _Traits, _Allocator>
3782 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3784 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3785 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3786 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3787 __r.push_back(__rhs);
3791 #ifndef _LIBCPP_CXX03_LANG
3793 template<class _CharT, class _Traits, class _Allocator>
3794 inline _LIBCPP_INLINE_VISIBILITY
3795 basic_string<_CharT, _Traits, _Allocator>
3796 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3798 return _VSTD::move(__lhs.append(__rhs));
3801 template<class _CharT, class _Traits, class _Allocator>
3802 inline _LIBCPP_INLINE_VISIBILITY
3803 basic_string<_CharT, _Traits, _Allocator>
3804 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3806 return _VSTD::move(__rhs.insert(0, __lhs));
3809 template<class _CharT, class _Traits, class _Allocator>
3810 inline _LIBCPP_INLINE_VISIBILITY
3811 basic_string<_CharT, _Traits, _Allocator>
3812 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3814 return _VSTD::move(__lhs.append(__rhs));
3817 template<class _CharT, class _Traits, class _Allocator>
3818 inline _LIBCPP_INLINE_VISIBILITY
3819 basic_string<_CharT, _Traits, _Allocator>
3820 operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3822 return _VSTD::move(__rhs.insert(0, __lhs));
3825 template<class _CharT, class _Traits, class _Allocator>
3826 inline _LIBCPP_INLINE_VISIBILITY
3827 basic_string<_CharT, _Traits, _Allocator>
3828 operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3830 __rhs.insert(__rhs.begin(), __lhs);
3831 return _VSTD::move(__rhs);
3834 template<class _CharT, class _Traits, class _Allocator>
3835 inline _LIBCPP_INLINE_VISIBILITY
3836 basic_string<_CharT, _Traits, _Allocator>
3837 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3839 return _VSTD::move(__lhs.append(__rhs));
3842 template<class _CharT, class _Traits, class _Allocator>
3843 inline _LIBCPP_INLINE_VISIBILITY
3844 basic_string<_CharT, _Traits, _Allocator>
3845 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3847 __lhs.push_back(__rhs);
3848 return _VSTD::move(__lhs);
3851 #endif // _LIBCPP_CXX03_LANG
3855 template<class _CharT, class _Traits, class _Allocator>
3856 inline _LIBCPP_INLINE_VISIBILITY
3858 swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
3859 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3860 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
3865 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3867 typedef basic_string<char16_t> u16string;
3868 typedef basic_string<char32_t> u32string;
3870 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
3872 _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3873 _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3874 _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3875 _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
3876 _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
3878 _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
3879 _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
3880 _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
3882 _LIBCPP_FUNC_VIS string to_string(int __val);
3883 _LIBCPP_FUNC_VIS string to_string(unsigned __val);
3884 _LIBCPP_FUNC_VIS string to_string(long __val);
3885 _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
3886 _LIBCPP_FUNC_VIS string to_string(long long __val);
3887 _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
3888 _LIBCPP_FUNC_VIS string to_string(float __val);
3889 _LIBCPP_FUNC_VIS string to_string(double __val);
3890 _LIBCPP_FUNC_VIS string to_string(long double __val);
3892 _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
3893 _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
3894 _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
3895 _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
3896 _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
3898 _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
3899 _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
3900 _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
3902 _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
3903 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
3904 _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
3905 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
3906 _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
3907 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
3908 _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
3909 _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
3910 _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
3912 template<class _CharT, class _Traits, class _Allocator>
3913 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
3914 basic_string<_CharT, _Traits, _Allocator>::npos;
3916 template<class _CharT, class _Traits, class _Allocator>
3917 struct _LIBCPP_TEMPLATE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
3918 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
3921 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
3924 template<class _CharT, class _Traits, class _Allocator>
3926 hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
3927 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
3929 return __do_string_hash(__val.data(), __val.data() + __val.size());
3932 template<class _CharT, class _Traits, class _Allocator>
3933 basic_ostream<_CharT, _Traits>&
3934 operator<<(basic_ostream<_CharT, _Traits>& __os,
3935 const basic_string<_CharT, _Traits, _Allocator>& __str);
3937 template<class _CharT, class _Traits, class _Allocator>
3938 basic_istream<_CharT, _Traits>&
3939 operator>>(basic_istream<_CharT, _Traits>& __is,
3940 basic_string<_CharT, _Traits, _Allocator>& __str);
3942 template<class _CharT, class _Traits, class _Allocator>
3943 basic_istream<_CharT, _Traits>&
3944 getline(basic_istream<_CharT, _Traits>& __is,
3945 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3947 template<class _CharT, class _Traits, class _Allocator>
3948 inline _LIBCPP_INLINE_VISIBILITY
3949 basic_istream<_CharT, _Traits>&
3950 getline(basic_istream<_CharT, _Traits>& __is,
3951 basic_string<_CharT, _Traits, _Allocator>& __str);
3953 #ifndef _LIBCPP_CXX03_LANG
3955 template<class _CharT, class _Traits, class _Allocator>
3956 inline _LIBCPP_INLINE_VISIBILITY
3957 basic_istream<_CharT, _Traits>&
3958 getline(basic_istream<_CharT, _Traits>&& __is,
3959 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
3961 template<class _CharT, class _Traits, class _Allocator>
3962 inline _LIBCPP_INLINE_VISIBILITY
3963 basic_istream<_CharT, _Traits>&
3964 getline(basic_istream<_CharT, _Traits>&& __is,
3965 basic_string<_CharT, _Traits, _Allocator>& __str);
3967 #endif // _LIBCPP_CXX03_LANG
3969 #if _LIBCPP_DEBUG_LEVEL >= 2
3971 template<class _CharT, class _Traits, class _Allocator>
3973 basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
3975 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
3976 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
3979 template<class _CharT, class _Traits, class _Allocator>
3981 basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
3983 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
3984 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
3987 template<class _CharT, class _Traits, class _Allocator>
3989 basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
3991 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
3992 return this->data() <= __p && __p <= this->data() + this->size();
3995 template<class _CharT, class _Traits, class _Allocator>
3997 basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
3999 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4000 return this->data() <= __p && __p < this->data() + this->size();
4003 #endif // _LIBCPP_DEBUG_LEVEL >= 2
4005 #if _LIBCPP_STD_VER > 11
4006 // Literal suffixes for basic_string [basic.string.literals]
4007 inline namespace literals
4009 inline namespace string_literals
4011 inline _LIBCPP_INLINE_VISIBILITY
4012 basic_string<char> operator "" s( const char *__str, size_t __len )
4014 return basic_string<char> (__str, __len);
4017 inline _LIBCPP_INLINE_VISIBILITY
4018 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4020 return basic_string<wchar_t> (__str, __len);
4023 inline _LIBCPP_INLINE_VISIBILITY
4024 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4026 return basic_string<char16_t> (__str, __len);
4029 inline _LIBCPP_INLINE_VISIBILITY
4030 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4032 return basic_string<char32_t> (__str, __len);
4038 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
4039 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
4040 _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
4042 _LIBCPP_END_NAMESPACE_STD
4044 #endif // _LIBCPP_STRING