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, size_type n = npos,
102 const allocator_type& a = allocator_type());
103 basic_string(const value_type* s, const allocator_type& a = allocator_type());
104 basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
105 basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
106 template<class InputIterator>
107 basic_string(InputIterator begin, InputIterator end,
108 const allocator_type& a = allocator_type());
109 basic_string(initializer_list<value_type>, const Allocator& = Allocator());
110 basic_string(const basic_string&, const Allocator&);
111 basic_string(basic_string&&, const Allocator&);
115 basic_string& operator=(const basic_string& str);
116 basic_string& operator=(basic_string&& str)
118 allocator_type::propagate_on_container_move_assignment::value &&
119 is_nothrow_move_assignable<allocator_type>::value);
120 basic_string& operator=(const value_type* s);
121 basic_string& operator=(value_type c);
122 basic_string& operator=(initializer_list<value_type>);
124 iterator begin() noexcept;
125 const_iterator begin() const noexcept;
126 iterator end() noexcept;
127 const_iterator end() const noexcept;
129 reverse_iterator rbegin() noexcept;
130 const_reverse_iterator rbegin() const noexcept;
131 reverse_iterator rend() noexcept;
132 const_reverse_iterator rend() const noexcept;
134 const_iterator cbegin() const noexcept;
135 const_iterator cend() const noexcept;
136 const_reverse_iterator crbegin() const noexcept;
137 const_reverse_iterator crend() const noexcept;
139 size_type size() const noexcept;
140 size_type length() const noexcept;
141 size_type max_size() const noexcept;
142 size_type capacity() const noexcept;
144 void resize(size_type n, value_type c);
145 void resize(size_type n);
147 void reserve(size_type res_arg = 0);
148 void shrink_to_fit();
149 void clear() noexcept;
150 bool empty() const noexcept;
152 const_reference operator[](size_type pos) const;
153 reference operator[](size_type pos);
155 const_reference at(size_type n) const;
156 reference at(size_type n);
158 basic_string& operator+=(const basic_string& str);
159 basic_string& operator+=(const value_type* s);
160 basic_string& operator+=(value_type c);
161 basic_string& operator+=(initializer_list<value_type>);
163 basic_string& append(const basic_string& str);
164 basic_string& append(const basic_string& str, size_type pos, size_type n);
165 basic_string& append(const value_type* s, size_type n);
166 basic_string& append(const value_type* s);
167 basic_string& append(size_type n, value_type c);
168 template<class InputIterator>
169 basic_string& append(InputIterator first, InputIterator last);
170 basic_string& append(initializer_list<value_type>);
172 void push_back(value_type c);
175 const_reference front() const;
177 const_reference back() const;
179 basic_string& assign(const basic_string& str);
180 basic_string& assign(basic_string&& str);
181 basic_string& assign(const basic_string& str, size_type pos, size_type n);
182 basic_string& assign(const value_type* s, size_type n);
183 basic_string& assign(const value_type* s);
184 basic_string& assign(size_type n, value_type c);
185 template<class InputIterator>
186 basic_string& assign(InputIterator first, InputIterator last);
187 basic_string& assign(initializer_list<value_type>);
189 basic_string& insert(size_type pos1, const basic_string& str);
190 basic_string& insert(size_type pos1, const basic_string& str,
191 size_type pos2, size_type n);
192 basic_string& insert(size_type pos, const value_type* s, size_type n);
193 basic_string& insert(size_type pos, const value_type* s);
194 basic_string& insert(size_type pos, size_type n, value_type c);
195 iterator insert(const_iterator p, value_type c);
196 iterator insert(const_iterator p, size_type n, value_type c);
197 template<class InputIterator>
198 iterator insert(const_iterator p, InputIterator first, InputIterator last);
199 iterator insert(const_iterator p, initializer_list<value_type>);
201 basic_string& erase(size_type pos = 0, size_type n = npos);
202 iterator erase(const_iterator position);
203 iterator erase(const_iterator first, const_iterator last);
205 basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
206 basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
207 size_type pos2, size_type n2);
208 basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
209 basic_string& replace(size_type pos, size_type n1, const value_type* s);
210 basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
211 basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
212 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
213 basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
214 basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
215 template<class InputIterator>
216 basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
217 basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
219 size_type copy(value_type* s, size_type n, size_type pos = 0) const;
220 basic_string substr(size_type pos = 0, size_type n = npos) const;
222 void swap(basic_string& str)
223 noexcept(!allocator_type::propagate_on_container_swap::value ||
224 __is_nothrow_swappable<allocator_type>::value)
226 const value_type* c_str() const noexcept;
227 const value_type* data() const noexcept;
229 allocator_type get_allocator() const noexcept;
231 size_type find(const basic_string& str, size_type pos = 0) const noexcept;
232 size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
233 size_type find(const value_type* s, size_type pos = 0) const noexcept;
234 size_type find(value_type c, size_type pos = 0) const noexcept;
236 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
237 size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
238 size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
239 size_type rfind(value_type c, size_type pos = npos) const noexcept;
241 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
242 size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
243 size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
244 size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
246 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
247 size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
248 size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
249 size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
251 size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
252 size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
253 size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
254 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
256 size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
257 size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
258 size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
259 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
261 int compare(const basic_string& str) const noexcept;
262 int compare(size_type pos1, size_type n1, const basic_string& str) const;
263 int compare(size_type pos1, size_type n1, const basic_string& str,
264 size_type pos2, size_type n2) const;
265 int compare(const value_type* s) const noexcept;
266 int compare(size_type pos1, size_type n1, const value_type* s) const;
267 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
269 bool __invariants() const;
272 template<class charT, class traits, class Allocator>
273 basic_string<charT, traits, Allocator>
274 operator+(const basic_string<charT, traits, Allocator>& lhs,
275 const basic_string<charT, traits, Allocator>& rhs);
277 template<class charT, class traits, class Allocator>
278 basic_string<charT, traits, Allocator>
279 operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
281 template<class charT, class traits, class Allocator>
282 basic_string<charT, traits, Allocator>
283 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
285 template<class charT, class traits, class Allocator>
286 basic_string<charT, traits, Allocator>
287 operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
289 template<class charT, class traits, class Allocator>
290 basic_string<charT, traits, Allocator>
291 operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
293 template<class charT, class traits, class Allocator>
294 bool operator==(const basic_string<charT, traits, Allocator>& lhs,
295 const basic_string<charT, traits, Allocator>& rhs) noexcept;
297 template<class charT, class traits, class Allocator>
298 bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
300 template<class charT, class traits, class Allocator>
301 bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
303 template<class charT, class traits, class Allocator>
304 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
305 const basic_string<charT, traits, Allocator>& rhs) noexcept;
307 template<class charT, class traits, class Allocator>
308 bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
310 template<class charT, class traits, class Allocator>
311 bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
313 template<class charT, class traits, class Allocator>
314 bool operator< (const basic_string<charT, traits, Allocator>& lhs,
315 const basic_string<charT, traits, Allocator>& rhs) noexcept;
317 template<class charT, class traits, class Allocator>
318 bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
320 template<class charT, class traits, class Allocator>
321 bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
323 template<class charT, class traits, class Allocator>
324 bool operator> (const basic_string<charT, traits, Allocator>& lhs,
325 const basic_string<charT, traits, Allocator>& rhs) noexcept;
327 template<class charT, class traits, class Allocator>
328 bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
330 template<class charT, class traits, class Allocator>
331 bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
333 template<class charT, class traits, class Allocator>
334 bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
335 const basic_string<charT, traits, Allocator>& rhs) noexcept;
337 template<class charT, class traits, class Allocator>
338 bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
340 template<class charT, class traits, class Allocator>
341 bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
343 template<class charT, class traits, class Allocator>
344 bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
345 const basic_string<charT, traits, Allocator>& rhs) noexcept;
347 template<class charT, class traits, class Allocator>
348 bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
350 template<class charT, class traits, class Allocator>
351 bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
353 template<class charT, class traits, class Allocator>
354 void swap(basic_string<charT, traits, Allocator>& lhs,
355 basic_string<charT, traits, Allocator>& rhs)
356 noexcept(noexcept(lhs.swap(rhs)));
358 template<class charT, class traits, class Allocator>
359 basic_istream<charT, traits>&
360 operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
362 template<class charT, class traits, class Allocator>
363 basic_ostream<charT, traits>&
364 operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
366 template<class charT, class traits, class Allocator>
367 basic_istream<charT, traits>&
368 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
371 template<class charT, class traits, class Allocator>
372 basic_istream<charT, traits>&
373 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
375 typedef basic_string<char> string;
376 typedef basic_string<wchar_t> wstring;
377 typedef basic_string<char16_t> u16string;
378 typedef basic_string<char32_t> u32string;
380 int stoi (const string& str, size_t* idx = 0, int base = 10);
381 long stol (const string& str, size_t* idx = 0, int base = 10);
382 unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
383 long long stoll (const string& str, size_t* idx = 0, int base = 10);
384 unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
386 float stof (const string& str, size_t* idx = 0);
387 double stod (const string& str, size_t* idx = 0);
388 long double stold(const string& str, size_t* idx = 0);
390 string to_string(int val);
391 string to_string(unsigned val);
392 string to_string(long val);
393 string to_string(unsigned long val);
394 string to_string(long long val);
395 string to_string(unsigned long long val);
396 string to_string(float val);
397 string to_string(double val);
398 string to_string(long double val);
400 int stoi (const wstring& str, size_t* idx = 0, int base = 10);
401 long stol (const wstring& str, size_t* idx = 0, int base = 10);
402 unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
403 long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
404 unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
406 float stof (const wstring& str, size_t* idx = 0);
407 double stod (const wstring& str, size_t* idx = 0);
408 long double stold(const wstring& str, size_t* idx = 0);
410 wstring to_wstring(int val);
411 wstring to_wstring(unsigned val);
412 wstring to_wstring(long val);
413 wstring to_wstring(unsigned long val);
414 wstring to_wstring(long long val);
415 wstring to_wstring(unsigned long long val);
416 wstring to_wstring(float val);
417 wstring to_wstring(double val);
418 wstring to_wstring(long double val);
420 template <> struct hash<string>;
421 template <> struct hash<u16string>;
422 template <> struct hash<u32string>;
423 template <> struct hash<wstring>;
425 basic_string<char> operator "" s( const char *str, size_t len ); // C++14
426 basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
427 basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
428 basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
437 #include <cstdio> // For EOF.
444 #include <type_traits>
445 #include <initializer_list>
446 #include <__functional_base>
447 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
450 #if defined(_LIBCPP_NO_EXCEPTIONS)
454 #include <__undef_min_max>
456 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
457 #pragma GCC system_header
460 _LIBCPP_BEGIN_NAMESPACE_STD
464 template <class _StateT>
465 class _LIBCPP_TYPE_VIS_ONLY fpos
471 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
473 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
475 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
476 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
478 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
479 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
480 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
481 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
484 template <class _StateT>
485 inline _LIBCPP_INLINE_VISIBILITY
486 streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
487 {return streamoff(__x) - streamoff(__y);}
489 template <class _StateT>
490 inline _LIBCPP_INLINE_VISIBILITY
491 bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
492 {return streamoff(__x) == streamoff(__y);}
494 template <class _StateT>
495 inline _LIBCPP_INLINE_VISIBILITY
496 bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
497 {return streamoff(__x) != streamoff(__y);}
501 template <class _CharT>
502 struct _LIBCPP_TYPE_VIS_ONLY char_traits
504 typedef _CharT char_type;
505 typedef int int_type;
506 typedef streamoff off_type;
507 typedef streampos pos_type;
508 typedef mbstate_t state_type;
510 _LIBCPP_INLINE_VISIBILITY
511 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
513 _LIBCPP_INLINE_VISIBILITY
514 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
515 {return __c1 == __c2;}
516 _LIBCPP_INLINE_VISIBILITY
517 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
518 {return __c1 < __c2;}
520 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
521 static size_t length(const char_type* __s);
522 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
523 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
524 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
525 static char_type* assign(char_type* __s, size_t __n, char_type __a);
527 _LIBCPP_INLINE_VISIBILITY
528 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
529 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
530 _LIBCPP_INLINE_VISIBILITY
531 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
532 {return char_type(__c);}
533 _LIBCPP_INLINE_VISIBILITY
534 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
535 {return int_type(__c);}
536 _LIBCPP_INLINE_VISIBILITY
537 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
538 {return __c1 == __c2;}
539 _LIBCPP_INLINE_VISIBILITY
540 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
541 {return int_type(EOF);}
544 template <class _CharT>
546 char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
548 for (; __n; --__n, ++__s1, ++__s2)
550 if (lt(*__s1, *__s2))
552 if (lt(*__s2, *__s1))
558 template <class _CharT>
559 inline _LIBCPP_INLINE_VISIBILITY
561 char_traits<_CharT>::length(const char_type* __s)
564 for (; !eq(*__s, char_type(0)); ++__s)
569 template <class _CharT>
570 inline _LIBCPP_INLINE_VISIBILITY
572 char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
583 template <class _CharT>
585 char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
587 char_type* __r = __s1;
590 for (; __n; --__n, ++__s1, ++__s2)
591 assign(*__s1, *__s2);
593 else if (__s2 < __s1)
598 assign(*--__s1, *--__s2);
603 template <class _CharT>
604 inline _LIBCPP_INLINE_VISIBILITY
606 char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
608 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
609 char_type* __r = __s1;
610 for (; __n; --__n, ++__s1, ++__s2)
611 assign(*__s1, *__s2);
615 template <class _CharT>
616 inline _LIBCPP_INLINE_VISIBILITY
618 char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
620 char_type* __r = __s;
621 for (; __n; --__n, ++__s)
629 struct _LIBCPP_TYPE_VIS_ONLY char_traits<char>
631 typedef char char_type;
632 typedef int int_type;
633 typedef streamoff off_type;
634 typedef streampos pos_type;
635 typedef mbstate_t state_type;
637 _LIBCPP_INLINE_VISIBILITY
638 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
640 _LIBCPP_INLINE_VISIBILITY
641 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
642 {return __c1 == __c2;}
643 _LIBCPP_INLINE_VISIBILITY
644 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
645 {return (unsigned char)__c1 < (unsigned char)__c2;}
647 _LIBCPP_INLINE_VISIBILITY
648 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
649 {return memcmp(__s1, __s2, __n);}
650 _LIBCPP_INLINE_VISIBILITY
651 static size_t length(const char_type* __s) {return strlen(__s);}
652 _LIBCPP_INLINE_VISIBILITY
653 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
654 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
655 _LIBCPP_INLINE_VISIBILITY
656 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
657 {return (char_type*)memmove(__s1, __s2, __n);}
658 _LIBCPP_INLINE_VISIBILITY
659 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
661 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
662 return (char_type*)memcpy(__s1, __s2, __n);
664 _LIBCPP_INLINE_VISIBILITY
665 static char_type* assign(char_type* __s, size_t __n, char_type __a)
666 {return (char_type*)memset(__s, to_int_type(__a), __n);}
668 _LIBCPP_INLINE_VISIBILITY
669 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
670 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
671 _LIBCPP_INLINE_VISIBILITY
672 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
673 {return char_type(__c);}
674 _LIBCPP_INLINE_VISIBILITY
675 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
676 {return int_type((unsigned char)__c);}
677 _LIBCPP_INLINE_VISIBILITY
678 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
679 {return __c1 == __c2;}
680 _LIBCPP_INLINE_VISIBILITY
681 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
682 {return int_type(EOF);}
685 // char_traits<wchar_t>
688 struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
690 typedef wchar_t char_type;
691 typedef wint_t int_type;
692 typedef streamoff off_type;
693 typedef streampos pos_type;
694 typedef mbstate_t state_type;
696 _LIBCPP_INLINE_VISIBILITY
697 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
699 _LIBCPP_INLINE_VISIBILITY
700 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
701 {return __c1 == __c2;}
702 _LIBCPP_INLINE_VISIBILITY
703 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
704 {return __c1 < __c2;}
706 _LIBCPP_INLINE_VISIBILITY
707 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
708 {return wmemcmp(__s1, __s2, __n);}
709 _LIBCPP_INLINE_VISIBILITY
710 static size_t length(const char_type* __s)
711 {return wcslen(__s);}
712 _LIBCPP_INLINE_VISIBILITY
713 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
714 {return (const char_type*)wmemchr(__s, __a, __n);}
715 _LIBCPP_INLINE_VISIBILITY
716 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
717 {return (char_type*)wmemmove(__s1, __s2, __n);}
718 _LIBCPP_INLINE_VISIBILITY
719 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
721 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
722 return (char_type*)wmemcpy(__s1, __s2, __n);
724 _LIBCPP_INLINE_VISIBILITY
725 static char_type* assign(char_type* __s, size_t __n, char_type __a)
726 {return (char_type*)wmemset(__s, __a, __n);}
728 _LIBCPP_INLINE_VISIBILITY
729 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
730 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
731 _LIBCPP_INLINE_VISIBILITY
732 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
733 {return char_type(__c);}
734 _LIBCPP_INLINE_VISIBILITY
735 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
736 {return int_type(__c);}
737 _LIBCPP_INLINE_VISIBILITY
738 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
739 {return __c1 == __c2;}
740 _LIBCPP_INLINE_VISIBILITY
741 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
742 {return int_type(WEOF);}
745 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
748 struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
750 typedef char16_t char_type;
751 typedef uint_least16_t int_type;
752 typedef streamoff off_type;
753 typedef u16streampos pos_type;
754 typedef mbstate_t state_type;
756 _LIBCPP_INLINE_VISIBILITY
757 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
759 _LIBCPP_INLINE_VISIBILITY
760 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
761 {return __c1 == __c2;}
762 _LIBCPP_INLINE_VISIBILITY
763 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
764 {return __c1 < __c2;}
766 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
767 static size_t length(const char_type* __s);
768 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
769 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
770 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
771 static char_type* assign(char_type* __s, size_t __n, char_type __a);
773 _LIBCPP_INLINE_VISIBILITY
774 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
775 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
776 _LIBCPP_INLINE_VISIBILITY
777 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
778 {return char_type(__c);}
779 _LIBCPP_INLINE_VISIBILITY
780 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
781 {return int_type(__c);}
782 _LIBCPP_INLINE_VISIBILITY
783 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
784 {return __c1 == __c2;}
785 _LIBCPP_INLINE_VISIBILITY
786 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
787 {return int_type(0xDFFF);}
790 inline _LIBCPP_INLINE_VISIBILITY
792 char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
794 for (; __n; --__n, ++__s1, ++__s2)
796 if (lt(*__s1, *__s2))
798 if (lt(*__s2, *__s1))
804 inline _LIBCPP_INLINE_VISIBILITY
806 char_traits<char16_t>::length(const char_type* __s)
809 for (; !eq(*__s, char_type(0)); ++__s)
814 inline _LIBCPP_INLINE_VISIBILITY
816 char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
827 inline _LIBCPP_INLINE_VISIBILITY
829 char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
831 char_type* __r = __s1;
834 for (; __n; --__n, ++__s1, ++__s2)
835 assign(*__s1, *__s2);
837 else if (__s2 < __s1)
842 assign(*--__s1, *--__s2);
847 inline _LIBCPP_INLINE_VISIBILITY
849 char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
851 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
852 char_type* __r = __s1;
853 for (; __n; --__n, ++__s1, ++__s2)
854 assign(*__s1, *__s2);
858 inline _LIBCPP_INLINE_VISIBILITY
860 char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
862 char_type* __r = __s;
863 for (; __n; --__n, ++__s)
869 struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
871 typedef char32_t char_type;
872 typedef uint_least32_t int_type;
873 typedef streamoff off_type;
874 typedef u32streampos pos_type;
875 typedef mbstate_t state_type;
877 _LIBCPP_INLINE_VISIBILITY
878 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
880 _LIBCPP_INLINE_VISIBILITY
881 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
882 {return __c1 == __c2;}
883 _LIBCPP_INLINE_VISIBILITY
884 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
885 {return __c1 < __c2;}
887 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
888 static size_t length(const char_type* __s);
889 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
890 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
891 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
892 static char_type* assign(char_type* __s, size_t __n, char_type __a);
894 _LIBCPP_INLINE_VISIBILITY
895 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
896 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
897 _LIBCPP_INLINE_VISIBILITY
898 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
899 {return char_type(__c);}
900 _LIBCPP_INLINE_VISIBILITY
901 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
902 {return int_type(__c);}
903 _LIBCPP_INLINE_VISIBILITY
904 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
905 {return __c1 == __c2;}
906 _LIBCPP_INLINE_VISIBILITY
907 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
908 {return int_type(0xFFFFFFFF);}
911 inline _LIBCPP_INLINE_VISIBILITY
913 char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
915 for (; __n; --__n, ++__s1, ++__s2)
917 if (lt(*__s1, *__s2))
919 if (lt(*__s2, *__s1))
925 inline _LIBCPP_INLINE_VISIBILITY
927 char_traits<char32_t>::length(const char_type* __s)
930 for (; !eq(*__s, char_type(0)); ++__s)
935 inline _LIBCPP_INLINE_VISIBILITY
937 char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
948 inline _LIBCPP_INLINE_VISIBILITY
950 char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
952 char_type* __r = __s1;
955 for (; __n; --__n, ++__s1, ++__s2)
956 assign(*__s1, *__s2);
958 else if (__s2 < __s1)
963 assign(*--__s1, *--__s2);
968 inline _LIBCPP_INLINE_VISIBILITY
970 char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
972 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
973 char_type* __r = __s1;
974 for (; __n; --__n, ++__s1, ++__s2)
975 assign(*__s1, *__s2);
979 inline _LIBCPP_INLINE_VISIBILITY
981 char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
983 char_type* __r = __s;
984 for (; __n; --__n, ++__s)
989 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
993 template<class _CharT, class _Traits, class _Allocator>
994 basic_string<_CharT, _Traits, _Allocator>
995 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
996 const basic_string<_CharT, _Traits, _Allocator>& __y);
998 template<class _CharT, class _Traits, class _Allocator>
999 basic_string<_CharT, _Traits, _Allocator>
1000 operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
1002 template<class _CharT, class _Traits, class _Allocator>
1003 basic_string<_CharT, _Traits, _Allocator>
1004 operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
1006 template<class _CharT, class _Traits, class _Allocator>
1007 basic_string<_CharT, _Traits, _Allocator>
1008 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
1010 template<class _CharT, class _Traits, class _Allocator>
1011 basic_string<_CharT, _Traits, _Allocator>
1012 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
1015 class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
1018 void __throw_length_error() const;
1019 void __throw_out_of_range() const;
1024 __basic_string_common<__b>::__throw_length_error() const
1026 #ifndef _LIBCPP_NO_EXCEPTIONS
1027 throw length_error("basic_string");
1029 assert(!"basic_string length_error");
1035 __basic_string_common<__b>::__throw_out_of_range() const
1037 #ifndef _LIBCPP_NO_EXCEPTIONS
1038 throw out_of_range("basic_string");
1040 assert(!"basic_string out_of_range");
1045 #pragma warning( push )
1046 #pragma warning( disable: 4231 )
1047 #endif // _LIBCPP_MSVC
1048 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
1050 #pragma warning( pop )
1051 #endif // _LIBCPP_MSVC
1053 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1055 template <class _CharT, size_t = sizeof(_CharT)>
1058 unsigned char __xx[sizeof(_CharT)-1];
1061 template <class _CharT>
1062 struct __padding<_CharT, 1>
1066 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1068 template<class _CharT, class _Traits, class _Allocator>
1069 class _LIBCPP_TYPE_VIS_ONLY basic_string
1070 : private __basic_string_common<true>
1073 typedef basic_string __self;
1074 typedef _Traits traits_type;
1075 typedef typename traits_type::char_type value_type;
1076 typedef _Allocator allocator_type;
1077 typedef allocator_traits<allocator_type> __alloc_traits;
1078 typedef typename __alloc_traits::size_type size_type;
1079 typedef typename __alloc_traits::difference_type difference_type;
1080 typedef value_type& reference;
1081 typedef const value_type& const_reference;
1082 typedef typename __alloc_traits::pointer pointer;
1083 typedef typename __alloc_traits::const_pointer const_pointer;
1085 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1086 static_assert((is_same<_CharT, value_type>::value),
1087 "traits_type::char_type must be the same type as CharT");
1088 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1089 "Allocator::value_type must be same type as value_type");
1090 #if defined(_LIBCPP_RAW_ITERATORS)
1091 typedef pointer iterator;
1092 typedef const_pointer const_iterator;
1093 #else // defined(_LIBCPP_RAW_ITERATORS)
1094 typedef __wrap_iter<pointer> iterator;
1095 typedef __wrap_iter<const_pointer> const_iterator;
1096 #endif // defined(_LIBCPP_RAW_ITERATORS)
1097 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1098 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1102 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1111 #if _LIBCPP_BIG_ENDIAN
1112 enum {__short_mask = 0x01};
1113 enum {__long_mask = 0x1ul};
1114 #else // _LIBCPP_BIG_ENDIAN
1115 enum {__short_mask = 0x80};
1116 enum {__long_mask = ~(size_type(~0) >> 1)};
1117 #endif // _LIBCPP_BIG_ENDIAN
1119 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1120 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1124 value_type __data_[__min_cap];
1126 : __padding<value_type>
1128 unsigned char __size_;
1141 #if _LIBCPP_BIG_ENDIAN
1142 enum {__short_mask = 0x80};
1143 enum {__long_mask = ~(size_type(~0) >> 1)};
1144 #else // _LIBCPP_BIG_ENDIAN
1145 enum {__short_mask = 0x01};
1146 enum {__long_mask = 0x1ul};
1147 #endif // _LIBCPP_BIG_ENDIAN
1149 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1150 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1156 unsigned char __size_;
1159 value_type __data_[__min_cap];
1162 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1164 union __ulx{__long __lx; __short __lxx;};
1166 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
1170 size_type __words[__n_words];
1183 __compressed_pair<__rep, allocator_type> __r_;
1186 static const size_type npos = -1;
1188 _LIBCPP_INLINE_VISIBILITY basic_string()
1189 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
1190 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
1191 basic_string(const basic_string& __str);
1192 basic_string(const basic_string& __str, const allocator_type& __a);
1193 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1194 _LIBCPP_INLINE_VISIBILITY
1195 basic_string(basic_string&& __str)
1196 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
1197 _LIBCPP_INLINE_VISIBILITY
1198 basic_string(basic_string&& __str, const allocator_type& __a);
1199 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1200 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
1201 _LIBCPP_INLINE_VISIBILITY
1202 basic_string(const value_type* __s, const allocator_type& __a);
1203 _LIBCPP_INLINE_VISIBILITY
1204 basic_string(const value_type* __s, size_type __n);
1205 _LIBCPP_INLINE_VISIBILITY
1206 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
1207 _LIBCPP_INLINE_VISIBILITY
1208 basic_string(size_type __n, value_type __c);
1209 _LIBCPP_INLINE_VISIBILITY
1210 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1211 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1212 const allocator_type& __a = allocator_type());
1213 template<class _InputIterator>
1214 _LIBCPP_INLINE_VISIBILITY
1215 basic_string(_InputIterator __first, _InputIterator __last);
1216 template<class _InputIterator>
1217 _LIBCPP_INLINE_VISIBILITY
1218 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
1219 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1220 _LIBCPP_INLINE_VISIBILITY
1221 basic_string(initializer_list<value_type> __il);
1222 _LIBCPP_INLINE_VISIBILITY
1223 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
1224 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1228 basic_string& operator=(const basic_string& __str);
1229 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1230 _LIBCPP_INLINE_VISIBILITY
1231 basic_string& operator=(basic_string&& __str)
1232 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1233 is_nothrow_move_assignable<allocator_type>::value);
1235 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
1236 basic_string& operator=(value_type __c);
1237 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1238 _LIBCPP_INLINE_VISIBILITY
1239 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1240 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1242 #if _LIBCPP_DEBUG_LEVEL >= 2
1243 _LIBCPP_INLINE_VISIBILITY
1244 iterator begin() _NOEXCEPT
1245 {return iterator(this, __get_pointer());}
1246 _LIBCPP_INLINE_VISIBILITY
1247 const_iterator begin() const _NOEXCEPT
1248 {return const_iterator(this, __get_pointer());}
1249 _LIBCPP_INLINE_VISIBILITY
1250 iterator end() _NOEXCEPT
1251 {return iterator(this, __get_pointer() + size());}
1252 _LIBCPP_INLINE_VISIBILITY
1253 const_iterator end() const _NOEXCEPT
1254 {return const_iterator(this, __get_pointer() + size());}
1256 _LIBCPP_INLINE_VISIBILITY
1257 iterator begin() _NOEXCEPT
1258 {return iterator(__get_pointer());}
1259 _LIBCPP_INLINE_VISIBILITY
1260 const_iterator begin() const _NOEXCEPT
1261 {return const_iterator(__get_pointer());}
1262 _LIBCPP_INLINE_VISIBILITY
1263 iterator end() _NOEXCEPT
1264 {return iterator(__get_pointer() + size());}
1265 _LIBCPP_INLINE_VISIBILITY
1266 const_iterator end() const _NOEXCEPT
1267 {return const_iterator(__get_pointer() + size());}
1268 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1269 _LIBCPP_INLINE_VISIBILITY
1270 reverse_iterator rbegin() _NOEXCEPT
1271 {return reverse_iterator(end());}
1272 _LIBCPP_INLINE_VISIBILITY
1273 const_reverse_iterator rbegin() const _NOEXCEPT
1274 {return const_reverse_iterator(end());}
1275 _LIBCPP_INLINE_VISIBILITY
1276 reverse_iterator rend() _NOEXCEPT
1277 {return reverse_iterator(begin());}
1278 _LIBCPP_INLINE_VISIBILITY
1279 const_reverse_iterator rend() const _NOEXCEPT
1280 {return const_reverse_iterator(begin());}
1282 _LIBCPP_INLINE_VISIBILITY
1283 const_iterator cbegin() const _NOEXCEPT
1285 _LIBCPP_INLINE_VISIBILITY
1286 const_iterator cend() const _NOEXCEPT
1288 _LIBCPP_INLINE_VISIBILITY
1289 const_reverse_iterator crbegin() const _NOEXCEPT
1291 _LIBCPP_INLINE_VISIBILITY
1292 const_reverse_iterator crend() const _NOEXCEPT
1295 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
1296 {return __is_long() ? __get_long_size() : __get_short_size();}
1297 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1298 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1299 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
1300 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1302 void resize(size_type __n, value_type __c);
1303 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1305 void reserve(size_type res_arg = 0);
1306 _LIBCPP_INLINE_VISIBILITY
1307 void shrink_to_fit() _NOEXCEPT {reserve();}
1308 _LIBCPP_INLINE_VISIBILITY
1309 void clear() _NOEXCEPT;
1310 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
1312 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1313 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1315 const_reference at(size_type __n) const;
1316 reference at(size_type __n);
1318 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1319 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
1320 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1321 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1322 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1323 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1325 _LIBCPP_INLINE_VISIBILITY
1326 basic_string& append(const basic_string& __str);
1327 basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
1328 basic_string& append(const value_type* __s, size_type __n);
1329 basic_string& append(const value_type* __s);
1330 basic_string& append(size_type __n, value_type __c);
1331 template<class _InputIterator>
1334 __is_input_iterator <_InputIterator>::value &&
1335 !__is_forward_iterator<_InputIterator>::value,
1338 append(_InputIterator __first, _InputIterator __last);
1339 template<class _ForwardIterator>
1342 __is_forward_iterator<_ForwardIterator>::value,
1345 append(_ForwardIterator __first, _ForwardIterator __last);
1346 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1347 _LIBCPP_INLINE_VISIBILITY
1348 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
1349 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1351 void push_back(value_type __c);
1352 _LIBCPP_INLINE_VISIBILITY
1354 _LIBCPP_INLINE_VISIBILITY reference front();
1355 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1356 _LIBCPP_INLINE_VISIBILITY reference back();
1357 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
1359 _LIBCPP_INLINE_VISIBILITY
1360 basic_string& assign(const basic_string& __str);
1361 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1362 _LIBCPP_INLINE_VISIBILITY
1363 basic_string& assign(basic_string&& str)
1364 {*this = _VSTD::move(str); return *this;}
1366 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
1367 basic_string& assign(const value_type* __s, size_type __n);
1368 basic_string& assign(const value_type* __s);
1369 basic_string& assign(size_type __n, value_type __c);
1370 template<class _InputIterator>
1373 __is_input_iterator <_InputIterator>::value &&
1374 !__is_forward_iterator<_InputIterator>::value,
1377 assign(_InputIterator __first, _InputIterator __last);
1378 template<class _ForwardIterator>
1381 __is_forward_iterator<_ForwardIterator>::value,
1384 assign(_ForwardIterator __first, _ForwardIterator __last);
1385 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1386 _LIBCPP_INLINE_VISIBILITY
1387 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1388 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1390 _LIBCPP_INLINE_VISIBILITY
1391 basic_string& insert(size_type __pos1, const basic_string& __str);
1392 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
1393 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1394 basic_string& insert(size_type __pos, const value_type* __s);
1395 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1396 iterator insert(const_iterator __pos, value_type __c);
1397 _LIBCPP_INLINE_VISIBILITY
1398 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1399 template<class _InputIterator>
1402 __is_input_iterator <_InputIterator>::value &&
1403 !__is_forward_iterator<_InputIterator>::value,
1406 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1407 template<class _ForwardIterator>
1410 __is_forward_iterator<_ForwardIterator>::value,
1413 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1414 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1415 _LIBCPP_INLINE_VISIBILITY
1416 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1417 {return insert(__pos, __il.begin(), __il.end());}
1418 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1420 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1421 _LIBCPP_INLINE_VISIBILITY
1422 iterator erase(const_iterator __pos);
1423 _LIBCPP_INLINE_VISIBILITY
1424 iterator erase(const_iterator __first, const_iterator __last);
1426 _LIBCPP_INLINE_VISIBILITY
1427 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1428 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
1429 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1430 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1431 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1432 _LIBCPP_INLINE_VISIBILITY
1433 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1434 _LIBCPP_INLINE_VISIBILITY
1435 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1436 _LIBCPP_INLINE_VISIBILITY
1437 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1438 _LIBCPP_INLINE_VISIBILITY
1439 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1440 template<class _InputIterator>
1443 __is_input_iterator<_InputIterator>::value,
1446 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1447 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1448 _LIBCPP_INLINE_VISIBILITY
1449 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1450 {return replace(__i1, __i2, __il.begin(), __il.end());}
1451 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1453 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1454 _LIBCPP_INLINE_VISIBILITY
1455 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1457 _LIBCPP_INLINE_VISIBILITY
1458 void swap(basic_string& __str)
1459 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1460 __is_nothrow_swappable<allocator_type>::value);
1462 _LIBCPP_INLINE_VISIBILITY
1463 const value_type* c_str() const _NOEXCEPT {return data();}
1464 _LIBCPP_INLINE_VISIBILITY
1465 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1467 _LIBCPP_INLINE_VISIBILITY
1468 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
1470 _LIBCPP_INLINE_VISIBILITY
1471 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1472 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1473 _LIBCPP_INLINE_VISIBILITY
1474 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1475 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1477 _LIBCPP_INLINE_VISIBILITY
1478 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1479 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1480 _LIBCPP_INLINE_VISIBILITY
1481 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1482 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1484 _LIBCPP_INLINE_VISIBILITY
1485 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1486 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1487 _LIBCPP_INLINE_VISIBILITY
1488 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1489 _LIBCPP_INLINE_VISIBILITY
1490 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1492 _LIBCPP_INLINE_VISIBILITY
1493 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1494 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1495 _LIBCPP_INLINE_VISIBILITY
1496 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1497 _LIBCPP_INLINE_VISIBILITY
1498 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1500 _LIBCPP_INLINE_VISIBILITY
1501 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1502 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1503 _LIBCPP_INLINE_VISIBILITY
1504 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1505 _LIBCPP_INLINE_VISIBILITY
1506 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1508 _LIBCPP_INLINE_VISIBILITY
1509 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1510 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1511 _LIBCPP_INLINE_VISIBILITY
1512 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1513 _LIBCPP_INLINE_VISIBILITY
1514 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1516 _LIBCPP_INLINE_VISIBILITY
1517 int compare(const basic_string& __str) const _NOEXCEPT;
1518 _LIBCPP_INLINE_VISIBILITY
1519 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1520 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
1521 int compare(const value_type* __s) const _NOEXCEPT;
1522 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1523 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1525 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1527 _LIBCPP_INLINE_VISIBILITY
1528 bool __is_long() const _NOEXCEPT
1529 {return bool(__r_.first().__s.__size_ & __short_mask);}
1531 #if _LIBCPP_DEBUG_LEVEL >= 2
1533 bool __dereferenceable(const const_iterator* __i) const;
1534 bool __decrementable(const const_iterator* __i) const;
1535 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1536 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1538 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1541 _LIBCPP_INLINE_VISIBILITY
1542 allocator_type& __alloc() _NOEXCEPT
1543 {return __r_.second();}
1544 _LIBCPP_INLINE_VISIBILITY
1545 const allocator_type& __alloc() const _NOEXCEPT
1546 {return __r_.second();}
1548 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1550 _LIBCPP_INLINE_VISIBILITY
1551 void __set_short_size(size_type __s) _NOEXCEPT
1552 # if _LIBCPP_BIG_ENDIAN
1553 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1555 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1558 _LIBCPP_INLINE_VISIBILITY
1559 size_type __get_short_size() const _NOEXCEPT
1560 # if _LIBCPP_BIG_ENDIAN
1561 {return __r_.first().__s.__size_ >> 1;}
1563 {return __r_.first().__s.__size_;}
1566 #else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1568 _LIBCPP_INLINE_VISIBILITY
1569 void __set_short_size(size_type __s) _NOEXCEPT
1570 # if _LIBCPP_BIG_ENDIAN
1571 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1573 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1576 _LIBCPP_INLINE_VISIBILITY
1577 size_type __get_short_size() const _NOEXCEPT
1578 # if _LIBCPP_BIG_ENDIAN
1579 {return __r_.first().__s.__size_;}
1581 {return __r_.first().__s.__size_ >> 1;}
1584 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1586 _LIBCPP_INLINE_VISIBILITY
1587 void __set_long_size(size_type __s) _NOEXCEPT
1588 {__r_.first().__l.__size_ = __s;}
1589 _LIBCPP_INLINE_VISIBILITY
1590 size_type __get_long_size() const _NOEXCEPT
1591 {return __r_.first().__l.__size_;}
1592 _LIBCPP_INLINE_VISIBILITY
1593 void __set_size(size_type __s) _NOEXCEPT
1594 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1596 _LIBCPP_INLINE_VISIBILITY
1597 void __set_long_cap(size_type __s) _NOEXCEPT
1598 {__r_.first().__l.__cap_ = __long_mask | __s;}
1599 _LIBCPP_INLINE_VISIBILITY
1600 size_type __get_long_cap() const _NOEXCEPT
1601 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1603 _LIBCPP_INLINE_VISIBILITY
1604 void __set_long_pointer(pointer __p) _NOEXCEPT
1605 {__r_.first().__l.__data_ = __p;}
1606 _LIBCPP_INLINE_VISIBILITY
1607 pointer __get_long_pointer() _NOEXCEPT
1608 {return __r_.first().__l.__data_;}
1609 _LIBCPP_INLINE_VISIBILITY
1610 const_pointer __get_long_pointer() const _NOEXCEPT
1611 {return __r_.first().__l.__data_;}
1612 _LIBCPP_INLINE_VISIBILITY
1613 pointer __get_short_pointer() _NOEXCEPT
1614 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1615 _LIBCPP_INLINE_VISIBILITY
1616 const_pointer __get_short_pointer() const _NOEXCEPT
1617 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1618 _LIBCPP_INLINE_VISIBILITY
1619 pointer __get_pointer() _NOEXCEPT
1620 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1621 _LIBCPP_INLINE_VISIBILITY
1622 const_pointer __get_pointer() const _NOEXCEPT
1623 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1625 _LIBCPP_INLINE_VISIBILITY
1626 void __zero() _NOEXCEPT
1628 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1629 for (unsigned __i = 0; __i < __n_words; ++__i)
1633 template <size_type __a> static
1634 _LIBCPP_INLINE_VISIBILITY
1635 size_type __align_it(size_type __s) _NOEXCEPT
1636 {return __s + (__a-1) & ~(__a-1);}
1637 enum {__alignment = 16};
1638 static _LIBCPP_INLINE_VISIBILITY
1639 size_type __recommend(size_type __s) _NOEXCEPT
1640 {return (__s < __min_cap ? __min_cap :
1641 __align_it<sizeof(value_type) < __alignment ?
1642 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
1644 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1645 void __init(const value_type* __s, size_type __sz);
1646 void __init(size_type __n, value_type __c);
1648 template <class _InputIterator>
1651 __is_input_iterator <_InputIterator>::value &&
1652 !__is_forward_iterator<_InputIterator>::value,
1655 __init(_InputIterator __first, _InputIterator __last);
1657 template <class _ForwardIterator>
1660 __is_forward_iterator<_ForwardIterator>::value,
1663 __init(_ForwardIterator __first, _ForwardIterator __last);
1665 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1666 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1667 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1668 size_type __n_copy, size_type __n_del,
1669 size_type __n_add, const value_type* __p_new_stuff);
1671 _LIBCPP_INLINE_VISIBILITY
1672 void __erase_to_end(size_type __pos);
1674 _LIBCPP_INLINE_VISIBILITY
1675 void __copy_assign_alloc(const basic_string& __str)
1676 {__copy_assign_alloc(__str, integral_constant<bool,
1677 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1679 _LIBCPP_INLINE_VISIBILITY
1680 void __copy_assign_alloc(const basic_string& __str, true_type)
1682 if (__alloc() != __str.__alloc())
1687 __alloc() = __str.__alloc();
1690 _LIBCPP_INLINE_VISIBILITY
1691 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
1694 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1695 _LIBCPP_INLINE_VISIBILITY
1696 void __move_assign(basic_string& __str, false_type);
1697 _LIBCPP_INLINE_VISIBILITY
1698 void __move_assign(basic_string& __str, true_type)
1699 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1702 _LIBCPP_INLINE_VISIBILITY
1704 __move_assign_alloc(basic_string& __str)
1706 !__alloc_traits::propagate_on_container_move_assignment::value ||
1707 is_nothrow_move_assignable<allocator_type>::value)
1708 {__move_assign_alloc(__str, integral_constant<bool,
1709 __alloc_traits::propagate_on_container_move_assignment::value>());}
1711 _LIBCPP_INLINE_VISIBILITY
1712 void __move_assign_alloc(basic_string& __c, true_type)
1713 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1715 __alloc() = _VSTD::move(__c.__alloc());
1718 _LIBCPP_INLINE_VISIBILITY
1719 void __move_assign_alloc(basic_string&, false_type)
1723 _LIBCPP_INLINE_VISIBILITY
1724 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1725 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1726 __is_nothrow_swappable<allocator_type>::value)
1727 {__swap_alloc(__x, __y, integral_constant<bool,
1728 __alloc_traits::propagate_on_container_swap::value>());}
1730 _LIBCPP_INLINE_VISIBILITY
1731 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1732 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
1737 _LIBCPP_INLINE_VISIBILITY
1738 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
1741 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1742 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
1744 friend basic_string operator+<>(const basic_string&, const basic_string&);
1745 friend basic_string operator+<>(const value_type*, const basic_string&);
1746 friend basic_string operator+<>(value_type, const basic_string&);
1747 friend basic_string operator+<>(const basic_string&, const value_type*);
1748 friend basic_string operator+<>(const basic_string&, value_type);
1751 template <class _CharT, class _Traits, class _Allocator>
1752 inline _LIBCPP_INLINE_VISIBILITY
1754 basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1756 #if _LIBCPP_DEBUG_LEVEL >= 2
1757 __get_db()->__invalidate_all(this);
1758 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1761 template <class _CharT, class _Traits, class _Allocator>
1762 inline _LIBCPP_INLINE_VISIBILITY
1764 basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1765 #if _LIBCPP_DEBUG_LEVEL >= 2
1770 #if _LIBCPP_DEBUG_LEVEL >= 2
1771 __c_node* __c = __get_db()->__find_c_and_lock(this);
1774 const_pointer __new_last = __get_pointer() + __pos;
1775 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1778 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1779 if (__i->base() > __new_last)
1781 (*__p)->__c_ = nullptr;
1782 if (--__c->end_ != __p)
1783 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1786 __get_db()->unlock();
1788 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1791 template <class _CharT, class _Traits, class _Allocator>
1792 inline _LIBCPP_INLINE_VISIBILITY
1793 basic_string<_CharT, _Traits, _Allocator>::basic_string()
1794 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1796 #if _LIBCPP_DEBUG_LEVEL >= 2
1797 __get_db()->__insert_c(this);
1802 template <class _CharT, class _Traits, class _Allocator>
1803 inline _LIBCPP_INLINE_VISIBILITY
1804 basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1807 #if _LIBCPP_DEBUG_LEVEL >= 2
1808 __get_db()->__insert_c(this);
1813 template <class _CharT, class _Traits, class _Allocator>
1815 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
1817 if (__reserve > max_size())
1818 this->__throw_length_error();
1820 if (__reserve < __min_cap)
1822 __set_short_size(__sz);
1823 __p = __get_short_pointer();
1827 size_type __cap = __recommend(__reserve);
1828 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1829 __set_long_pointer(__p);
1830 __set_long_cap(__cap+1);
1831 __set_long_size(__sz);
1833 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1834 traits_type::assign(__p[__sz], value_type());
1837 template <class _CharT, class _Traits, class _Allocator>
1839 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1841 if (__sz > max_size())
1842 this->__throw_length_error();
1844 if (__sz < __min_cap)
1846 __set_short_size(__sz);
1847 __p = __get_short_pointer();
1851 size_type __cap = __recommend(__sz);
1852 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1853 __set_long_pointer(__p);
1854 __set_long_cap(__cap+1);
1855 __set_long_size(__sz);
1857 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1858 traits_type::assign(__p[__sz], value_type());
1861 template <class _CharT, class _Traits, class _Allocator>
1862 inline _LIBCPP_INLINE_VISIBILITY
1863 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
1865 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
1866 __init(__s, traits_type::length(__s));
1867 #if _LIBCPP_DEBUG_LEVEL >= 2
1868 __get_db()->__insert_c(this);
1872 template <class _CharT, class _Traits, class _Allocator>
1873 inline _LIBCPP_INLINE_VISIBILITY
1874 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
1877 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
1878 __init(__s, traits_type::length(__s));
1879 #if _LIBCPP_DEBUG_LEVEL >= 2
1880 __get_db()->__insert_c(this);
1884 template <class _CharT, class _Traits, class _Allocator>
1885 inline _LIBCPP_INLINE_VISIBILITY
1886 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
1888 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
1890 #if _LIBCPP_DEBUG_LEVEL >= 2
1891 __get_db()->__insert_c(this);
1895 template <class _CharT, class _Traits, class _Allocator>
1896 inline _LIBCPP_INLINE_VISIBILITY
1897 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
1900 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
1902 #if _LIBCPP_DEBUG_LEVEL >= 2
1903 __get_db()->__insert_c(this);
1907 template <class _CharT, class _Traits, class _Allocator>
1908 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1909 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
1911 if (!__str.__is_long())
1912 __r_.first().__r = __str.__r_.first().__r;
1914 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1915 #if _LIBCPP_DEBUG_LEVEL >= 2
1916 __get_db()->__insert_c(this);
1920 template <class _CharT, class _Traits, class _Allocator>
1921 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1924 if (!__str.__is_long())
1925 __r_.first().__r = __str.__r_.first().__r;
1927 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1928 #if _LIBCPP_DEBUG_LEVEL >= 2
1929 __get_db()->__insert_c(this);
1933 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1935 template <class _CharT, class _Traits, class _Allocator>
1936 inline _LIBCPP_INLINE_VISIBILITY
1937 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1938 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1939 : __r_(_VSTD::move(__str.__r_))
1942 #if _LIBCPP_DEBUG_LEVEL >= 2
1943 __get_db()->__insert_c(this);
1945 __get_db()->swap(this, &__str);
1949 template <class _CharT, class _Traits, class _Allocator>
1950 inline _LIBCPP_INLINE_VISIBILITY
1951 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1954 if (__a == __str.__alloc() || !__str.__is_long())
1955 __r_.first().__r = __str.__r_.first().__r;
1957 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1959 #if _LIBCPP_DEBUG_LEVEL >= 2
1960 __get_db()->__insert_c(this);
1962 __get_db()->swap(this, &__str);
1966 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1968 template <class _CharT, class _Traits, class _Allocator>
1970 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1972 if (__n > max_size())
1973 this->__throw_length_error();
1975 if (__n < __min_cap)
1977 __set_short_size(__n);
1978 __p = __get_short_pointer();
1982 size_type __cap = __recommend(__n);
1983 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1984 __set_long_pointer(__p);
1985 __set_long_cap(__cap+1);
1986 __set_long_size(__n);
1988 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
1989 traits_type::assign(__p[__n], value_type());
1992 template <class _CharT, class _Traits, class _Allocator>
1993 inline _LIBCPP_INLINE_VISIBILITY
1994 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1997 #if _LIBCPP_DEBUG_LEVEL >= 2
1998 __get_db()->__insert_c(this);
2002 template <class _CharT, class _Traits, class _Allocator>
2003 inline _LIBCPP_INLINE_VISIBILITY
2004 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2008 #if _LIBCPP_DEBUG_LEVEL >= 2
2009 __get_db()->__insert_c(this);
2013 template <class _CharT, class _Traits, class _Allocator>
2014 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2015 const allocator_type& __a)
2018 size_type __str_sz = __str.size();
2019 if (__pos > __str_sz)
2020 this->__throw_out_of_range();
2021 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2022 #if _LIBCPP_DEBUG_LEVEL >= 2
2023 __get_db()->__insert_c(this);
2027 template <class _CharT, class _Traits, class _Allocator>
2028 template <class _InputIterator>
2031 __is_input_iterator <_InputIterator>::value &&
2032 !__is_forward_iterator<_InputIterator>::value,
2035 basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2038 #ifndef _LIBCPP_NO_EXCEPTIONS
2041 #endif // _LIBCPP_NO_EXCEPTIONS
2042 for (; __first != __last; ++__first)
2043 push_back(*__first);
2044 #ifndef _LIBCPP_NO_EXCEPTIONS
2049 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2052 #endif // _LIBCPP_NO_EXCEPTIONS
2055 template <class _CharT, class _Traits, class _Allocator>
2056 template <class _ForwardIterator>
2059 __is_forward_iterator<_ForwardIterator>::value,
2062 basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2064 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
2065 if (__sz > max_size())
2066 this->__throw_length_error();
2068 if (__sz < __min_cap)
2070 __set_short_size(__sz);
2071 __p = __get_short_pointer();
2075 size_type __cap = __recommend(__sz);
2076 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2077 __set_long_pointer(__p);
2078 __set_long_cap(__cap+1);
2079 __set_long_size(__sz);
2081 for (; __first != __last; ++__first, ++__p)
2082 traits_type::assign(*__p, *__first);
2083 traits_type::assign(*__p, value_type());
2086 template <class _CharT, class _Traits, class _Allocator>
2087 template<class _InputIterator>
2088 inline _LIBCPP_INLINE_VISIBILITY
2089 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2091 __init(__first, __last);
2092 #if _LIBCPP_DEBUG_LEVEL >= 2
2093 __get_db()->__insert_c(this);
2097 template <class _CharT, class _Traits, class _Allocator>
2098 template<class _InputIterator>
2099 inline _LIBCPP_INLINE_VISIBILITY
2100 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2101 const allocator_type& __a)
2104 __init(__first, __last);
2105 #if _LIBCPP_DEBUG_LEVEL >= 2
2106 __get_db()->__insert_c(this);
2110 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2112 template <class _CharT, class _Traits, class _Allocator>
2113 inline _LIBCPP_INLINE_VISIBILITY
2114 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2116 __init(__il.begin(), __il.end());
2117 #if _LIBCPP_DEBUG_LEVEL >= 2
2118 __get_db()->__insert_c(this);
2122 template <class _CharT, class _Traits, class _Allocator>
2123 inline _LIBCPP_INLINE_VISIBILITY
2124 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2127 __init(__il.begin(), __il.end());
2128 #if _LIBCPP_DEBUG_LEVEL >= 2
2129 __get_db()->__insert_c(this);
2133 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2135 template <class _CharT, class _Traits, class _Allocator>
2136 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2138 #if _LIBCPP_DEBUG_LEVEL >= 2
2139 __get_db()->__erase_c(this);
2142 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2145 template <class _CharT, class _Traits, class _Allocator>
2147 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2148 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2149 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
2151 size_type __ms = max_size();
2152 if (__delta_cap > __ms - __old_cap - 1)
2153 this->__throw_length_error();
2154 pointer __old_p = __get_pointer();
2155 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2156 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2158 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2159 __invalidate_all_iterators();
2161 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2162 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2164 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
2165 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2166 if (__sec_cp_sz != 0)
2167 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2168 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2169 if (__old_cap+1 != __min_cap)
2170 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2171 __set_long_pointer(__p);
2172 __set_long_cap(__cap+1);
2173 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2174 __set_long_size(__old_sz);
2175 traits_type::assign(__p[__old_sz], value_type());
2178 template <class _CharT, class _Traits, class _Allocator>
2180 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2181 size_type __n_copy, size_type __n_del, size_type __n_add)
2183 size_type __ms = max_size();
2184 if (__delta_cap > __ms - __old_cap)
2185 this->__throw_length_error();
2186 pointer __old_p = __get_pointer();
2187 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2188 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2190 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2191 __invalidate_all_iterators();
2193 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2194 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2195 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2196 if (__sec_cp_sz != 0)
2197 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2198 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2200 if (__old_cap+1 != __min_cap)
2201 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2202 __set_long_pointer(__p);
2203 __set_long_cap(__cap+1);
2208 template <class _CharT, class _Traits, class _Allocator>
2209 basic_string<_CharT, _Traits, _Allocator>&
2210 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2212 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign recieved nullptr");
2213 size_type __cap = capacity();
2216 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2217 traits_type::move(__p, __s, __n);
2218 traits_type::assign(__p[__n], value_type());
2220 __invalidate_iterators_past(__n);
2224 size_type __sz = size();
2225 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2230 template <class _CharT, class _Traits, class _Allocator>
2231 basic_string<_CharT, _Traits, _Allocator>&
2232 basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2234 size_type __cap = capacity();
2237 size_type __sz = size();
2238 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2241 __invalidate_iterators_past(__n);
2242 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2243 traits_type::assign(__p, __n, __c);
2244 traits_type::assign(__p[__n], value_type());
2249 template <class _CharT, class _Traits, class _Allocator>
2250 basic_string<_CharT, _Traits, _Allocator>&
2251 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2256 __p = __get_long_pointer();
2261 __p = __get_short_pointer();
2262 __set_short_size(1);
2264 traits_type::assign(*__p, __c);
2265 traits_type::assign(*++__p, value_type());
2266 __invalidate_iterators_past(1);
2270 template <class _CharT, class _Traits, class _Allocator>
2271 basic_string<_CharT, _Traits, _Allocator>&
2272 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2276 __copy_assign_alloc(__str);
2282 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2284 template <class _CharT, class _Traits, class _Allocator>
2285 inline _LIBCPP_INLINE_VISIBILITY
2287 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2289 if (__alloc() != __str.__alloc())
2292 __move_assign(__str, true_type());
2295 template <class _CharT, class _Traits, class _Allocator>
2296 inline _LIBCPP_INLINE_VISIBILITY
2298 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2299 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2303 __r_.first() = __str.__r_.first();
2304 __move_assign_alloc(__str);
2308 template <class _CharT, class _Traits, class _Allocator>
2309 inline _LIBCPP_INLINE_VISIBILITY
2310 basic_string<_CharT, _Traits, _Allocator>&
2311 basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2312 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2313 is_nothrow_move_assignable<allocator_type>::value)
2315 __move_assign(__str, integral_constant<bool,
2316 __alloc_traits::propagate_on_container_move_assignment::value>());
2322 template <class _CharT, class _Traits, class _Allocator>
2323 template<class _InputIterator>
2326 __is_input_iterator <_InputIterator>::value &&
2327 !__is_forward_iterator<_InputIterator>::value,
2328 basic_string<_CharT, _Traits, _Allocator>&
2330 basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2333 for (; __first != __last; ++__first)
2334 push_back(*__first);
2338 template <class _CharT, class _Traits, class _Allocator>
2339 template<class _ForwardIterator>
2342 __is_forward_iterator<_ForwardIterator>::value,
2343 basic_string<_CharT, _Traits, _Allocator>&
2345 basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2347 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2348 size_type __cap = capacity();
2351 size_type __sz = size();
2352 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2355 __invalidate_iterators_past(__n);
2356 pointer __p = __get_pointer();
2357 for (; __first != __last; ++__first, ++__p)
2358 traits_type::assign(*__p, *__first);
2359 traits_type::assign(*__p, value_type());
2364 template <class _CharT, class _Traits, class _Allocator>
2365 inline _LIBCPP_INLINE_VISIBILITY
2366 basic_string<_CharT, _Traits, _Allocator>&
2367 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2369 return assign(__str.data(), __str.size());
2372 template <class _CharT, class _Traits, class _Allocator>
2373 basic_string<_CharT, _Traits, _Allocator>&
2374 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2376 size_type __sz = __str.size();
2378 this->__throw_out_of_range();
2379 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2382 template <class _CharT, class _Traits, class _Allocator>
2383 basic_string<_CharT, _Traits, _Allocator>&
2384 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2386 _LIBCPP_ASSERT(__s != nullptr, "string::assign recieved nullptr");
2387 return assign(__s, traits_type::length(__s));
2392 template <class _CharT, class _Traits, class _Allocator>
2393 basic_string<_CharT, _Traits, _Allocator>&
2394 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2396 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append recieved nullptr");
2397 size_type __cap = capacity();
2398 size_type __sz = size();
2399 if (__cap - __sz >= __n)
2403 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2404 traits_type::copy(__p + __sz, __s, __n);
2407 traits_type::assign(__p[__sz], value_type());
2411 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2415 template <class _CharT, class _Traits, class _Allocator>
2416 basic_string<_CharT, _Traits, _Allocator>&
2417 basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2421 size_type __cap = capacity();
2422 size_type __sz = size();
2423 if (__cap - __sz < __n)
2424 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2425 pointer __p = __get_pointer();
2426 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
2429 traits_type::assign(__p[__sz], value_type());
2434 template <class _CharT, class _Traits, class _Allocator>
2436 basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2438 bool __is_short = !__is_long();
2443 __cap = __min_cap - 1;
2444 __sz = __get_short_size();
2448 __cap = __get_long_cap() - 1;
2449 __sz = __get_long_size();
2453 __grow_by(__cap, 1, __sz, __sz, 0);
2454 __is_short = !__is_long();
2459 __p = __get_short_pointer() + __sz;
2460 __set_short_size(__sz+1);
2464 __p = __get_long_pointer() + __sz;
2465 __set_long_size(__sz+1);
2467 traits_type::assign(*__p, __c);
2468 traits_type::assign(*++__p, value_type());
2471 template <class _CharT, class _Traits, class _Allocator>
2472 template<class _InputIterator>
2475 __is_input_iterator <_InputIterator>::value &&
2476 !__is_forward_iterator<_InputIterator>::value,
2477 basic_string<_CharT, _Traits, _Allocator>&
2479 basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2481 for (; __first != __last; ++__first)
2482 push_back(*__first);
2486 template <class _CharT, class _Traits, class _Allocator>
2487 template<class _ForwardIterator>
2490 __is_forward_iterator<_ForwardIterator>::value,
2491 basic_string<_CharT, _Traits, _Allocator>&
2493 basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2495 size_type __sz = size();
2496 size_type __cap = capacity();
2497 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2500 if (__cap - __sz < __n)
2501 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2502 pointer __p = __get_pointer() + __sz;
2503 for (; __first != __last; ++__p, ++__first)
2504 traits_type::assign(*__p, *__first);
2505 traits_type::assign(*__p, value_type());
2506 __set_size(__sz + __n);
2511 template <class _CharT, class _Traits, class _Allocator>
2512 inline _LIBCPP_INLINE_VISIBILITY
2513 basic_string<_CharT, _Traits, _Allocator>&
2514 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2516 return append(__str.data(), __str.size());
2519 template <class _CharT, class _Traits, class _Allocator>
2520 basic_string<_CharT, _Traits, _Allocator>&
2521 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2523 size_type __sz = __str.size();
2525 this->__throw_out_of_range();
2526 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2529 template <class _CharT, class _Traits, class _Allocator>
2530 basic_string<_CharT, _Traits, _Allocator>&
2531 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2533 _LIBCPP_ASSERT(__s != nullptr, "string::append recieved nullptr");
2534 return append(__s, traits_type::length(__s));
2539 template <class _CharT, class _Traits, class _Allocator>
2540 basic_string<_CharT, _Traits, _Allocator>&
2541 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2543 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert recieved nullptr");
2544 size_type __sz = size();
2546 this->__throw_out_of_range();
2547 size_type __cap = capacity();
2548 if (__cap - __sz >= __n)
2552 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2553 size_type __n_move = __sz - __pos;
2556 if (__p + __pos <= __s && __s < __p + __sz)
2558 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2560 traits_type::move(__p + __pos, __s, __n);
2563 traits_type::assign(__p[__sz], value_type());
2567 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2571 template <class _CharT, class _Traits, class _Allocator>
2572 basic_string<_CharT, _Traits, _Allocator>&
2573 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2575 size_type __sz = size();
2577 this->__throw_out_of_range();
2580 size_type __cap = capacity();
2582 if (__cap - __sz >= __n)
2584 __p = _VSTD::__to_raw_pointer(__get_pointer());
2585 size_type __n_move = __sz - __pos;
2587 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2591 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2592 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2594 traits_type::assign(__p + __pos, __n, __c);
2597 traits_type::assign(__p[__sz], value_type());
2602 template <class _CharT, class _Traits, class _Allocator>
2603 template<class _InputIterator>
2606 __is_input_iterator <_InputIterator>::value &&
2607 !__is_forward_iterator<_InputIterator>::value,
2608 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2610 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2612 #if _LIBCPP_DEBUG_LEVEL >= 2
2613 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2614 "string::insert(iterator, range) called with an iterator not"
2615 " referring to this string");
2617 size_type __old_sz = size();
2618 difference_type __ip = __pos - begin();
2619 for (; __first != __last; ++__first)
2620 push_back(*__first);
2621 pointer __p = __get_pointer();
2622 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
2623 #if _LIBCPP_DEBUG_LEVEL >= 2
2624 return iterator(this, __p + __ip);
2626 return iterator(__p + __ip);
2630 template <class _CharT, class _Traits, class _Allocator>
2631 template<class _ForwardIterator>
2634 __is_forward_iterator<_ForwardIterator>::value,
2635 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2637 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2639 #if _LIBCPP_DEBUG_LEVEL >= 2
2640 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2641 "string::insert(iterator, range) called with an iterator not"
2642 " referring to this string");
2644 size_type __ip = static_cast<size_type>(__pos - begin());
2645 size_type __sz = size();
2646 size_type __cap = capacity();
2647 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2651 if (__cap - __sz >= __n)
2653 __p = _VSTD::__to_raw_pointer(__get_pointer());
2654 size_type __n_move = __sz - __ip;
2656 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2660 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2661 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2665 traits_type::assign(__p[__sz], value_type());
2666 for (__p += __ip; __first != __last; ++__p, ++__first)
2667 traits_type::assign(*__p, *__first);
2669 return begin() + __ip;
2672 template <class _CharT, class _Traits, class _Allocator>
2673 inline _LIBCPP_INLINE_VISIBILITY
2674 basic_string<_CharT, _Traits, _Allocator>&
2675 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2677 return insert(__pos1, __str.data(), __str.size());
2680 template <class _CharT, class _Traits, class _Allocator>
2681 basic_string<_CharT, _Traits, _Allocator>&
2682 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2683 size_type __pos2, size_type __n)
2685 size_type __str_sz = __str.size();
2686 if (__pos2 > __str_sz)
2687 this->__throw_out_of_range();
2688 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2691 template <class _CharT, class _Traits, class _Allocator>
2692 basic_string<_CharT, _Traits, _Allocator>&
2693 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2695 _LIBCPP_ASSERT(__s != nullptr, "string::insert recieved nullptr");
2696 return insert(__pos, __s, traits_type::length(__s));
2699 template <class _CharT, class _Traits, class _Allocator>
2700 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2701 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2703 size_type __ip = static_cast<size_type>(__pos - begin());
2704 size_type __sz = size();
2705 size_type __cap = capacity();
2709 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2710 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2714 __p = _VSTD::__to_raw_pointer(__get_pointer());
2715 size_type __n_move = __sz - __ip;
2717 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2719 traits_type::assign(__p[__ip], __c);
2720 traits_type::assign(__p[++__sz], value_type());
2722 return begin() + static_cast<difference_type>(__ip);
2725 template <class _CharT, class _Traits, class _Allocator>
2726 inline _LIBCPP_INLINE_VISIBILITY
2727 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2728 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2730 #if _LIBCPP_DEBUG_LEVEL >= 2
2731 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2732 "string::insert(iterator, n, value) called with an iterator not"
2733 " referring to this string");
2735 difference_type __p = __pos - begin();
2736 insert(static_cast<size_type>(__p), __n, __c);
2737 return begin() + __p;
2742 template <class _CharT, class _Traits, class _Allocator>
2743 basic_string<_CharT, _Traits, _Allocator>&
2744 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2746 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace recieved nullptr");
2747 size_type __sz = size();
2749 this->__throw_out_of_range();
2750 __n1 = _VSTD::min(__n1, __sz - __pos);
2751 size_type __cap = capacity();
2752 if (__cap - __sz + __n1 >= __n2)
2754 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2757 size_type __n_move = __sz - __pos - __n1;
2762 traits_type::move(__p + __pos, __s, __n2);
2763 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2766 if (__p + __pos < __s && __s < __p + __sz)
2768 if (__p + __pos + __n1 <= __s)
2770 else // __p + __pos < __s < __p + __pos + __n1
2772 traits_type::move(__p + __pos, __s, __n1);
2779 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2782 traits_type::move(__p + __pos, __s, __n2);
2784 __sz += __n2 - __n1;
2786 __invalidate_iterators_past(__sz);
2787 traits_type::assign(__p[__sz], value_type());
2790 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2794 template <class _CharT, class _Traits, class _Allocator>
2795 basic_string<_CharT, _Traits, _Allocator>&
2796 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2798 size_type __sz = size();
2800 this->__throw_out_of_range();
2801 __n1 = _VSTD::min(__n1, __sz - __pos);
2802 size_type __cap = capacity();
2804 if (__cap - __sz + __n1 >= __n2)
2806 __p = _VSTD::__to_raw_pointer(__get_pointer());
2809 size_type __n_move = __sz - __pos - __n1;
2811 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2816 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2817 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2819 traits_type::assign(__p + __pos, __n2, __c);
2820 __sz += __n2 - __n1;
2822 __invalidate_iterators_past(__sz);
2823 traits_type::assign(__p[__sz], value_type());
2827 template <class _CharT, class _Traits, class _Allocator>
2828 template<class _InputIterator>
2831 __is_input_iterator<_InputIterator>::value,
2832 basic_string<_CharT, _Traits, _Allocator>&
2834 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
2835 _InputIterator __j1, _InputIterator __j2)
2837 for (; true; ++__i1, ++__j1)
2842 insert(__i1, __j1, __j2);
2850 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
2855 template <class _CharT, class _Traits, class _Allocator>
2856 inline _LIBCPP_INLINE_VISIBILITY
2857 basic_string<_CharT, _Traits, _Allocator>&
2858 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2860 return replace(__pos1, __n1, __str.data(), __str.size());
2863 template <class _CharT, class _Traits, class _Allocator>
2864 basic_string<_CharT, _Traits, _Allocator>&
2865 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2866 size_type __pos2, size_type __n2)
2868 size_type __str_sz = __str.size();
2869 if (__pos2 > __str_sz)
2870 this->__throw_out_of_range();
2871 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2874 template <class _CharT, class _Traits, class _Allocator>
2875 basic_string<_CharT, _Traits, _Allocator>&
2876 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
2878 _LIBCPP_ASSERT(__s != nullptr, "string::replace recieved nullptr");
2879 return replace(__pos, __n1, __s, traits_type::length(__s));
2882 template <class _CharT, class _Traits, class _Allocator>
2883 inline _LIBCPP_INLINE_VISIBILITY
2884 basic_string<_CharT, _Traits, _Allocator>&
2885 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
2887 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2888 __str.data(), __str.size());
2891 template <class _CharT, class _Traits, class _Allocator>
2892 inline _LIBCPP_INLINE_VISIBILITY
2893 basic_string<_CharT, _Traits, _Allocator>&
2894 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
2896 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2899 template <class _CharT, class _Traits, class _Allocator>
2900 inline _LIBCPP_INLINE_VISIBILITY
2901 basic_string<_CharT, _Traits, _Allocator>&
2902 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
2904 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2907 template <class _CharT, class _Traits, class _Allocator>
2908 inline _LIBCPP_INLINE_VISIBILITY
2909 basic_string<_CharT, _Traits, _Allocator>&
2910 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
2912 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2917 template <class _CharT, class _Traits, class _Allocator>
2918 basic_string<_CharT, _Traits, _Allocator>&
2919 basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2921 size_type __sz = size();
2923 this->__throw_out_of_range();
2926 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2927 __n = _VSTD::min(__n, __sz - __pos);
2928 size_type __n_move = __sz - __pos - __n;
2930 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2933 __invalidate_iterators_past(__sz);
2934 traits_type::assign(__p[__sz], value_type());
2939 template <class _CharT, class _Traits, class _Allocator>
2940 inline _LIBCPP_INLINE_VISIBILITY
2941 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2942 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2944 #if _LIBCPP_DEBUG_LEVEL >= 2
2945 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2946 "string::erase(iterator) called with an iterator not"
2947 " referring to this string");
2949 _LIBCPP_ASSERT(__pos != end(),
2950 "string::erase(iterator) called with a non-dereferenceable iterator");
2951 iterator __b = begin();
2952 size_type __r = static_cast<size_type>(__pos - __b);
2954 return __b + static_cast<difference_type>(__r);
2957 template <class _CharT, class _Traits, class _Allocator>
2958 inline _LIBCPP_INLINE_VISIBILITY
2959 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2960 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2962 #if _LIBCPP_DEBUG_LEVEL >= 2
2963 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
2964 "string::erase(iterator, iterator) called with an iterator not"
2965 " referring to this string");
2967 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
2968 iterator __b = begin();
2969 size_type __r = static_cast<size_type>(__first - __b);
2970 erase(__r, static_cast<size_type>(__last - __first));
2971 return __b + static_cast<difference_type>(__r);
2974 template <class _CharT, class _Traits, class _Allocator>
2975 inline _LIBCPP_INLINE_VISIBILITY
2977 basic_string<_CharT, _Traits, _Allocator>::pop_back()
2979 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
2983 __sz = __get_long_size() - 1;
2984 __set_long_size(__sz);
2985 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2989 __sz = __get_short_size() - 1;
2990 __set_short_size(__sz);
2991 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2993 __invalidate_iterators_past(__sz);
2996 template <class _CharT, class _Traits, class _Allocator>
2997 inline _LIBCPP_INLINE_VISIBILITY
2999 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
3001 __invalidate_all_iterators();
3004 traits_type::assign(*__get_long_pointer(), value_type());
3009 traits_type::assign(*__get_short_pointer(), value_type());
3010 __set_short_size(0);
3014 template <class _CharT, class _Traits, class _Allocator>
3015 inline _LIBCPP_INLINE_VISIBILITY
3017 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3021 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3022 __set_long_size(__pos);
3026 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3027 __set_short_size(__pos);
3029 __invalidate_iterators_past(__pos);
3032 template <class _CharT, class _Traits, class _Allocator>
3034 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3036 size_type __sz = size();
3038 append(__n - __sz, __c);
3040 __erase_to_end(__n);
3043 template <class _CharT, class _Traits, class _Allocator>
3044 inline _LIBCPP_INLINE_VISIBILITY
3045 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3046 basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
3048 size_type __m = __alloc_traits::max_size(__alloc());
3049 #if _LIBCPP_BIG_ENDIAN
3050 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
3052 return __m - __alignment;
3056 template <class _CharT, class _Traits, class _Allocator>
3058 basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3060 if (__res_arg > max_size())
3061 this->__throw_length_error();
3062 size_type __cap = capacity();
3063 size_type __sz = size();
3064 __res_arg = _VSTD::max(__res_arg, __sz);
3065 __res_arg = __recommend(__res_arg);
3066 if (__res_arg != __cap)
3068 pointer __new_data, __p;
3069 bool __was_long, __now_long;
3070 if (__res_arg == __min_cap - 1)
3074 __new_data = __get_short_pointer();
3075 __p = __get_long_pointer();
3079 if (__res_arg > __cap)
3080 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3083 #ifndef _LIBCPP_NO_EXCEPTIONS
3086 #endif // _LIBCPP_NO_EXCEPTIONS
3087 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3088 #ifndef _LIBCPP_NO_EXCEPTIONS
3094 #else // _LIBCPP_NO_EXCEPTIONS
3095 if (__new_data == nullptr)
3097 #endif // _LIBCPP_NO_EXCEPTIONS
3100 __was_long = __is_long();
3101 __p = __get_pointer();
3103 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3104 _VSTD::__to_raw_pointer(__p), size()+1);
3106 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3109 __set_long_cap(__res_arg+1);
3110 __set_long_size(__sz);
3111 __set_long_pointer(__new_data);
3114 __set_short_size(__sz);
3115 __invalidate_all_iterators();
3119 template <class _CharT, class _Traits, class _Allocator>
3120 inline _LIBCPP_INLINE_VISIBILITY
3121 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3122 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3124 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3125 return *(data() + __pos);
3128 template <class _CharT, class _Traits, class _Allocator>
3129 inline _LIBCPP_INLINE_VISIBILITY
3130 typename basic_string<_CharT, _Traits, _Allocator>::reference
3131 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3133 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3134 return *(__get_pointer() + __pos);
3137 template <class _CharT, class _Traits, class _Allocator>
3138 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3139 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3142 this->__throw_out_of_range();
3143 return (*this)[__n];
3146 template <class _CharT, class _Traits, class _Allocator>
3147 typename basic_string<_CharT, _Traits, _Allocator>::reference
3148 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3151 this->__throw_out_of_range();
3152 return (*this)[__n];
3155 template <class _CharT, class _Traits, class _Allocator>
3156 inline _LIBCPP_INLINE_VISIBILITY
3157 typename basic_string<_CharT, _Traits, _Allocator>::reference
3158 basic_string<_CharT, _Traits, _Allocator>::front()
3160 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3161 return *__get_pointer();
3164 template <class _CharT, class _Traits, class _Allocator>
3165 inline _LIBCPP_INLINE_VISIBILITY
3166 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3167 basic_string<_CharT, _Traits, _Allocator>::front() const
3169 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3173 template <class _CharT, class _Traits, class _Allocator>
3174 inline _LIBCPP_INLINE_VISIBILITY
3175 typename basic_string<_CharT, _Traits, _Allocator>::reference
3176 basic_string<_CharT, _Traits, _Allocator>::back()
3178 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3179 return *(__get_pointer() + size() - 1);
3182 template <class _CharT, class _Traits, class _Allocator>
3183 inline _LIBCPP_INLINE_VISIBILITY
3184 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3185 basic_string<_CharT, _Traits, _Allocator>::back() const
3187 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3188 return *(data() + size() - 1);
3191 template <class _CharT, class _Traits, class _Allocator>
3192 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3193 basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3195 size_type __sz = size();
3197 this->__throw_out_of_range();
3198 size_type __rlen = _VSTD::min(__n, __sz - __pos);
3199 traits_type::copy(__s, data() + __pos, __rlen);
3203 template <class _CharT, class _Traits, class _Allocator>
3204 inline _LIBCPP_INLINE_VISIBILITY
3205 basic_string<_CharT, _Traits, _Allocator>
3206 basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3208 return basic_string(*this, __pos, __n, __alloc());
3211 template <class _CharT, class _Traits, class _Allocator>
3212 inline _LIBCPP_INLINE_VISIBILITY
3214 basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3215 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3216 __is_nothrow_swappable<allocator_type>::value)
3218 #if _LIBCPP_DEBUG_LEVEL >= 2
3220 __get_db()->__invalidate_all(this);
3221 if (!__str.__is_long())
3222 __get_db()->__invalidate_all(&__str);
3223 __get_db()->swap(this, &__str);
3225 _VSTD::swap(__r_.first(), __str.__r_.first());
3226 __swap_alloc(__alloc(), __str.__alloc());
3231 template <class _Traits>
3232 struct _LIBCPP_HIDDEN __traits_eq
3234 typedef typename _Traits::char_type char_type;
3235 _LIBCPP_INLINE_VISIBILITY
3236 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3237 {return _Traits::eq(__x, __y);}
3240 template<class _CharT, class _Traits, class _Allocator>
3241 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3242 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3244 size_type __n) const _NOEXCEPT
3246 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): recieved nullptr");
3247 size_type __sz = size();
3248 if (__pos > __sz || __sz - __pos < __n)
3252 const value_type* __p = data();
3253 const value_type* __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
3254 __traits_eq<traits_type>());
3255 if (__r == __p + __sz)
3257 return static_cast<size_type>(__r - __p);
3260 template<class _CharT, class _Traits, class _Allocator>
3261 inline _LIBCPP_INLINE_VISIBILITY
3262 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3263 basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3264 size_type __pos) const _NOEXCEPT
3266 return find(__str.data(), __pos, __str.size());
3269 template<class _CharT, class _Traits, class _Allocator>
3270 inline _LIBCPP_INLINE_VISIBILITY
3271 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3272 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3273 size_type __pos) const _NOEXCEPT
3275 _LIBCPP_ASSERT(__s != nullptr, "string::find(): recieved nullptr");
3276 return find(__s, __pos, traits_type::length(__s));
3279 template<class _CharT, class _Traits, class _Allocator>
3280 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3281 basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3282 size_type __pos) const _NOEXCEPT
3284 size_type __sz = size();
3287 const value_type* __p = data();
3288 const value_type* __r = traits_type::find(__p + __pos, __sz - __pos, __c);
3291 return static_cast<size_type>(__r - __p);
3296 template<class _CharT, class _Traits, class _Allocator>
3297 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3298 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3300 size_type __n) const _NOEXCEPT
3302 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): recieved nullptr");
3303 size_type __sz = size();
3304 __pos = _VSTD::min(__pos, __sz);
3305 if (__n < __sz - __pos)
3309 const value_type* __p = data();
3310 const value_type* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
3311 __traits_eq<traits_type>());
3312 if (__n > 0 && __r == __p + __pos)
3314 return static_cast<size_type>(__r - __p);
3317 template<class _CharT, class _Traits, class _Allocator>
3318 inline _LIBCPP_INLINE_VISIBILITY
3319 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3320 basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3321 size_type __pos) const _NOEXCEPT
3323 return rfind(__str.data(), __pos, __str.size());
3326 template<class _CharT, class _Traits, class _Allocator>
3327 inline _LIBCPP_INLINE_VISIBILITY
3328 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3329 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3330 size_type __pos) const _NOEXCEPT
3332 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): recieved nullptr");
3333 return rfind(__s, __pos, traits_type::length(__s));
3336 template<class _CharT, class _Traits, class _Allocator>
3337 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3338 basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3339 size_type __pos) const _NOEXCEPT
3341 size_type __sz = size();
3348 const value_type* __p = data();
3349 for (const value_type* __ps = __p + __pos; __ps != __p;)
3351 if (traits_type::eq(*--__ps, __c))
3352 return static_cast<size_type>(__ps - __p);
3360 template<class _CharT, class _Traits, class _Allocator>
3361 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3362 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3364 size_type __n) const _NOEXCEPT
3366 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): recieved nullptr");
3367 size_type __sz = size();
3368 if (__pos >= __sz || __n == 0)
3370 const value_type* __p = data();
3371 const value_type* __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
3372 __s + __n, __traits_eq<traits_type>());
3373 if (__r == __p + __sz)
3375 return static_cast<size_type>(__r - __p);
3378 template<class _CharT, class _Traits, class _Allocator>
3379 inline _LIBCPP_INLINE_VISIBILITY
3380 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3381 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3382 size_type __pos) const _NOEXCEPT
3384 return find_first_of(__str.data(), __pos, __str.size());
3387 template<class _CharT, class _Traits, class _Allocator>
3388 inline _LIBCPP_INLINE_VISIBILITY
3389 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3390 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3391 size_type __pos) const _NOEXCEPT
3393 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): recieved nullptr");
3394 return find_first_of(__s, __pos, traits_type::length(__s));
3397 template<class _CharT, class _Traits, class _Allocator>
3398 inline _LIBCPP_INLINE_VISIBILITY
3399 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3400 basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3401 size_type __pos) const _NOEXCEPT
3403 return find(__c, __pos);
3408 template<class _CharT, class _Traits, class _Allocator>
3409 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3410 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3412 size_type __n) const _NOEXCEPT
3414 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): recieved nullptr");
3417 size_type __sz = size();
3422 const value_type* __p = data();
3423 for (const value_type* __ps = __p + __pos; __ps != __p;)
3425 const value_type* __r = traits_type::find(__s, __n, *--__ps);
3427 return static_cast<size_type>(__ps - __p);
3433 template<class _CharT, class _Traits, class _Allocator>
3434 inline _LIBCPP_INLINE_VISIBILITY
3435 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3436 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3437 size_type __pos) const _NOEXCEPT
3439 return find_last_of(__str.data(), __pos, __str.size());
3442 template<class _CharT, class _Traits, class _Allocator>
3443 inline _LIBCPP_INLINE_VISIBILITY
3444 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3445 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3446 size_type __pos) const _NOEXCEPT
3448 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): recieved nullptr");
3449 return find_last_of(__s, __pos, traits_type::length(__s));
3452 template<class _CharT, class _Traits, class _Allocator>
3453 inline _LIBCPP_INLINE_VISIBILITY
3454 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3455 basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3456 size_type __pos) const _NOEXCEPT
3458 return rfind(__c, __pos);
3461 // find_first_not_of
3463 template<class _CharT, class _Traits, class _Allocator>
3464 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3465 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3467 size_type __n) const _NOEXCEPT
3469 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): recieved nullptr");
3470 size_type __sz = size();
3473 const value_type* __p = data();
3474 const value_type* __pe = __p + __sz;
3475 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
3476 if (traits_type::find(__s, __n, *__ps) == 0)
3477 return static_cast<size_type>(__ps - __p);
3482 template<class _CharT, class _Traits, class _Allocator>
3483 inline _LIBCPP_INLINE_VISIBILITY
3484 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3485 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3486 size_type __pos) const _NOEXCEPT
3488 return find_first_not_of(__str.data(), __pos, __str.size());
3491 template<class _CharT, class _Traits, class _Allocator>
3492 inline _LIBCPP_INLINE_VISIBILITY
3493 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3494 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3495 size_type __pos) const _NOEXCEPT
3497 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): recieved nullptr");
3498 return find_first_not_of(__s, __pos, traits_type::length(__s));
3501 template<class _CharT, class _Traits, class _Allocator>
3502 inline _LIBCPP_INLINE_VISIBILITY
3503 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3504 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3505 size_type __pos) const _NOEXCEPT
3507 size_type __sz = size();
3510 const value_type* __p = data();
3511 const value_type* __pe = __p + __sz;
3512 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
3513 if (!traits_type::eq(*__ps, __c))
3514 return static_cast<size_type>(__ps - __p);
3521 template<class _CharT, class _Traits, class _Allocator>
3522 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3523 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3525 size_type __n) const _NOEXCEPT
3527 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): recieved nullptr");
3528 size_type __sz = size();
3533 const value_type* __p = data();
3534 for (const value_type* __ps = __p + __pos; __ps != __p;)
3535 if (traits_type::find(__s, __n, *--__ps) == 0)
3536 return static_cast<size_type>(__ps - __p);
3540 template<class _CharT, class _Traits, class _Allocator>
3541 inline _LIBCPP_INLINE_VISIBILITY
3542 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3543 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3544 size_type __pos) const _NOEXCEPT
3546 return find_last_not_of(__str.data(), __pos, __str.size());
3549 template<class _CharT, class _Traits, class _Allocator>
3550 inline _LIBCPP_INLINE_VISIBILITY
3551 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3552 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3553 size_type __pos) const _NOEXCEPT
3555 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): recieved nullptr");
3556 return find_last_not_of(__s, __pos, traits_type::length(__s));
3559 template<class _CharT, class _Traits, class _Allocator>
3560 inline _LIBCPP_INLINE_VISIBILITY
3561 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3562 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3563 size_type __pos) const _NOEXCEPT
3565 size_type __sz = size();
3570 const value_type* __p = data();
3571 for (const value_type* __ps = __p + __pos; __ps != __p;)
3572 if (!traits_type::eq(*--__ps, __c))
3573 return static_cast<size_type>(__ps - __p);
3579 template <class _CharT, class _Traits, class _Allocator>
3580 inline _LIBCPP_INLINE_VISIBILITY
3582 basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3584 size_t __lhs_sz = size();
3585 size_t __rhs_sz = __str.size();
3586 int __result = traits_type::compare(data(), __str.data(),
3587 _VSTD::min(__lhs_sz, __rhs_sz));
3590 if (__lhs_sz < __rhs_sz)
3592 if (__lhs_sz > __rhs_sz)
3597 template <class _CharT, class _Traits, class _Allocator>
3598 inline _LIBCPP_INLINE_VISIBILITY
3600 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3602 const basic_string& __str) const
3604 return compare(__pos1, __n1, __str.data(), __str.size());
3607 template <class _CharT, class _Traits, class _Allocator>
3609 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3611 const basic_string& __str,
3613 size_type __n2) const
3615 size_type __sz = __str.size();
3617 this->__throw_out_of_range();
3618 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
3622 template <class _CharT, class _Traits, class _Allocator>
3624 basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3626 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): recieved nullptr");
3627 return compare(0, npos, __s, traits_type::length(__s));
3630 template <class _CharT, class _Traits, class _Allocator>
3632 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3634 const value_type* __s) const
3636 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): recieved nullptr");
3637 return compare(__pos1, __n1, __s, traits_type::length(__s));
3640 template <class _CharT, class _Traits, class _Allocator>
3642 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3644 const value_type* __s,
3645 size_type __n2) const
3647 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): recieved nullptr");
3648 size_type __sz = size();
3649 if (__pos1 > __sz || __n2 == npos)
3650 this->__throw_out_of_range();
3651 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3652 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
3657 else if (__rlen > __n2)
3665 template<class _CharT, class _Traits, class _Allocator>
3666 inline _LIBCPP_INLINE_VISIBILITY
3668 basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3670 if (size() > capacity())
3672 if (capacity() < __min_cap - 1)
3676 if (data()[size()] != value_type(0))
3683 template<class _CharT, class _Traits, class _Allocator>
3684 inline _LIBCPP_INLINE_VISIBILITY
3686 operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3687 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3689 size_t __lhs_sz = __lhs.size();
3690 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3695 template<class _Allocator>
3696 inline _LIBCPP_INLINE_VISIBILITY
3698 operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3699 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3701 size_t __lhs_sz = __lhs.size();
3702 if (__lhs_sz != __rhs.size())
3704 const char* __lp = __lhs.data();
3705 const char* __rp = __rhs.data();
3706 if (__lhs.__is_long())
3707 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3708 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3714 template<class _CharT, class _Traits, class _Allocator>
3715 inline _LIBCPP_INLINE_VISIBILITY
3717 operator==(const _CharT* __lhs,
3718 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3720 return __rhs.compare(__lhs) == 0;
3723 template<class _CharT, class _Traits, class _Allocator>
3724 inline _LIBCPP_INLINE_VISIBILITY
3726 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3727 const _CharT* __rhs) _NOEXCEPT
3729 return __lhs.compare(__rhs) == 0;
3734 template<class _CharT, class _Traits, class _Allocator>
3735 inline _LIBCPP_INLINE_VISIBILITY
3737 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3738 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3740 return !(__lhs == __rhs);
3743 template<class _CharT, class _Traits, class _Allocator>
3744 inline _LIBCPP_INLINE_VISIBILITY
3746 operator!=(const _CharT* __lhs,
3747 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3749 return !(__lhs == __rhs);
3752 template<class _CharT, class _Traits, class _Allocator>
3753 inline _LIBCPP_INLINE_VISIBILITY
3755 operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3756 const _CharT* __rhs) _NOEXCEPT
3758 return !(__lhs == __rhs);
3763 template<class _CharT, class _Traits, class _Allocator>
3764 inline _LIBCPP_INLINE_VISIBILITY
3766 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3767 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3769 return __lhs.compare(__rhs) < 0;
3772 template<class _CharT, class _Traits, class _Allocator>
3773 inline _LIBCPP_INLINE_VISIBILITY
3775 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3776 const _CharT* __rhs) _NOEXCEPT
3778 return __lhs.compare(__rhs) < 0;
3781 template<class _CharT, class _Traits, class _Allocator>
3782 inline _LIBCPP_INLINE_VISIBILITY
3784 operator< (const _CharT* __lhs,
3785 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3787 return __rhs.compare(__lhs) > 0;
3792 template<class _CharT, class _Traits, class _Allocator>
3793 inline _LIBCPP_INLINE_VISIBILITY
3795 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3796 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3798 return __rhs < __lhs;
3801 template<class _CharT, class _Traits, class _Allocator>
3802 inline _LIBCPP_INLINE_VISIBILITY
3804 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3805 const _CharT* __rhs) _NOEXCEPT
3807 return __rhs < __lhs;
3810 template<class _CharT, class _Traits, class _Allocator>
3811 inline _LIBCPP_INLINE_VISIBILITY
3813 operator> (const _CharT* __lhs,
3814 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3816 return __rhs < __lhs;
3821 template<class _CharT, class _Traits, class _Allocator>
3822 inline _LIBCPP_INLINE_VISIBILITY
3824 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3825 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3827 return !(__rhs < __lhs);
3830 template<class _CharT, class _Traits, class _Allocator>
3831 inline _LIBCPP_INLINE_VISIBILITY
3833 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3834 const _CharT* __rhs) _NOEXCEPT
3836 return !(__rhs < __lhs);
3839 template<class _CharT, class _Traits, class _Allocator>
3840 inline _LIBCPP_INLINE_VISIBILITY
3842 operator<=(const _CharT* __lhs,
3843 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3845 return !(__rhs < __lhs);
3850 template<class _CharT, class _Traits, class _Allocator>
3851 inline _LIBCPP_INLINE_VISIBILITY
3853 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3854 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3856 return !(__lhs < __rhs);
3859 template<class _CharT, class _Traits, class _Allocator>
3860 inline _LIBCPP_INLINE_VISIBILITY
3862 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3863 const _CharT* __rhs) _NOEXCEPT
3865 return !(__lhs < __rhs);
3868 template<class _CharT, class _Traits, class _Allocator>
3869 inline _LIBCPP_INLINE_VISIBILITY
3871 operator>=(const _CharT* __lhs,
3872 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3874 return !(__lhs < __rhs);
3879 template<class _CharT, class _Traits, class _Allocator>
3880 basic_string<_CharT, _Traits, _Allocator>
3881 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3882 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3884 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3885 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3886 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3887 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3888 __r.append(__rhs.data(), __rhs_sz);
3892 template<class _CharT, class _Traits, class _Allocator>
3893 basic_string<_CharT, _Traits, _Allocator>
3894 operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3896 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3897 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3898 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3899 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3900 __r.append(__rhs.data(), __rhs_sz);
3904 template<class _CharT, class _Traits, class _Allocator>
3905 basic_string<_CharT, _Traits, _Allocator>
3906 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3908 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3909 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3910 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3911 __r.append(__rhs.data(), __rhs_sz);
3915 template<class _CharT, class _Traits, class _Allocator>
3916 basic_string<_CharT, _Traits, _Allocator>
3917 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3919 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3920 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3921 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3922 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3923 __r.append(__rhs, __rhs_sz);
3927 template<class _CharT, class _Traits, class _Allocator>
3928 basic_string<_CharT, _Traits, _Allocator>
3929 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3931 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3932 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3933 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3934 __r.push_back(__rhs);
3938 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3940 template<class _CharT, class _Traits, class _Allocator>
3941 inline _LIBCPP_INLINE_VISIBILITY
3942 basic_string<_CharT, _Traits, _Allocator>
3943 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3945 return _VSTD::move(__lhs.append(__rhs));
3948 template<class _CharT, class _Traits, class _Allocator>
3949 inline _LIBCPP_INLINE_VISIBILITY
3950 basic_string<_CharT, _Traits, _Allocator>
3951 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3953 return _VSTD::move(__rhs.insert(0, __lhs));
3956 template<class _CharT, class _Traits, class _Allocator>
3957 inline _LIBCPP_INLINE_VISIBILITY
3958 basic_string<_CharT, _Traits, _Allocator>
3959 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3961 return _VSTD::move(__lhs.append(__rhs));
3964 template<class _CharT, class _Traits, class _Allocator>
3965 inline _LIBCPP_INLINE_VISIBILITY
3966 basic_string<_CharT, _Traits, _Allocator>
3967 operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3969 return _VSTD::move(__rhs.insert(0, __lhs));
3972 template<class _CharT, class _Traits, class _Allocator>
3973 inline _LIBCPP_INLINE_VISIBILITY
3974 basic_string<_CharT, _Traits, _Allocator>
3975 operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3977 __rhs.insert(__rhs.begin(), __lhs);
3978 return _VSTD::move(__rhs);
3981 template<class _CharT, class _Traits, class _Allocator>
3982 inline _LIBCPP_INLINE_VISIBILITY
3983 basic_string<_CharT, _Traits, _Allocator>
3984 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3986 return _VSTD::move(__lhs.append(__rhs));
3989 template<class _CharT, class _Traits, class _Allocator>
3990 inline _LIBCPP_INLINE_VISIBILITY
3991 basic_string<_CharT, _Traits, _Allocator>
3992 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3994 __lhs.push_back(__rhs);
3995 return _VSTD::move(__lhs);
3998 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4002 template<class _CharT, class _Traits, class _Allocator>
4003 inline _LIBCPP_INLINE_VISIBILITY
4005 swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
4006 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4007 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
4012 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4014 typedef basic_string<char16_t> u16string;
4015 typedef basic_string<char32_t> u32string;
4017 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
4019 _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4020 _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4021 _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4022 _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4023 _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4025 _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4026 _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4027 _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
4029 _LIBCPP_FUNC_VIS string to_string(int __val);
4030 _LIBCPP_FUNC_VIS string to_string(unsigned __val);
4031 _LIBCPP_FUNC_VIS string to_string(long __val);
4032 _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4033 _LIBCPP_FUNC_VIS string to_string(long long __val);
4034 _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4035 _LIBCPP_FUNC_VIS string to_string(float __val);
4036 _LIBCPP_FUNC_VIS string to_string(double __val);
4037 _LIBCPP_FUNC_VIS string to_string(long double __val);
4039 _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4040 _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4041 _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4042 _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4043 _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4045 _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4046 _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4047 _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
4049 _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4050 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4051 _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4052 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4053 _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4054 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4055 _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4056 _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4057 _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
4059 template<class _CharT, class _Traits, class _Allocator>
4060 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4061 basic_string<_CharT, _Traits, _Allocator>::npos;
4063 template<class _Ptr>
4064 size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
4066 typedef typename iterator_traits<_Ptr>::value_type value_type;
4067 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
4070 template<class _CharT, class _Traits, class _Allocator>
4071 struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
4072 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4075 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
4078 template<class _CharT, class _Traits, class _Allocator>
4080 hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
4081 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
4083 return __do_string_hash(__val.data(), __val.data() + __val.size());
4086 template<class _CharT, class _Traits, class _Allocator>
4087 basic_ostream<_CharT, _Traits>&
4088 operator<<(basic_ostream<_CharT, _Traits>& __os,
4089 const basic_string<_CharT, _Traits, _Allocator>& __str);
4091 template<class _CharT, class _Traits, class _Allocator>
4092 basic_istream<_CharT, _Traits>&
4093 operator>>(basic_istream<_CharT, _Traits>& __is,
4094 basic_string<_CharT, _Traits, _Allocator>& __str);
4096 template<class _CharT, class _Traits, class _Allocator>
4097 basic_istream<_CharT, _Traits>&
4098 getline(basic_istream<_CharT, _Traits>& __is,
4099 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4101 template<class _CharT, class _Traits, class _Allocator>
4102 inline _LIBCPP_INLINE_VISIBILITY
4103 basic_istream<_CharT, _Traits>&
4104 getline(basic_istream<_CharT, _Traits>& __is,
4105 basic_string<_CharT, _Traits, _Allocator>& __str);
4107 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4109 template<class _CharT, class _Traits, class _Allocator>
4110 inline _LIBCPP_INLINE_VISIBILITY
4111 basic_istream<_CharT, _Traits>&
4112 getline(basic_istream<_CharT, _Traits>&& __is,
4113 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4115 template<class _CharT, class _Traits, class _Allocator>
4116 inline _LIBCPP_INLINE_VISIBILITY
4117 basic_istream<_CharT, _Traits>&
4118 getline(basic_istream<_CharT, _Traits>&& __is,
4119 basic_string<_CharT, _Traits, _Allocator>& __str);
4121 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4123 #if _LIBCPP_DEBUG_LEVEL >= 2
4125 template<class _CharT, class _Traits, class _Allocator>
4127 basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4129 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4130 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4133 template<class _CharT, class _Traits, class _Allocator>
4135 basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4137 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4138 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4141 template<class _CharT, class _Traits, class _Allocator>
4143 basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4145 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4146 return this->data() <= __p && __p <= this->data() + this->size();
4149 template<class _CharT, class _Traits, class _Allocator>
4151 basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4153 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4154 return this->data() <= __p && __p < this->data() + this->size();
4157 #endif // _LIBCPP_DEBUG_LEVEL >= 2
4159 #if _LIBCPP_STD_VER > 11
4160 // Literal suffixes for basic_string [basic.string.literals]
4161 inline namespace literals
4163 inline namespace string_literals
4165 inline _LIBCPP_INLINE_VISIBILITY
4166 basic_string<char> operator "" s( const char *__str, size_t __len )
4168 return basic_string<char> (__str, __len);
4171 inline _LIBCPP_INLINE_VISIBILITY
4172 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4174 return basic_string<wchar_t> (__str, __len);
4177 inline _LIBCPP_INLINE_VISIBILITY
4178 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4180 return basic_string<char16_t> (__str, __len);
4183 inline _LIBCPP_INLINE_VISIBILITY
4184 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4186 return basic_string<char32_t> (__str, __len);
4192 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4193 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
4194 _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
4196 _LIBCPP_END_NAMESPACE_STD
4198 #endif // _LIBCPP_STRING