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>;
432 #include <cstdio> // For EOF.
439 #include <type_traits>
440 #include <initializer_list>
441 #include <__functional_base>
442 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
445 #if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG)
449 #include <__undef_min_max>
451 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
452 #pragma GCC system_header
455 _LIBCPP_BEGIN_NAMESPACE_STD
459 template <class _StateT>
460 class _LIBCPP_TYPE_VIS fpos
466 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
468 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
470 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
471 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
473 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
474 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
475 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
476 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
479 template <class _StateT>
480 inline _LIBCPP_INLINE_VISIBILITY
481 streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
482 {return streamoff(__x) - streamoff(__y);}
484 template <class _StateT>
485 inline _LIBCPP_INLINE_VISIBILITY
486 bool 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);}
496 template <class _CharT>
497 struct _LIBCPP_TYPE_VIS char_traits
499 typedef _CharT char_type;
500 typedef int int_type;
501 typedef streamoff off_type;
502 typedef streampos pos_type;
503 typedef mbstate_t state_type;
505 _LIBCPP_INLINE_VISIBILITY
506 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
508 _LIBCPP_INLINE_VISIBILITY
509 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
510 {return __c1 == __c2;}
511 _LIBCPP_INLINE_VISIBILITY
512 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
513 {return __c1 < __c2;}
515 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
516 static size_t length(const char_type* __s);
517 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
518 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
519 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
520 static char_type* assign(char_type* __s, size_t __n, char_type __a);
522 _LIBCPP_INLINE_VISIBILITY
523 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
524 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
525 _LIBCPP_INLINE_VISIBILITY
526 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
527 {return char_type(__c);}
528 _LIBCPP_INLINE_VISIBILITY
529 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
530 {return int_type(__c);}
531 _LIBCPP_INLINE_VISIBILITY
532 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
533 {return __c1 == __c2;}
534 _LIBCPP_INLINE_VISIBILITY
535 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
536 {return int_type(EOF);}
539 template <class _CharT>
541 char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
543 for (; __n; --__n, ++__s1, ++__s2)
545 if (lt(*__s1, *__s2))
547 if (lt(*__s2, *__s1))
553 template <class _CharT>
554 inline _LIBCPP_INLINE_VISIBILITY
556 char_traits<_CharT>::length(const char_type* __s)
559 for (; !eq(*__s, char_type(0)); ++__s)
564 template <class _CharT>
565 inline _LIBCPP_INLINE_VISIBILITY
567 char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
578 template <class _CharT>
580 char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
582 char_type* __r = __s1;
585 for (; __n; --__n, ++__s1, ++__s2)
586 assign(*__s1, *__s2);
588 else if (__s2 < __s1)
593 assign(*--__s1, *--__s2);
598 template <class _CharT>
599 inline _LIBCPP_INLINE_VISIBILITY
601 char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
603 char_type* __r = __s1;
604 for (; __n; --__n, ++__s1, ++__s2)
605 assign(*__s1, *__s2);
609 template <class _CharT>
610 inline _LIBCPP_INLINE_VISIBILITY
612 char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
614 char_type* __r = __s;
615 for (; __n; --__n, ++__s)
623 struct _LIBCPP_TYPE_VIS char_traits<char>
625 typedef char char_type;
626 typedef int int_type;
627 typedef streamoff off_type;
628 typedef streampos pos_type;
629 typedef mbstate_t state_type;
631 _LIBCPP_INLINE_VISIBILITY
632 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
634 _LIBCPP_INLINE_VISIBILITY
635 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
636 {return __c1 == __c2;}
637 _LIBCPP_INLINE_VISIBILITY
638 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
639 {return (unsigned char)__c1 < (unsigned char)__c2;}
641 _LIBCPP_INLINE_VISIBILITY
642 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
643 {return memcmp(__s1, __s2, __n);}
644 _LIBCPP_INLINE_VISIBILITY
645 static size_t length(const char_type* __s) {return strlen(__s);}
646 _LIBCPP_INLINE_VISIBILITY
647 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
648 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
649 _LIBCPP_INLINE_VISIBILITY
650 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
651 {return (char_type*)memmove(__s1, __s2, __n);}
652 _LIBCPP_INLINE_VISIBILITY
653 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
654 {return (char_type*)memcpy(__s1, __s2, __n);}
655 _LIBCPP_INLINE_VISIBILITY
656 static char_type* assign(char_type* __s, size_t __n, char_type __a)
657 {return (char_type*)memset(__s, to_int_type(__a), __n);}
659 _LIBCPP_INLINE_VISIBILITY
660 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
661 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
662 _LIBCPP_INLINE_VISIBILITY
663 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
664 {return char_type(__c);}
665 _LIBCPP_INLINE_VISIBILITY
666 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
667 {return int_type((unsigned char)__c);}
668 _LIBCPP_INLINE_VISIBILITY
669 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
670 {return __c1 == __c2;}
671 _LIBCPP_INLINE_VISIBILITY
672 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
673 {return int_type(EOF);}
676 // char_traits<wchar_t>
679 struct _LIBCPP_TYPE_VIS char_traits<wchar_t>
681 typedef wchar_t char_type;
682 typedef wint_t int_type;
683 typedef streamoff off_type;
684 typedef streampos pos_type;
685 typedef mbstate_t state_type;
687 _LIBCPP_INLINE_VISIBILITY
688 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
690 _LIBCPP_INLINE_VISIBILITY
691 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
692 {return __c1 == __c2;}
693 _LIBCPP_INLINE_VISIBILITY
694 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
695 {return __c1 < __c2;}
697 _LIBCPP_INLINE_VISIBILITY
698 static int compare(const char_type* __s1, const char_type* __s2, size_t __n)
699 {return wmemcmp(__s1, __s2, __n);}
700 _LIBCPP_INLINE_VISIBILITY
701 static size_t length(const char_type* __s)
702 {return wcslen(__s);}
703 _LIBCPP_INLINE_VISIBILITY
704 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
705 {return (const char_type*)wmemchr(__s, __a, __n);}
706 _LIBCPP_INLINE_VISIBILITY
707 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
708 {return (char_type*)wmemmove(__s1, __s2, __n);}
709 _LIBCPP_INLINE_VISIBILITY
710 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
711 {return (char_type*)wmemcpy(__s1, __s2, __n);}
712 _LIBCPP_INLINE_VISIBILITY
713 static char_type* assign(char_type* __s, size_t __n, char_type __a)
714 {return (char_type*)wmemset(__s, __a, __n);}
716 _LIBCPP_INLINE_VISIBILITY
717 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
718 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
719 _LIBCPP_INLINE_VISIBILITY
720 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
721 {return char_type(__c);}
722 _LIBCPP_INLINE_VISIBILITY
723 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
724 {return int_type(__c);}
725 _LIBCPP_INLINE_VISIBILITY
726 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
727 {return __c1 == __c2;}
728 _LIBCPP_INLINE_VISIBILITY
729 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
730 {return int_type(WEOF);}
733 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
736 struct _LIBCPP_TYPE_VIS char_traits<char16_t>
738 typedef char16_t char_type;
739 typedef uint_least16_t int_type;
740 typedef streamoff off_type;
741 typedef u16streampos pos_type;
742 typedef mbstate_t state_type;
744 _LIBCPP_INLINE_VISIBILITY
745 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
747 _LIBCPP_INLINE_VISIBILITY
748 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
749 {return __c1 == __c2;}
750 _LIBCPP_INLINE_VISIBILITY
751 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
752 {return __c1 < __c2;}
754 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
755 static size_t length(const char_type* __s);
756 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
757 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
758 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
759 static char_type* assign(char_type* __s, size_t __n, char_type __a);
761 _LIBCPP_INLINE_VISIBILITY
762 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
763 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
764 _LIBCPP_INLINE_VISIBILITY
765 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
766 {return char_type(__c);}
767 _LIBCPP_INLINE_VISIBILITY
768 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
769 {return int_type(__c);}
770 _LIBCPP_INLINE_VISIBILITY
771 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
772 {return __c1 == __c2;}
773 _LIBCPP_INLINE_VISIBILITY
774 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
775 {return int_type(0xDFFF);}
778 inline _LIBCPP_INLINE_VISIBILITY
780 char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
782 for (; __n; --__n, ++__s1, ++__s2)
784 if (lt(*__s1, *__s2))
786 if (lt(*__s2, *__s1))
792 inline _LIBCPP_INLINE_VISIBILITY
794 char_traits<char16_t>::length(const char_type* __s)
797 for (; !eq(*__s, char_type(0)); ++__s)
802 inline _LIBCPP_INLINE_VISIBILITY
804 char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
815 inline _LIBCPP_INLINE_VISIBILITY
817 char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
819 char_type* __r = __s1;
822 for (; __n; --__n, ++__s1, ++__s2)
823 assign(*__s1, *__s2);
825 else if (__s2 < __s1)
830 assign(*--__s1, *--__s2);
835 inline _LIBCPP_INLINE_VISIBILITY
837 char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
839 char_type* __r = __s1;
840 for (; __n; --__n, ++__s1, ++__s2)
841 assign(*__s1, *__s2);
845 inline _LIBCPP_INLINE_VISIBILITY
847 char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
849 char_type* __r = __s;
850 for (; __n; --__n, ++__s)
856 struct _LIBCPP_TYPE_VIS char_traits<char32_t>
858 typedef char32_t char_type;
859 typedef uint_least32_t int_type;
860 typedef streamoff off_type;
861 typedef u32streampos pos_type;
862 typedef mbstate_t state_type;
864 _LIBCPP_INLINE_VISIBILITY
865 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
867 _LIBCPP_INLINE_VISIBILITY
868 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
869 {return __c1 == __c2;}
870 _LIBCPP_INLINE_VISIBILITY
871 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
872 {return __c1 < __c2;}
874 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
875 static size_t length(const char_type* __s);
876 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
877 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
878 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
879 static char_type* assign(char_type* __s, size_t __n, char_type __a);
881 _LIBCPP_INLINE_VISIBILITY
882 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
883 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
884 _LIBCPP_INLINE_VISIBILITY
885 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
886 {return char_type(__c);}
887 _LIBCPP_INLINE_VISIBILITY
888 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
889 {return int_type(__c);}
890 _LIBCPP_INLINE_VISIBILITY
891 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
892 {return __c1 == __c2;}
893 _LIBCPP_INLINE_VISIBILITY
894 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
895 {return int_type(0xFFFFFFFF);}
898 inline _LIBCPP_INLINE_VISIBILITY
900 char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
902 for (; __n; --__n, ++__s1, ++__s2)
904 if (lt(*__s1, *__s2))
906 if (lt(*__s2, *__s1))
912 inline _LIBCPP_INLINE_VISIBILITY
914 char_traits<char32_t>::length(const char_type* __s)
917 for (; !eq(*__s, char_type(0)); ++__s)
922 inline _LIBCPP_INLINE_VISIBILITY
924 char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
935 inline _LIBCPP_INLINE_VISIBILITY
937 char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
939 char_type* __r = __s1;
942 for (; __n; --__n, ++__s1, ++__s2)
943 assign(*__s1, *__s2);
945 else if (__s2 < __s1)
950 assign(*--__s1, *--__s2);
955 inline _LIBCPP_INLINE_VISIBILITY
957 char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
959 char_type* __r = __s1;
960 for (; __n; --__n, ++__s1, ++__s2)
961 assign(*__s1, *__s2);
965 inline _LIBCPP_INLINE_VISIBILITY
967 char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
969 char_type* __r = __s;
970 for (; __n; --__n, ++__s)
975 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
979 template<class _CharT, class _Traits, class _Allocator>
980 basic_string<_CharT, _Traits, _Allocator>
981 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
982 const basic_string<_CharT, _Traits, _Allocator>& __y);
984 template<class _CharT, class _Traits, class _Allocator>
985 basic_string<_CharT, _Traits, _Allocator>
986 operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
988 template<class _CharT, class _Traits, class _Allocator>
989 basic_string<_CharT, _Traits, _Allocator>
990 operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
992 template<class _CharT, class _Traits, class _Allocator>
993 basic_string<_CharT, _Traits, _Allocator>
994 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
996 template<class _CharT, class _Traits, class _Allocator>
997 basic_string<_CharT, _Traits, _Allocator>
998 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
1001 class __basic_string_common
1004 void __throw_length_error() const;
1005 void __throw_out_of_range() const;
1010 __basic_string_common<__b>::__throw_length_error() const
1012 #ifndef _LIBCPP_NO_EXCEPTIONS
1013 throw length_error("basic_string");
1015 assert(!"basic_string length_error");
1021 __basic_string_common<__b>::__throw_out_of_range() const
1023 #ifndef _LIBCPP_NO_EXCEPTIONS
1024 throw out_of_range("basic_string");
1026 assert(!"basic_string out_of_range");
1031 #pragma warning( push )
1032 #pragma warning( disable: 4231 )
1034 _LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>)
1036 #pragma warning( pop )
1039 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1041 template <class _CharT, size_t = sizeof(_CharT)>
1044 unsigned char __xx[sizeof(_CharT)-1];
1047 template <class _CharT>
1048 struct __padding<_CharT, 1>
1052 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1054 template<class _CharT, class _Traits, class _Allocator>
1055 class _LIBCPP_TYPE_VIS basic_string
1056 : private __basic_string_common<true>
1059 typedef basic_string __self;
1060 typedef _Traits traits_type;
1061 typedef typename traits_type::char_type value_type;
1062 typedef _Allocator allocator_type;
1063 typedef allocator_traits<allocator_type> __alloc_traits;
1064 typedef typename __alloc_traits::size_type size_type;
1065 typedef typename __alloc_traits::difference_type difference_type;
1066 typedef value_type& reference;
1067 typedef const value_type& const_reference;
1068 typedef typename __alloc_traits::pointer pointer;
1069 typedef typename __alloc_traits::const_pointer const_pointer;
1070 #ifdef _LIBCPP_DEBUG
1071 typedef __debug_iter<basic_string, pointer> iterator;
1072 typedef __debug_iter<basic_string, const_pointer> const_iterator;
1074 friend class __debug_iter<basic_string, pointer>;
1075 friend class __debug_iter<basic_string, const_pointer>;
1076 #elif defined(_LIBCPP_RAW_ITERATORS)
1077 typedef pointer iterator;
1078 typedef const_pointer const_iterator;
1079 #else // defined(_LIBCPP_RAW_ITERATORS)
1080 typedef __wrap_iter<pointer> iterator;
1081 typedef __wrap_iter<const_pointer> const_iterator;
1082 #endif // defined(_LIBCPP_RAW_ITERATORS)
1083 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1084 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1088 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1097 #if _LIBCPP_BIG_ENDIAN
1098 enum {__short_mask = 0x01};
1099 enum {__long_mask = 0x1ul};
1100 #else // _LIBCPP_BIG_ENDIAN
1101 enum {__short_mask = 0x80};
1102 enum {__long_mask = ~(size_type(~0) >> 1)};
1103 #endif // _LIBCPP_BIG_ENDIAN
1105 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1106 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1110 value_type __data_[__min_cap];
1112 : __padding<value_type>
1114 unsigned char __size_;
1127 #if _LIBCPP_BIG_ENDIAN
1128 enum {__short_mask = 0x80};
1129 enum {__long_mask = ~(size_type(~0) >> 1)};
1130 #else // _LIBCPP_BIG_ENDIAN
1131 enum {__short_mask = 0x01};
1132 enum {__long_mask = 0x1ul};
1133 #endif // _LIBCPP_BIG_ENDIAN
1135 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1136 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1142 unsigned char __size_;
1145 value_type __data_[__min_cap];
1148 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1150 union __lx{__long __lx; __short __lxx;};
1152 enum {__n_words = sizeof(__lx) / sizeof(size_type)};
1156 size_type __words[__n_words];
1169 __compressed_pair<__rep, allocator_type> __r_;
1171 #ifdef _LIBCPP_DEBUG
1173 pair<iterator*, const_iterator*> __iterator_list_;
1175 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;}
1176 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;}
1178 #endif // _LIBCPP_DEBUG
1181 static const size_type npos = -1;
1183 _LIBCPP_INLINE_VISIBILITY basic_string()
1184 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
1185 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
1186 basic_string(const basic_string& __str);
1187 basic_string(const basic_string& __str, const allocator_type& __a);
1188 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1189 _LIBCPP_INLINE_VISIBILITY
1190 basic_string(basic_string&& __str)
1191 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
1192 _LIBCPP_INLINE_VISIBILITY
1193 basic_string(basic_string&& __str, const allocator_type& __a);
1194 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1195 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
1196 _LIBCPP_INLINE_VISIBILITY
1197 basic_string(const value_type* __s, const allocator_type& __a);
1198 _LIBCPP_INLINE_VISIBILITY
1199 basic_string(const value_type* __s, size_type __n);
1200 _LIBCPP_INLINE_VISIBILITY
1201 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
1202 _LIBCPP_INLINE_VISIBILITY
1203 basic_string(size_type __n, value_type __c);
1204 _LIBCPP_INLINE_VISIBILITY
1205 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1206 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1207 const allocator_type& __a = allocator_type());
1208 template<class _InputIterator>
1209 _LIBCPP_INLINE_VISIBILITY
1210 basic_string(_InputIterator __first, _InputIterator __last);
1211 template<class _InputIterator>
1212 _LIBCPP_INLINE_VISIBILITY
1213 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
1214 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1215 _LIBCPP_INLINE_VISIBILITY
1216 basic_string(initializer_list<value_type> __il);
1217 _LIBCPP_INLINE_VISIBILITY
1218 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
1219 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1223 basic_string& operator=(const basic_string& __str);
1224 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1225 _LIBCPP_INLINE_VISIBILITY
1226 basic_string& operator=(basic_string&& __str)
1227 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1228 is_nothrow_move_assignable<allocator_type>::value);
1230 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
1231 basic_string& operator=(value_type __c);
1232 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1233 _LIBCPP_INLINE_VISIBILITY
1234 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1235 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1237 #ifndef _LIBCPP_DEBUG
1238 _LIBCPP_INLINE_VISIBILITY
1239 iterator begin() _NOEXCEPT
1240 {return iterator(__get_pointer());}
1241 _LIBCPP_INLINE_VISIBILITY
1242 const_iterator begin() const _NOEXCEPT
1243 {return const_iterator(__get_pointer());}
1244 _LIBCPP_INLINE_VISIBILITY
1245 iterator end() _NOEXCEPT
1246 {return iterator(__get_pointer() + size());}
1247 _LIBCPP_INLINE_VISIBILITY
1248 const_iterator end() const _NOEXCEPT
1249 {return const_iterator(__get_pointer() + size());}
1250 #else // _LIBCPP_DEBUG
1251 _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());}
1252 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());}
1253 _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());}
1254 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());}
1255 #endif // _LIBCPP_DEBUG
1256 _LIBCPP_INLINE_VISIBILITY
1257 reverse_iterator rbegin() _NOEXCEPT
1258 {return reverse_iterator(end());}
1259 _LIBCPP_INLINE_VISIBILITY
1260 const_reverse_iterator rbegin() const _NOEXCEPT
1261 {return const_reverse_iterator(end());}
1262 _LIBCPP_INLINE_VISIBILITY
1263 reverse_iterator rend() _NOEXCEPT
1264 {return reverse_iterator(begin());}
1265 _LIBCPP_INLINE_VISIBILITY
1266 const_reverse_iterator rend() const _NOEXCEPT
1267 {return const_reverse_iterator(begin());}
1269 _LIBCPP_INLINE_VISIBILITY
1270 const_iterator cbegin() const _NOEXCEPT
1272 _LIBCPP_INLINE_VISIBILITY
1273 const_iterator cend() const _NOEXCEPT
1275 _LIBCPP_INLINE_VISIBILITY
1276 const_reverse_iterator crbegin() const _NOEXCEPT
1278 _LIBCPP_INLINE_VISIBILITY
1279 const_reverse_iterator crend() const _NOEXCEPT
1282 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
1283 {return __is_long() ? __get_long_size() : __get_short_size();}
1284 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1285 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1286 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
1287 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1289 void resize(size_type __n, value_type __c);
1290 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1292 void reserve(size_type res_arg = 0);
1293 _LIBCPP_INLINE_VISIBILITY
1294 void shrink_to_fit() _NOEXCEPT {reserve();}
1295 _LIBCPP_INLINE_VISIBILITY
1296 void clear() _NOEXCEPT;
1297 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
1299 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1300 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1302 const_reference at(size_type __n) const;
1303 reference at(size_type __n);
1305 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1306 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
1307 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1308 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1309 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1310 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1312 _LIBCPP_INLINE_VISIBILITY
1313 basic_string& append(const basic_string& __str);
1314 basic_string& append(const basic_string& __str, size_type __pos, size_type __n);
1315 basic_string& append(const value_type* __s, size_type __n);
1316 basic_string& append(const value_type* __s);
1317 basic_string& append(size_type __n, value_type __c);
1318 template<class _InputIterator>
1321 __is_input_iterator <_InputIterator>::value &&
1322 !__is_forward_iterator<_InputIterator>::value,
1325 append(_InputIterator __first, _InputIterator __last);
1326 template<class _ForwardIterator>
1329 __is_forward_iterator<_ForwardIterator>::value,
1332 append(_ForwardIterator __first, _ForwardIterator __last);
1333 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1334 _LIBCPP_INLINE_VISIBILITY
1335 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
1336 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1338 void push_back(value_type __c);
1339 _LIBCPP_INLINE_VISIBILITY
1341 _LIBCPP_INLINE_VISIBILITY reference front();
1342 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1343 _LIBCPP_INLINE_VISIBILITY reference back();
1344 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
1346 _LIBCPP_INLINE_VISIBILITY
1347 basic_string& assign(const basic_string& __str);
1348 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1349 _LIBCPP_INLINE_VISIBILITY
1350 basic_string& assign(basic_string&& str)
1351 {*this = _VSTD::move(str); return *this;}
1353 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n);
1354 basic_string& assign(const value_type* __s, size_type __n);
1355 basic_string& assign(const value_type* __s);
1356 basic_string& assign(size_type __n, value_type __c);
1357 template<class _InputIterator>
1360 __is_input_iterator <_InputIterator>::value &&
1361 !__is_forward_iterator<_InputIterator>::value,
1364 assign(_InputIterator __first, _InputIterator __last);
1365 template<class _ForwardIterator>
1368 __is_forward_iterator<_ForwardIterator>::value,
1371 assign(_ForwardIterator __first, _ForwardIterator __last);
1372 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1373 _LIBCPP_INLINE_VISIBILITY
1374 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1375 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1377 _LIBCPP_INLINE_VISIBILITY
1378 basic_string& insert(size_type __pos1, const basic_string& __str);
1379 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n);
1380 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1381 basic_string& insert(size_type __pos, const value_type* __s);
1382 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1383 iterator insert(const_iterator __pos, value_type __c);
1384 _LIBCPP_INLINE_VISIBILITY
1385 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1386 template<class _InputIterator>
1389 __is_input_iterator <_InputIterator>::value &&
1390 !__is_forward_iterator<_InputIterator>::value,
1393 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1394 template<class _ForwardIterator>
1397 __is_forward_iterator<_ForwardIterator>::value,
1400 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1401 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1402 _LIBCPP_INLINE_VISIBILITY
1403 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1404 {return insert(__pos, __il.begin(), __il.end());}
1405 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1407 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1408 _LIBCPP_INLINE_VISIBILITY
1409 iterator erase(const_iterator __pos);
1410 _LIBCPP_INLINE_VISIBILITY
1411 iterator erase(const_iterator __first, const_iterator __last);
1413 _LIBCPP_INLINE_VISIBILITY
1414 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1415 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2);
1416 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1417 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1418 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1419 _LIBCPP_INLINE_VISIBILITY
1420 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1421 _LIBCPP_INLINE_VISIBILITY
1422 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1423 _LIBCPP_INLINE_VISIBILITY
1424 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1425 _LIBCPP_INLINE_VISIBILITY
1426 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1427 template<class _InputIterator>
1430 __is_input_iterator<_InputIterator>::value,
1433 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1434 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1435 _LIBCPP_INLINE_VISIBILITY
1436 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1437 {return replace(__i1, __i2, __il.begin(), __il.end());}
1438 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1440 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1441 _LIBCPP_INLINE_VISIBILITY
1442 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1444 _LIBCPP_INLINE_VISIBILITY
1445 void swap(basic_string& __str)
1446 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1447 __is_nothrow_swappable<allocator_type>::value);
1449 _LIBCPP_INLINE_VISIBILITY
1450 const value_type* c_str() const _NOEXCEPT {return data();}
1451 _LIBCPP_INLINE_VISIBILITY
1452 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1454 _LIBCPP_INLINE_VISIBILITY
1455 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
1457 _LIBCPP_INLINE_VISIBILITY
1458 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1459 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1460 _LIBCPP_INLINE_VISIBILITY
1461 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1462 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1464 _LIBCPP_INLINE_VISIBILITY
1465 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1466 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1467 _LIBCPP_INLINE_VISIBILITY
1468 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1469 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1471 _LIBCPP_INLINE_VISIBILITY
1472 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1473 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1474 _LIBCPP_INLINE_VISIBILITY
1475 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1476 _LIBCPP_INLINE_VISIBILITY
1477 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1479 _LIBCPP_INLINE_VISIBILITY
1480 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1481 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1482 _LIBCPP_INLINE_VISIBILITY
1483 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1484 _LIBCPP_INLINE_VISIBILITY
1485 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1487 _LIBCPP_INLINE_VISIBILITY
1488 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1489 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1490 _LIBCPP_INLINE_VISIBILITY
1491 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1492 _LIBCPP_INLINE_VISIBILITY
1493 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1495 _LIBCPP_INLINE_VISIBILITY
1496 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1497 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1498 _LIBCPP_INLINE_VISIBILITY
1499 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1500 _LIBCPP_INLINE_VISIBILITY
1501 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1503 _LIBCPP_INLINE_VISIBILITY
1504 int compare(const basic_string& __str) const _NOEXCEPT;
1505 _LIBCPP_INLINE_VISIBILITY
1506 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1507 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const;
1508 int compare(const value_type* __s) const _NOEXCEPT;
1509 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1510 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1512 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1514 _LIBCPP_INLINE_VISIBILITY
1515 bool __is_long() const _NOEXCEPT
1516 {return bool(__r_.first().__s.__size_ & __short_mask);}
1519 _LIBCPP_INLINE_VISIBILITY
1520 allocator_type& __alloc() _NOEXCEPT
1521 {return __r_.second();}
1522 _LIBCPP_INLINE_VISIBILITY
1523 const allocator_type& __alloc() const _NOEXCEPT
1524 {return __r_.second();}
1526 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1528 _LIBCPP_INLINE_VISIBILITY
1529 void __set_short_size(size_type __s) _NOEXCEPT
1530 # if _LIBCPP_BIG_ENDIAN
1531 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1533 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1536 _LIBCPP_INLINE_VISIBILITY
1537 size_type __get_short_size() const _NOEXCEPT
1538 # if _LIBCPP_BIG_ENDIAN
1539 {return __r_.first().__s.__size_ >> 1;}
1541 {return __r_.first().__s.__size_;}
1544 #else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1546 _LIBCPP_INLINE_VISIBILITY
1547 void __set_short_size(size_type __s) _NOEXCEPT
1548 # if _LIBCPP_BIG_ENDIAN
1549 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1551 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1554 _LIBCPP_INLINE_VISIBILITY
1555 size_type __get_short_size() const _NOEXCEPT
1556 # if _LIBCPP_BIG_ENDIAN
1557 {return __r_.first().__s.__size_;}
1559 {return __r_.first().__s.__size_ >> 1;}
1562 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1564 _LIBCPP_INLINE_VISIBILITY
1565 void __set_long_size(size_type __s) _NOEXCEPT
1566 {__r_.first().__l.__size_ = __s;}
1567 _LIBCPP_INLINE_VISIBILITY
1568 size_type __get_long_size() const _NOEXCEPT
1569 {return __r_.first().__l.__size_;}
1570 _LIBCPP_INLINE_VISIBILITY
1571 void __set_size(size_type __s) _NOEXCEPT
1572 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1574 _LIBCPP_INLINE_VISIBILITY
1575 void __set_long_cap(size_type __s) _NOEXCEPT
1576 {__r_.first().__l.__cap_ = __long_mask | __s;}
1577 _LIBCPP_INLINE_VISIBILITY
1578 size_type __get_long_cap() const _NOEXCEPT
1579 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1581 _LIBCPP_INLINE_VISIBILITY
1582 void __set_long_pointer(pointer __p) _NOEXCEPT
1583 {__r_.first().__l.__data_ = __p;}
1584 _LIBCPP_INLINE_VISIBILITY
1585 pointer __get_long_pointer() _NOEXCEPT
1586 {return __r_.first().__l.__data_;}
1587 _LIBCPP_INLINE_VISIBILITY
1588 const_pointer __get_long_pointer() const _NOEXCEPT
1589 {return __r_.first().__l.__data_;}
1590 _LIBCPP_INLINE_VISIBILITY
1591 pointer __get_short_pointer() _NOEXCEPT
1592 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1593 _LIBCPP_INLINE_VISIBILITY
1594 const_pointer __get_short_pointer() const _NOEXCEPT
1595 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1596 _LIBCPP_INLINE_VISIBILITY
1597 pointer __get_pointer() _NOEXCEPT
1598 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1599 _LIBCPP_INLINE_VISIBILITY
1600 const_pointer __get_pointer() const _NOEXCEPT
1601 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1603 _LIBCPP_INLINE_VISIBILITY
1604 void __zero() _NOEXCEPT
1606 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1607 for (unsigned __i = 0; __i < __n_words; ++__i)
1611 template <size_type __a> static
1612 _LIBCPP_INLINE_VISIBILITY
1613 size_type __align(size_type __s) _NOEXCEPT
1614 {return __s + (__a-1) & ~(__a-1);}
1615 enum {__alignment = 16};
1616 static _LIBCPP_INLINE_VISIBILITY
1617 size_type __recommend(size_type __s) _NOEXCEPT
1618 {return (__s < __min_cap ? __min_cap :
1619 __align<sizeof(value_type) < __alignment ?
1620 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
1622 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1623 void __init(const value_type* __s, size_type __sz);
1624 void __init(size_type __n, value_type __c);
1626 template <class _InputIterator>
1629 __is_input_iterator <_InputIterator>::value &&
1630 !__is_forward_iterator<_InputIterator>::value,
1633 __init(_InputIterator __first, _InputIterator __last);
1635 template <class _ForwardIterator>
1638 __is_forward_iterator<_ForwardIterator>::value,
1641 __init(_ForwardIterator __first, _ForwardIterator __last);
1643 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1644 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1645 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1646 size_type __n_copy, size_type __n_del,
1647 size_type __n_add, const value_type* __p_new_stuff);
1649 _LIBCPP_INLINE_VISIBILITY
1650 void __erase_to_end(size_type __pos);
1652 _LIBCPP_INLINE_VISIBILITY
1653 void __copy_assign_alloc(const basic_string& __str)
1654 {__copy_assign_alloc(__str, integral_constant<bool,
1655 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1657 _LIBCPP_INLINE_VISIBILITY
1658 void __copy_assign_alloc(const basic_string& __str, true_type)
1660 if (__alloc() != __str.__alloc())
1665 __alloc() = __str.__alloc();
1668 _LIBCPP_INLINE_VISIBILITY
1669 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
1672 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1673 _LIBCPP_INLINE_VISIBILITY
1674 void __move_assign(basic_string& __str, false_type);
1675 _LIBCPP_INLINE_VISIBILITY
1676 void __move_assign(basic_string& __str, true_type)
1677 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1680 _LIBCPP_INLINE_VISIBILITY
1682 __move_assign_alloc(basic_string& __str)
1684 !__alloc_traits::propagate_on_container_move_assignment::value ||
1685 is_nothrow_move_assignable<allocator_type>::value)
1686 {__move_assign_alloc(__str, integral_constant<bool,
1687 __alloc_traits::propagate_on_container_move_assignment::value>());}
1689 _LIBCPP_INLINE_VISIBILITY
1690 void __move_assign_alloc(basic_string& __c, true_type)
1691 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1693 __alloc() = _VSTD::move(__c.__alloc());
1696 _LIBCPP_INLINE_VISIBILITY
1697 void __move_assign_alloc(basic_string&, false_type)
1701 _LIBCPP_INLINE_VISIBILITY
1702 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1703 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1704 __is_nothrow_swappable<allocator_type>::value)
1705 {__swap_alloc(__x, __y, integral_constant<bool,
1706 __alloc_traits::propagate_on_container_swap::value>());}
1708 _LIBCPP_INLINE_VISIBILITY
1709 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1710 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
1715 _LIBCPP_INLINE_VISIBILITY
1716 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
1719 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1720 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
1722 friend basic_string operator+<>(const basic_string&, const basic_string&);
1723 friend basic_string operator+<>(const value_type*, const basic_string&);
1724 friend basic_string operator+<>(value_type, const basic_string&);
1725 friend basic_string operator+<>(const basic_string&, const value_type*);
1726 friend basic_string operator+<>(const basic_string&, value_type);
1729 template <class _CharT, class _Traits, class _Allocator>
1730 #ifndef _LIBCPP_DEBUG
1731 _LIBCPP_INLINE_VISIBILITY inline
1734 basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1736 #ifdef _LIBCPP_DEBUG
1737 iterator::__remove_all(this);
1738 const_iterator::__remove_all(this);
1739 #endif // _LIBCPP_DEBUG
1742 template <class _CharT, class _Traits, class _Allocator>
1743 #ifndef _LIBCPP_DEBUG
1744 _LIBCPP_INLINE_VISIBILITY inline
1747 basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1748 #ifdef _LIBCPP_DEBUG
1753 #ifdef _LIBCPP_DEBUG
1754 const_iterator __beg = begin();
1755 if (__iterator_list_.first)
1757 for (iterator* __p = __iterator_list_.first; __p;)
1759 if (*__p - __beg > static_cast<difference_type>(__pos))
1761 iterator* __n = __p;
1763 __n->__remove_owner();
1769 if (__iterator_list_.second)
1771 for (const_iterator* __p = __iterator_list_.second; __p;)
1773 if (*__p - __beg > static_cast<difference_type>(__pos))
1775 const_iterator* __n = __p;
1777 __n->__remove_owner();
1783 #endif // _LIBCPP_DEBUG
1786 template <class _CharT, class _Traits, class _Allocator>
1787 _LIBCPP_INLINE_VISIBILITY inline
1788 basic_string<_CharT, _Traits, _Allocator>::basic_string()
1789 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1794 template <class _CharT, class _Traits, class _Allocator>
1795 _LIBCPP_INLINE_VISIBILITY inline
1796 basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1802 template <class _CharT, class _Traits, class _Allocator>
1804 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
1806 if (__reserve > max_size())
1807 this->__throw_length_error();
1809 if (__reserve < __min_cap)
1811 __set_short_size(__sz);
1812 __p = __get_short_pointer();
1816 size_type __cap = __recommend(__reserve);
1817 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1818 __set_long_pointer(__p);
1819 __set_long_cap(__cap+1);
1820 __set_long_size(__sz);
1822 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1823 traits_type::assign(__p[__sz], value_type());
1826 template <class _CharT, class _Traits, class _Allocator>
1828 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1830 if (__sz > max_size())
1831 this->__throw_length_error();
1833 if (__sz < __min_cap)
1835 __set_short_size(__sz);
1836 __p = __get_short_pointer();
1840 size_type __cap = __recommend(__sz);
1841 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1842 __set_long_pointer(__p);
1843 __set_long_cap(__cap+1);
1844 __set_long_size(__sz);
1846 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1847 traits_type::assign(__p[__sz], value_type());
1850 template <class _CharT, class _Traits, class _Allocator>
1851 _LIBCPP_INLINE_VISIBILITY inline
1852 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
1854 #ifdef _LIBCPP_DEBUG
1857 __init(__s, traits_type::length(__s));
1860 template <class _CharT, class _Traits, class _Allocator>
1861 _LIBCPP_INLINE_VISIBILITY inline
1862 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
1865 #ifdef _LIBCPP_DEBUG
1868 __init(__s, traits_type::length(__s));
1871 template <class _CharT, class _Traits, class _Allocator>
1872 _LIBCPP_INLINE_VISIBILITY inline
1873 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
1875 #ifdef _LIBCPP_DEBUG
1881 template <class _CharT, class _Traits, class _Allocator>
1882 _LIBCPP_INLINE_VISIBILITY inline
1883 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
1886 #ifdef _LIBCPP_DEBUG
1892 template <class _CharT, class _Traits, class _Allocator>
1893 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
1894 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
1896 if (!__str.__is_long())
1897 __r_.first().__r = __str.__r_.first().__r;
1899 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1902 template <class _CharT, class _Traits, class _Allocator>
1903 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
1906 if (!__str.__is_long())
1907 __r_.first().__r = __str.__r_.first().__r;
1909 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1912 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1914 template <class _CharT, class _Traits, class _Allocator>
1915 _LIBCPP_INLINE_VISIBILITY inline
1916 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
1917 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
1918 : __r_(_VSTD::move(__str.__r_))
1921 #ifdef _LIBCPP_DEBUG
1922 __str.__invalidate_all_iterators();
1926 template <class _CharT, class _Traits, class _Allocator>
1927 _LIBCPP_INLINE_VISIBILITY inline
1928 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
1931 if (__a == __str.__alloc() || !__str.__is_long())
1932 __r_.first().__r = __str.__r_.first().__r;
1934 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
1936 #ifdef _LIBCPP_DEBUG
1937 __str.__invalidate_all_iterators();
1941 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1943 template <class _CharT, class _Traits, class _Allocator>
1945 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
1947 if (__n > max_size())
1948 this->__throw_length_error();
1950 if (__n < __min_cap)
1952 __set_short_size(__n);
1953 __p = __get_short_pointer();
1957 size_type __cap = __recommend(__n);
1958 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1959 __set_long_pointer(__p);
1960 __set_long_cap(__cap+1);
1961 __set_long_size(__n);
1963 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
1964 traits_type::assign(__p[__n], value_type());
1967 template <class _CharT, class _Traits, class _Allocator>
1968 _LIBCPP_INLINE_VISIBILITY inline
1969 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
1974 template <class _CharT, class _Traits, class _Allocator>
1975 _LIBCPP_INLINE_VISIBILITY inline
1976 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
1982 template <class _CharT, class _Traits, class _Allocator>
1983 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
1984 const allocator_type& __a)
1987 size_type __str_sz = __str.size();
1988 if (__pos > __str_sz)
1989 this->__throw_out_of_range();
1990 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
1993 template <class _CharT, class _Traits, class _Allocator>
1994 template <class _InputIterator>
1997 __is_input_iterator <_InputIterator>::value &&
1998 !__is_forward_iterator<_InputIterator>::value,
2001 basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2004 #ifndef _LIBCPP_NO_EXCEPTIONS
2007 #endif // _LIBCPP_NO_EXCEPTIONS
2008 for (; __first != __last; ++__first)
2009 push_back(*__first);
2010 #ifndef _LIBCPP_NO_EXCEPTIONS
2015 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2018 #endif // _LIBCPP_NO_EXCEPTIONS
2021 template <class _CharT, class _Traits, class _Allocator>
2022 template <class _ForwardIterator>
2025 __is_forward_iterator<_ForwardIterator>::value,
2028 basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2030 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
2031 if (__sz > max_size())
2032 this->__throw_length_error();
2034 if (__sz < __min_cap)
2036 __set_short_size(__sz);
2037 __p = __get_short_pointer();
2041 size_type __cap = __recommend(__sz);
2042 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2043 __set_long_pointer(__p);
2044 __set_long_cap(__cap+1);
2045 __set_long_size(__sz);
2047 for (; __first != __last; ++__first, ++__p)
2048 traits_type::assign(*__p, *__first);
2049 traits_type::assign(*__p, value_type());
2052 template <class _CharT, class _Traits, class _Allocator>
2053 template<class _InputIterator>
2054 _LIBCPP_INLINE_VISIBILITY inline
2055 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2057 __init(__first, __last);
2060 template <class _CharT, class _Traits, class _Allocator>
2061 template<class _InputIterator>
2062 _LIBCPP_INLINE_VISIBILITY inline
2063 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2064 const allocator_type& __a)
2067 __init(__first, __last);
2070 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2072 template <class _CharT, class _Traits, class _Allocator>
2073 _LIBCPP_INLINE_VISIBILITY inline
2074 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2076 __init(__il.begin(), __il.end());
2079 template <class _CharT, class _Traits, class _Allocator>
2080 _LIBCPP_INLINE_VISIBILITY inline
2081 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2084 __init(__il.begin(), __il.end());
2087 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2089 template <class _CharT, class _Traits, class _Allocator>
2090 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2092 __invalidate_all_iterators();
2094 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2097 template <class _CharT, class _Traits, class _Allocator>
2099 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2100 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2101 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
2103 size_type __ms = max_size();
2104 if (__delta_cap > __ms - __old_cap - 1)
2105 this->__throw_length_error();
2106 pointer __old_p = __get_pointer();
2107 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2108 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2110 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2111 __invalidate_all_iterators();
2113 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2114 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2116 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
2117 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2118 if (__sec_cp_sz != 0)
2119 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2120 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2121 if (__old_cap+1 != __min_cap)
2122 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2123 __set_long_pointer(__p);
2124 __set_long_cap(__cap+1);
2125 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2126 __set_long_size(__old_sz);
2127 traits_type::assign(__p[__old_sz], value_type());
2130 template <class _CharT, class _Traits, class _Allocator>
2132 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2133 size_type __n_copy, size_type __n_del, size_type __n_add)
2135 size_type __ms = max_size();
2136 if (__delta_cap > __ms - __old_cap - 1)
2137 this->__throw_length_error();
2138 pointer __old_p = __get_pointer();
2139 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2140 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2142 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2143 __invalidate_all_iterators();
2145 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2146 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2147 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2148 if (__sec_cp_sz != 0)
2149 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2150 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2152 if (__old_cap+1 != __min_cap)
2153 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2154 __set_long_pointer(__p);
2155 __set_long_cap(__cap+1);
2160 template <class _CharT, class _Traits, class _Allocator>
2161 basic_string<_CharT, _Traits, _Allocator>&
2162 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2164 #ifdef _LIBCPP_DEBUG
2167 size_type __cap = capacity();
2170 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2171 traits_type::move(__p, __s, __n);
2172 traits_type::assign(__p[__n], value_type());
2174 __invalidate_iterators_past(__n);
2178 size_type __sz = size();
2179 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2184 template <class _CharT, class _Traits, class _Allocator>
2185 basic_string<_CharT, _Traits, _Allocator>&
2186 basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2188 size_type __cap = capacity();
2191 size_type __sz = size();
2192 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2195 __invalidate_iterators_past(__n);
2196 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2197 traits_type::assign(__p, __n, __c);
2198 traits_type::assign(__p[__n], value_type());
2203 template <class _CharT, class _Traits, class _Allocator>
2204 basic_string<_CharT, _Traits, _Allocator>&
2205 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2210 __p = __get_long_pointer();
2215 __p = __get_short_pointer();
2216 __set_short_size(1);
2218 traits_type::assign(*__p, __c);
2219 traits_type::assign(*++__p, value_type());
2220 __invalidate_iterators_past(1);
2224 template <class _CharT, class _Traits, class _Allocator>
2225 basic_string<_CharT, _Traits, _Allocator>&
2226 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2230 __copy_assign_alloc(__str);
2236 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2238 template <class _CharT, class _Traits, class _Allocator>
2239 _LIBCPP_INLINE_VISIBILITY inline
2241 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2243 if (__alloc() != __str.__alloc())
2246 __move_assign(__str, true_type());
2249 template <class _CharT, class _Traits, class _Allocator>
2250 _LIBCPP_INLINE_VISIBILITY inline
2252 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2253 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2257 __r_.first() = __str.__r_.first();
2258 __move_assign_alloc(__str);
2262 template <class _CharT, class _Traits, class _Allocator>
2263 _LIBCPP_INLINE_VISIBILITY inline
2264 basic_string<_CharT, _Traits, _Allocator>&
2265 basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2266 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2267 is_nothrow_move_assignable<allocator_type>::value)
2269 __move_assign(__str, integral_constant<bool,
2270 __alloc_traits::propagate_on_container_move_assignment::value>());
2276 template <class _CharT, class _Traits, class _Allocator>
2277 template<class _InputIterator>
2280 __is_input_iterator <_InputIterator>::value &&
2281 !__is_forward_iterator<_InputIterator>::value,
2282 basic_string<_CharT, _Traits, _Allocator>&
2284 basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2287 for (; __first != __last; ++__first)
2288 push_back(*__first);
2292 template <class _CharT, class _Traits, class _Allocator>
2293 template<class _ForwardIterator>
2296 __is_forward_iterator<_ForwardIterator>::value,
2297 basic_string<_CharT, _Traits, _Allocator>&
2299 basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2301 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2302 size_type __cap = capacity();
2305 size_type __sz = size();
2306 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2309 __invalidate_iterators_past(__n);
2310 pointer __p = __get_pointer();
2311 for (; __first != __last; ++__first, ++__p)
2312 traits_type::assign(*__p, *__first);
2313 traits_type::assign(*__p, value_type());
2318 template <class _CharT, class _Traits, class _Allocator>
2319 _LIBCPP_INLINE_VISIBILITY inline
2320 basic_string<_CharT, _Traits, _Allocator>&
2321 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2323 return assign(__str.data(), __str.size());
2326 template <class _CharT, class _Traits, class _Allocator>
2327 basic_string<_CharT, _Traits, _Allocator>&
2328 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2330 size_type __sz = __str.size();
2332 this->__throw_out_of_range();
2333 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2336 template <class _CharT, class _Traits, class _Allocator>
2337 basic_string<_CharT, _Traits, _Allocator>&
2338 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2340 #ifdef _LIBCPP_DEBUG
2343 return assign(__s, traits_type::length(__s));
2348 template <class _CharT, class _Traits, class _Allocator>
2349 basic_string<_CharT, _Traits, _Allocator>&
2350 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2352 #ifdef _LIBCPP_DEBUG
2355 size_type __cap = capacity();
2356 size_type __sz = size();
2357 if (__cap - __sz >= __n)
2361 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2362 traits_type::copy(__p + __sz, __s, __n);
2365 traits_type::assign(__p[__sz], value_type());
2369 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2373 template <class _CharT, class _Traits, class _Allocator>
2374 basic_string<_CharT, _Traits, _Allocator>&
2375 basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2379 size_type __cap = capacity();
2380 size_type __sz = size();
2381 if (__cap - __sz < __n)
2382 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2383 pointer __p = __get_pointer();
2384 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
2387 traits_type::assign(__p[__sz], value_type());
2392 template <class _CharT, class _Traits, class _Allocator>
2394 basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2396 bool __is_short = !__is_long();
2401 __cap = __min_cap - 1;
2402 __sz = __get_short_size();
2406 __cap = __get_long_cap() - 1;
2407 __sz = __get_long_size();
2411 __grow_by(__cap, 1, __sz, __sz, 0);
2412 __is_short = !__is_long();
2417 __p = __get_short_pointer() + __sz;
2418 __set_short_size(__sz+1);
2422 __p = __get_long_pointer() + __sz;
2423 __set_long_size(__sz+1);
2425 traits_type::assign(*__p, __c);
2426 traits_type::assign(*++__p, value_type());
2429 template <class _CharT, class _Traits, class _Allocator>
2430 template<class _InputIterator>
2433 __is_input_iterator <_InputIterator>::value &&
2434 !__is_forward_iterator<_InputIterator>::value,
2435 basic_string<_CharT, _Traits, _Allocator>&
2437 basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2439 for (; __first != __last; ++__first)
2440 push_back(*__first);
2444 template <class _CharT, class _Traits, class _Allocator>
2445 template<class _ForwardIterator>
2448 __is_forward_iterator<_ForwardIterator>::value,
2449 basic_string<_CharT, _Traits, _Allocator>&
2451 basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2453 size_type __sz = size();
2454 size_type __cap = capacity();
2455 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2458 if (__cap - __sz < __n)
2459 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2460 pointer __p = __get_pointer() + __sz;
2461 for (; __first != __last; ++__p, ++__first)
2462 traits_type::assign(*__p, *__first);
2463 traits_type::assign(*__p, value_type());
2464 __set_size(__sz + __n);
2469 template <class _CharT, class _Traits, class _Allocator>
2470 _LIBCPP_INLINE_VISIBILITY inline
2471 basic_string<_CharT, _Traits, _Allocator>&
2472 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2474 return append(__str.data(), __str.size());
2477 template <class _CharT, class _Traits, class _Allocator>
2478 basic_string<_CharT, _Traits, _Allocator>&
2479 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2481 size_type __sz = __str.size();
2483 this->__throw_out_of_range();
2484 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2487 template <class _CharT, class _Traits, class _Allocator>
2488 basic_string<_CharT, _Traits, _Allocator>&
2489 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2491 #ifdef _LIBCPP_DEBUG
2494 return append(__s, traits_type::length(__s));
2499 template <class _CharT, class _Traits, class _Allocator>
2500 basic_string<_CharT, _Traits, _Allocator>&
2501 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2503 #ifdef _LIBCPP_DEBUG
2506 size_type __sz = size();
2508 this->__throw_out_of_range();
2509 size_type __cap = capacity();
2510 if (__cap - __sz >= __n)
2514 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2515 size_type __n_move = __sz - __pos;
2518 if (__p + __pos <= __s && __s < __p + __sz)
2520 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2522 traits_type::move(__p + __pos, __s, __n);
2525 traits_type::assign(__p[__sz], value_type());
2529 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2533 template <class _CharT, class _Traits, class _Allocator>
2534 basic_string<_CharT, _Traits, _Allocator>&
2535 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2537 size_type __sz = size();
2539 this->__throw_out_of_range();
2542 size_type __cap = capacity();
2544 if (__cap - __sz >= __n)
2546 __p = _VSTD::__to_raw_pointer(__get_pointer());
2547 size_type __n_move = __sz - __pos;
2549 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2553 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2554 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2556 traits_type::assign(__p + __pos, __n, __c);
2559 traits_type::assign(__p[__sz], value_type());
2564 template <class _CharT, class _Traits, class _Allocator>
2565 template<class _InputIterator>
2568 __is_input_iterator <_InputIterator>::value &&
2569 !__is_forward_iterator<_InputIterator>::value,
2570 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2572 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2574 size_type __old_sz = size();
2575 difference_type __ip = __pos - begin();
2576 for (; __first != __last; ++__first)
2577 push_back(*__first);
2578 pointer __p = __get_pointer();
2579 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
2580 return iterator(__p + __ip);
2583 template <class _CharT, class _Traits, class _Allocator>
2584 template<class _ForwardIterator>
2587 __is_forward_iterator<_ForwardIterator>::value,
2588 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2590 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2592 size_type __ip = static_cast<size_type>(__pos - begin());
2593 size_type __sz = size();
2594 size_type __cap = capacity();
2595 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2599 if (__cap - __sz >= __n)
2601 __p = _VSTD::__to_raw_pointer(__get_pointer());
2602 size_type __n_move = __sz - __ip;
2604 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2608 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2609 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2613 traits_type::assign(__p[__sz], value_type());
2614 for (__p += __ip; __first != __last; ++__p, ++__first)
2615 traits_type::assign(*__p, *__first);
2617 return begin() + __ip;
2620 template <class _CharT, class _Traits, class _Allocator>
2621 _LIBCPP_INLINE_VISIBILITY inline
2622 basic_string<_CharT, _Traits, _Allocator>&
2623 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2625 return insert(__pos1, __str.data(), __str.size());
2628 template <class _CharT, class _Traits, class _Allocator>
2629 basic_string<_CharT, _Traits, _Allocator>&
2630 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2631 size_type __pos2, size_type __n)
2633 size_type __str_sz = __str.size();
2634 if (__pos2 > __str_sz)
2635 this->__throw_out_of_range();
2636 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2639 template <class _CharT, class _Traits, class _Allocator>
2640 basic_string<_CharT, _Traits, _Allocator>&
2641 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2643 #ifdef _LIBCPP_DEBUG
2646 return insert(__pos, __s, traits_type::length(__s));
2649 template <class _CharT, class _Traits, class _Allocator>
2650 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2651 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2653 size_type __ip = static_cast<size_type>(__pos - begin());
2654 size_type __sz = size();
2655 size_type __cap = capacity();
2659 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2660 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2664 __p = _VSTD::__to_raw_pointer(__get_pointer());
2665 size_type __n_move = __sz - __ip;
2667 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2669 traits_type::assign(__p[__ip], __c);
2670 traits_type::assign(__p[++__sz], value_type());
2672 return begin() + static_cast<difference_type>(__ip);
2675 template <class _CharT, class _Traits, class _Allocator>
2676 _LIBCPP_INLINE_VISIBILITY inline
2677 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2678 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2680 difference_type __p = __pos - begin();
2681 insert(static_cast<size_type>(__p), __n, __c);
2682 return begin() + __p;
2687 template <class _CharT, class _Traits, class _Allocator>
2688 basic_string<_CharT, _Traits, _Allocator>&
2689 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2691 #ifdef _LIBCPP_DEBUG
2694 size_type __sz = size();
2696 this->__throw_out_of_range();
2697 __n1 = _VSTD::min(__n1, __sz - __pos);
2698 size_type __cap = capacity();
2699 if (__cap - __sz + __n1 >= __n2)
2701 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2704 size_type __n_move = __sz - __pos - __n1;
2709 traits_type::move(__p + __pos, __s, __n2);
2710 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2713 if (__p + __pos < __s && __s < __p + __sz)
2715 if (__p + __pos + __n1 <= __s)
2717 else // __p + __pos < __s < __p + __pos + __n1
2719 traits_type::move(__p + __pos, __s, __n1);
2726 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2729 traits_type::move(__p + __pos, __s, __n2);
2731 __sz += __n2 - __n1;
2733 __invalidate_iterators_past(__sz);
2734 traits_type::assign(__p[__sz], value_type());
2737 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2741 template <class _CharT, class _Traits, class _Allocator>
2742 basic_string<_CharT, _Traits, _Allocator>&
2743 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2745 size_type __sz = size();
2747 this->__throw_out_of_range();
2748 __n1 = _VSTD::min(__n1, __sz - __pos);
2749 size_type __cap = capacity();
2751 if (__cap - __sz + __n1 >= __n2)
2753 __p = _VSTD::__to_raw_pointer(__get_pointer());
2756 size_type __n_move = __sz - __pos - __n1;
2758 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2763 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2764 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2766 traits_type::assign(__p + __pos, __n2, __c);
2767 __sz += __n2 - __n1;
2769 __invalidate_iterators_past(__sz);
2770 traits_type::assign(__p[__sz], value_type());
2774 template <class _CharT, class _Traits, class _Allocator>
2775 template<class _InputIterator>
2778 __is_input_iterator<_InputIterator>::value,
2779 basic_string<_CharT, _Traits, _Allocator>&
2781 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
2782 _InputIterator __j1, _InputIterator __j2)
2784 for (; true; ++__i1, ++__j1)
2789 insert(__i1, __j1, __j2);
2797 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
2802 template <class _CharT, class _Traits, class _Allocator>
2803 _LIBCPP_INLINE_VISIBILITY inline
2804 basic_string<_CharT, _Traits, _Allocator>&
2805 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2807 return replace(__pos1, __n1, __str.data(), __str.size());
2810 template <class _CharT, class _Traits, class _Allocator>
2811 basic_string<_CharT, _Traits, _Allocator>&
2812 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
2813 size_type __pos2, size_type __n2)
2815 size_type __str_sz = __str.size();
2816 if (__pos2 > __str_sz)
2817 this->__throw_out_of_range();
2818 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
2821 template <class _CharT, class _Traits, class _Allocator>
2822 basic_string<_CharT, _Traits, _Allocator>&
2823 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
2825 #ifdef _LIBCPP_DEBUG
2828 return replace(__pos, __n1, __s, traits_type::length(__s));
2831 template <class _CharT, class _Traits, class _Allocator>
2832 _LIBCPP_INLINE_VISIBILITY inline
2833 basic_string<_CharT, _Traits, _Allocator>&
2834 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
2836 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
2837 __str.data(), __str.size());
2840 template <class _CharT, class _Traits, class _Allocator>
2841 _LIBCPP_INLINE_VISIBILITY inline
2842 basic_string<_CharT, _Traits, _Allocator>&
2843 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
2845 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
2848 template <class _CharT, class _Traits, class _Allocator>
2849 _LIBCPP_INLINE_VISIBILITY inline
2850 basic_string<_CharT, _Traits, _Allocator>&
2851 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
2853 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
2856 template <class _CharT, class _Traits, class _Allocator>
2857 _LIBCPP_INLINE_VISIBILITY inline
2858 basic_string<_CharT, _Traits, _Allocator>&
2859 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
2861 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
2866 template <class _CharT, class _Traits, class _Allocator>
2867 basic_string<_CharT, _Traits, _Allocator>&
2868 basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
2870 size_type __sz = size();
2872 this->__throw_out_of_range();
2875 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2876 __n = _VSTD::min(__n, __sz - __pos);
2877 size_type __n_move = __sz - __pos - __n;
2879 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
2882 __invalidate_iterators_past(__sz);
2883 traits_type::assign(__p[__sz], value_type());
2888 template <class _CharT, class _Traits, class _Allocator>
2889 _LIBCPP_INLINE_VISIBILITY inline
2890 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2891 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
2893 iterator __b = begin();
2894 size_type __r = static_cast<size_type>(__pos - __b);
2896 return __b + static_cast<difference_type>(__r);
2899 template <class _CharT, class _Traits, class _Allocator>
2900 _LIBCPP_INLINE_VISIBILITY inline
2901 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2902 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
2904 iterator __b = begin();
2905 size_type __r = static_cast<size_type>(__first - __b);
2906 erase(__r, static_cast<size_type>(__last - __first));
2907 return __b + static_cast<difference_type>(__r);
2910 template <class _CharT, class _Traits, class _Allocator>
2911 _LIBCPP_INLINE_VISIBILITY inline
2913 basic_string<_CharT, _Traits, _Allocator>::pop_back()
2915 #ifdef _LIBCPP_DEBUG
2921 __sz = __get_long_size() - 1;
2922 __set_long_size(__sz);
2923 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
2927 __sz = __get_short_size() - 1;
2928 __set_short_size(__sz);
2929 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
2931 __invalidate_iterators_past(__sz);
2934 template <class _CharT, class _Traits, class _Allocator>
2935 _LIBCPP_INLINE_VISIBILITY inline
2937 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
2939 __invalidate_all_iterators();
2942 traits_type::assign(*__get_long_pointer(), value_type());
2947 traits_type::assign(*__get_short_pointer(), value_type());
2948 __set_short_size(0);
2952 template <class _CharT, class _Traits, class _Allocator>
2953 _LIBCPP_INLINE_VISIBILITY inline
2955 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
2959 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
2960 __set_long_size(__pos);
2964 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
2965 __set_short_size(__pos);
2967 __invalidate_iterators_past(__pos);
2970 template <class _CharT, class _Traits, class _Allocator>
2972 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
2974 size_type __sz = size();
2976 append(__n - __sz, __c);
2978 __erase_to_end(__n);
2981 template <class _CharT, class _Traits, class _Allocator>
2982 _LIBCPP_INLINE_VISIBILITY inline
2983 typename basic_string<_CharT, _Traits, _Allocator>::size_type
2984 basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
2986 size_type __m = __alloc_traits::max_size(__alloc());
2987 #if _LIBCPP_BIG_ENDIAN
2988 return (__m <= ~__long_mask ? __m : __m/2) - 1;
2994 template <class _CharT, class _Traits, class _Allocator>
2996 basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
2998 if (__res_arg > max_size())
2999 this->__throw_length_error();
3000 size_type __cap = capacity();
3001 size_type __sz = size();
3002 __res_arg = _VSTD::max(__res_arg, __sz);
3003 __res_arg = __recommend(__res_arg);
3004 if (__res_arg != __cap)
3006 pointer __new_data, __p;
3007 bool __was_long, __now_long;
3008 if (__res_arg == __min_cap - 1)
3012 __new_data = __get_short_pointer();
3013 __p = __get_long_pointer();
3017 if (__res_arg > __cap)
3018 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3021 #ifndef _LIBCPP_NO_EXCEPTIONS
3024 #endif // _LIBCPP_NO_EXCEPTIONS
3025 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3026 #ifndef _LIBCPP_NO_EXCEPTIONS
3032 #else // _LIBCPP_NO_EXCEPTIONS
3033 if (__new_data == nullptr)
3035 #endif // _LIBCPP_NO_EXCEPTIONS
3038 __was_long = __is_long();
3039 __p = __get_pointer();
3041 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3042 _VSTD::__to_raw_pointer(__p), size()+1);
3044 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3047 __set_long_cap(__res_arg+1);
3048 __set_long_size(__sz);
3049 __set_long_pointer(__new_data);
3052 __set_short_size(__sz);
3053 __invalidate_all_iterators();
3057 template <class _CharT, class _Traits, class _Allocator>
3058 _LIBCPP_INLINE_VISIBILITY inline
3059 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3060 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3062 #ifdef __LIBCPP_DEBUG
3063 assert(__pos <= size());
3065 return *(data() + __pos);
3068 template <class _CharT, class _Traits, class _Allocator>
3069 _LIBCPP_INLINE_VISIBILITY inline
3070 typename basic_string<_CharT, _Traits, _Allocator>::reference
3071 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3073 #ifdef __LIBCPP_DEBUG
3074 assert(__pos < size());
3076 return *(__get_pointer() + __pos);
3079 template <class _CharT, class _Traits, class _Allocator>
3080 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3081 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3084 this->__throw_out_of_range();
3085 return (*this)[__n];
3088 template <class _CharT, class _Traits, class _Allocator>
3089 typename basic_string<_CharT, _Traits, _Allocator>::reference
3090 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3093 this->__throw_out_of_range();
3094 return (*this)[__n];
3097 template <class _CharT, class _Traits, class _Allocator>
3098 _LIBCPP_INLINE_VISIBILITY inline
3099 typename basic_string<_CharT, _Traits, _Allocator>::reference
3100 basic_string<_CharT, _Traits, _Allocator>::front()
3102 #ifdef _LIBCPP_DEBUG
3105 return *__get_pointer();
3108 template <class _CharT, class _Traits, class _Allocator>
3109 _LIBCPP_INLINE_VISIBILITY inline
3110 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3111 basic_string<_CharT, _Traits, _Allocator>::front() const
3113 #ifdef _LIBCPP_DEBUG
3119 template <class _CharT, class _Traits, class _Allocator>
3120 _LIBCPP_INLINE_VISIBILITY inline
3121 typename basic_string<_CharT, _Traits, _Allocator>::reference
3122 basic_string<_CharT, _Traits, _Allocator>::back()
3124 #ifdef _LIBCPP_DEBUG
3127 return *(__get_pointer() + size() - 1);
3130 template <class _CharT, class _Traits, class _Allocator>
3131 _LIBCPP_INLINE_VISIBILITY inline
3132 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3133 basic_string<_CharT, _Traits, _Allocator>::back() const
3135 #ifdef _LIBCPP_DEBUG
3138 return *(data() + size() - 1);
3141 template <class _CharT, class _Traits, class _Allocator>
3142 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3143 basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3145 size_type __sz = size();
3147 this->__throw_out_of_range();
3148 size_type __rlen = _VSTD::min(__n, __sz - __pos);
3149 traits_type::copy(__s, data() + __pos, __rlen);
3153 template <class _CharT, class _Traits, class _Allocator>
3154 _LIBCPP_INLINE_VISIBILITY inline
3155 basic_string<_CharT, _Traits, _Allocator>
3156 basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3158 return basic_string(*this, __pos, __n, __alloc());
3161 template <class _CharT, class _Traits, class _Allocator>
3162 _LIBCPP_INLINE_VISIBILITY inline
3164 basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3165 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3166 __is_nothrow_swappable<allocator_type>::value)
3168 _VSTD::swap(__r_.first(), __str.__r_.first());
3169 __swap_alloc(__alloc(), __str.__alloc());
3170 #ifdef _LIBCPP_DEBUG
3171 __invalidate_all_iterators();
3172 __str.__invalidate_all_iterators();
3173 #endif // _LIBCPP_DEBUG
3178 template <class _Traits>
3179 struct _LIBCPP_HIDDEN __traits_eq
3181 typedef typename _Traits::char_type char_type;
3182 _LIBCPP_INLINE_VISIBILITY
3183 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3184 {return _Traits::eq(__x, __y);}
3187 template<class _CharT, class _Traits, class _Allocator>
3188 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3189 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3191 size_type __n) const _NOEXCEPT
3193 #ifdef _LIBCPP_DEBUG
3196 size_type __sz = size();
3197 if (__pos > __sz || __sz - __pos < __n)
3201 const value_type* __p = data();
3202 const value_type* __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n,
3203 __traits_eq<traits_type>());
3204 if (__r == __p + __sz)
3206 return static_cast<size_type>(__r - __p);
3209 template<class _CharT, class _Traits, class _Allocator>
3210 _LIBCPP_INLINE_VISIBILITY inline
3211 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3212 basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3213 size_type __pos) const _NOEXCEPT
3215 return find(__str.data(), __pos, __str.size());
3218 template<class _CharT, class _Traits, class _Allocator>
3219 _LIBCPP_INLINE_VISIBILITY inline
3220 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3221 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3222 size_type __pos) const _NOEXCEPT
3224 #ifdef _LIBCPP_DEBUG
3227 return find(__s, __pos, traits_type::length(__s));
3230 template<class _CharT, class _Traits, class _Allocator>
3231 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3232 basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3233 size_type __pos) const _NOEXCEPT
3235 size_type __sz = size();
3238 const value_type* __p = data();
3239 const value_type* __r = traits_type::find(__p + __pos, __sz - __pos, __c);
3242 return static_cast<size_type>(__r - __p);
3247 template<class _CharT, class _Traits, class _Allocator>
3248 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3249 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3251 size_type __n) const _NOEXCEPT
3253 #ifdef _LIBCPP_DEBUG
3256 size_type __sz = size();
3257 __pos = _VSTD::min(__pos, __sz);
3258 if (__n < __sz - __pos)
3262 const value_type* __p = data();
3263 const value_type* __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n,
3264 __traits_eq<traits_type>());
3265 if (__n > 0 && __r == __p + __pos)
3267 return static_cast<size_type>(__r - __p);
3270 template<class _CharT, class _Traits, class _Allocator>
3271 _LIBCPP_INLINE_VISIBILITY inline
3272 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3273 basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3274 size_type __pos) const _NOEXCEPT
3276 return rfind(__str.data(), __pos, __str.size());
3279 template<class _CharT, class _Traits, class _Allocator>
3280 _LIBCPP_INLINE_VISIBILITY inline
3281 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3282 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3283 size_type __pos) const _NOEXCEPT
3285 #ifdef _LIBCPP_DEBUG
3288 return rfind(__s, __pos, traits_type::length(__s));
3291 template<class _CharT, class _Traits, class _Allocator>
3292 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3293 basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3294 size_type __pos) const _NOEXCEPT
3296 size_type __sz = size();
3303 const value_type* __p = data();
3304 for (const value_type* __ps = __p + __pos; __ps != __p;)
3306 if (traits_type::eq(*--__ps, __c))
3307 return static_cast<size_type>(__ps - __p);
3315 template<class _CharT, class _Traits, class _Allocator>
3316 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3317 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3319 size_type __n) const _NOEXCEPT
3321 #ifdef _LIBCPP_DEBUG
3324 size_type __sz = size();
3325 if (__pos >= __sz || __n == 0)
3327 const value_type* __p = data();
3328 const value_type* __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s,
3329 __s + __n, __traits_eq<traits_type>());
3330 if (__r == __p + __sz)
3332 return static_cast<size_type>(__r - __p);
3335 template<class _CharT, class _Traits, class _Allocator>
3336 _LIBCPP_INLINE_VISIBILITY inline
3337 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3338 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3339 size_type __pos) const _NOEXCEPT
3341 return find_first_of(__str.data(), __pos, __str.size());
3344 template<class _CharT, class _Traits, class _Allocator>
3345 _LIBCPP_INLINE_VISIBILITY inline
3346 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3347 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3348 size_type __pos) const _NOEXCEPT
3350 #ifdef _LIBCPP_DEBUG
3353 return find_first_of(__s, __pos, traits_type::length(__s));
3356 template<class _CharT, class _Traits, class _Allocator>
3357 _LIBCPP_INLINE_VISIBILITY inline
3358 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3359 basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3360 size_type __pos) const _NOEXCEPT
3362 return find(__c, __pos);
3367 template<class _CharT, class _Traits, class _Allocator>
3368 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3369 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3371 size_type __n) const _NOEXCEPT
3373 #ifdef _LIBCPP_DEBUG
3378 size_type __sz = size();
3383 const value_type* __p = data();
3384 for (const value_type* __ps = __p + __pos; __ps != __p;)
3386 const value_type* __r = traits_type::find(__s, __n, *--__ps);
3388 return static_cast<size_type>(__ps - __p);
3394 template<class _CharT, class _Traits, class _Allocator>
3395 _LIBCPP_INLINE_VISIBILITY inline
3396 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3397 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3398 size_type __pos) const _NOEXCEPT
3400 return find_last_of(__str.data(), __pos, __str.size());
3403 template<class _CharT, class _Traits, class _Allocator>
3404 _LIBCPP_INLINE_VISIBILITY inline
3405 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3406 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3407 size_type __pos) const _NOEXCEPT
3409 #ifdef _LIBCPP_DEBUG
3412 return find_last_of(__s, __pos, traits_type::length(__s));
3415 template<class _CharT, class _Traits, class _Allocator>
3416 _LIBCPP_INLINE_VISIBILITY inline
3417 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3418 basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3419 size_type __pos) const _NOEXCEPT
3421 return rfind(__c, __pos);
3424 // find_first_not_of
3426 template<class _CharT, class _Traits, class _Allocator>
3427 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3428 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3430 size_type __n) const _NOEXCEPT
3432 #ifdef _LIBCPP_DEBUG
3435 size_type __sz = size();
3438 const value_type* __p = data();
3439 const value_type* __pe = __p + __sz;
3440 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
3441 if (traits_type::find(__s, __n, *__ps) == 0)
3442 return static_cast<size_type>(__ps - __p);
3447 template<class _CharT, class _Traits, class _Allocator>
3448 _LIBCPP_INLINE_VISIBILITY inline
3449 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3450 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3451 size_type __pos) const _NOEXCEPT
3453 return find_first_not_of(__str.data(), __pos, __str.size());
3456 template<class _CharT, class _Traits, class _Allocator>
3457 _LIBCPP_INLINE_VISIBILITY inline
3458 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3459 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3460 size_type __pos) const _NOEXCEPT
3462 #ifdef _LIBCPP_DEBUG
3465 return find_first_not_of(__s, __pos, traits_type::length(__s));
3468 template<class _CharT, class _Traits, class _Allocator>
3469 _LIBCPP_INLINE_VISIBILITY inline
3470 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3471 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3472 size_type __pos) const _NOEXCEPT
3474 size_type __sz = size();
3477 const value_type* __p = data();
3478 const value_type* __pe = __p + __sz;
3479 for (const value_type* __ps = __p + __pos; __ps != __pe; ++__ps)
3480 if (!traits_type::eq(*__ps, __c))
3481 return static_cast<size_type>(__ps - __p);
3488 template<class _CharT, class _Traits, class _Allocator>
3489 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3490 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3492 size_type __n) const _NOEXCEPT
3494 #ifdef _LIBCPP_DEBUG
3497 size_type __sz = size();
3502 const value_type* __p = data();
3503 for (const value_type* __ps = __p + __pos; __ps != __p;)
3504 if (traits_type::find(__s, __n, *--__ps) == 0)
3505 return static_cast<size_type>(__ps - __p);
3509 template<class _CharT, class _Traits, class _Allocator>
3510 _LIBCPP_INLINE_VISIBILITY inline
3511 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3512 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3513 size_type __pos) const _NOEXCEPT
3515 return find_last_not_of(__str.data(), __pos, __str.size());
3518 template<class _CharT, class _Traits, class _Allocator>
3519 _LIBCPP_INLINE_VISIBILITY inline
3520 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3521 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3522 size_type __pos) const _NOEXCEPT
3524 #ifdef _LIBCPP_DEBUG
3527 return find_last_not_of(__s, __pos, traits_type::length(__s));
3530 template<class _CharT, class _Traits, class _Allocator>
3531 _LIBCPP_INLINE_VISIBILITY inline
3532 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3533 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3534 size_type __pos) const _NOEXCEPT
3536 size_type __sz = size();
3541 const value_type* __p = data();
3542 for (const value_type* __ps = __p + __pos; __ps != __p;)
3543 if (!traits_type::eq(*--__ps, __c))
3544 return static_cast<size_type>(__ps - __p);
3550 template <class _CharT, class _Traits, class _Allocator>
3551 _LIBCPP_INLINE_VISIBILITY inline
3553 basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3555 size_t __lhs_sz = size();
3556 size_t __rhs_sz = __str.size();
3557 int __result = traits_type::compare(data(), __str.data(),
3558 _VSTD::min(__lhs_sz, __rhs_sz));
3561 if (__lhs_sz < __rhs_sz)
3563 if (__lhs_sz > __rhs_sz)
3568 template <class _CharT, class _Traits, class _Allocator>
3569 _LIBCPP_INLINE_VISIBILITY inline
3571 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3573 const basic_string& __str) const
3575 return compare(__pos1, __n1, __str.data(), __str.size());
3578 template <class _CharT, class _Traits, class _Allocator>
3580 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3582 const basic_string& __str,
3584 size_type __n2) const
3586 size_type __sz = __str.size();
3588 this->__throw_out_of_range();
3589 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
3593 template <class _CharT, class _Traits, class _Allocator>
3595 basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3597 #ifdef _LIBCPP_DEBUG
3600 return compare(0, npos, __s, traits_type::length(__s));
3603 template <class _CharT, class _Traits, class _Allocator>
3605 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3607 const value_type* __s) const
3609 #ifdef _LIBCPP_DEBUG
3612 return compare(__pos1, __n1, __s, traits_type::length(__s));
3615 template <class _CharT, class _Traits, class _Allocator>
3617 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3619 const value_type* __s,
3620 size_type __n2) const
3622 #ifdef _LIBCPP_DEBUG
3625 size_type __sz = size();
3626 if (__pos1 > __sz || __n2 == npos)
3627 this->__throw_out_of_range();
3628 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3629 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
3634 else if (__rlen > __n2)
3642 template<class _CharT, class _Traits, class _Allocator>
3643 _LIBCPP_INLINE_VISIBILITY inline
3645 basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3647 if (size() > capacity())
3649 if (capacity() < __min_cap - 1)
3653 if (data()[size()] != value_type(0))
3660 template<class _CharT, class _Traits, class _Allocator>
3661 _LIBCPP_INLINE_VISIBILITY inline
3663 operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3664 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3666 size_t __lhs_sz = __lhs.size();
3667 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3672 template<class _Allocator>
3673 _LIBCPP_INLINE_VISIBILITY inline
3675 operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3676 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3678 size_t __lhs_sz = __lhs.size();
3679 if (__lhs_sz != __rhs.size())
3681 const char* __lp = __lhs.data();
3682 const char* __rp = __rhs.data();
3683 if (__lhs.__is_long())
3684 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3685 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3691 template<class _CharT, class _Traits, class _Allocator>
3692 _LIBCPP_INLINE_VISIBILITY inline
3694 operator==(const _CharT* __lhs,
3695 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3697 return __rhs.compare(__lhs) == 0;
3700 template<class _CharT, class _Traits, class _Allocator>
3701 _LIBCPP_INLINE_VISIBILITY inline
3703 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3704 const _CharT* __rhs) _NOEXCEPT
3706 return __lhs.compare(__rhs) == 0;
3711 template<class _CharT, class _Traits, class _Allocator>
3712 _LIBCPP_INLINE_VISIBILITY inline
3714 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3715 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3717 return !(__lhs == __rhs);
3720 template<class _CharT, class _Traits, class _Allocator>
3721 _LIBCPP_INLINE_VISIBILITY inline
3723 operator!=(const _CharT* __lhs,
3724 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3726 return !(__lhs == __rhs);
3729 template<class _CharT, class _Traits, class _Allocator>
3730 _LIBCPP_INLINE_VISIBILITY inline
3732 operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3733 const _CharT* __rhs) _NOEXCEPT
3735 return !(__lhs == __rhs);
3740 template<class _CharT, class _Traits, class _Allocator>
3741 _LIBCPP_INLINE_VISIBILITY inline
3743 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3744 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3746 return __lhs.compare(__rhs) < 0;
3749 template<class _CharT, class _Traits, class _Allocator>
3750 _LIBCPP_INLINE_VISIBILITY inline
3752 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3753 const _CharT* __rhs) _NOEXCEPT
3755 return __lhs.compare(__rhs) < 0;
3758 template<class _CharT, class _Traits, class _Allocator>
3759 _LIBCPP_INLINE_VISIBILITY inline
3761 operator< (const _CharT* __lhs,
3762 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3764 return __rhs.compare(__lhs) > 0;
3769 template<class _CharT, class _Traits, class _Allocator>
3770 _LIBCPP_INLINE_VISIBILITY inline
3772 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3773 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3775 return __rhs < __lhs;
3778 template<class _CharT, class _Traits, class _Allocator>
3779 _LIBCPP_INLINE_VISIBILITY inline
3781 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3782 const _CharT* __rhs) _NOEXCEPT
3784 return __rhs < __lhs;
3787 template<class _CharT, class _Traits, class _Allocator>
3788 _LIBCPP_INLINE_VISIBILITY inline
3790 operator> (const _CharT* __lhs,
3791 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3793 return __rhs < __lhs;
3798 template<class _CharT, class _Traits, class _Allocator>
3799 _LIBCPP_INLINE_VISIBILITY inline
3801 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3802 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3804 return !(__rhs < __lhs);
3807 template<class _CharT, class _Traits, class _Allocator>
3808 _LIBCPP_INLINE_VISIBILITY inline
3810 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3811 const _CharT* __rhs) _NOEXCEPT
3813 return !(__rhs < __lhs);
3816 template<class _CharT, class _Traits, class _Allocator>
3817 _LIBCPP_INLINE_VISIBILITY inline
3819 operator<=(const _CharT* __lhs,
3820 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3822 return !(__rhs < __lhs);
3827 template<class _CharT, class _Traits, class _Allocator>
3828 _LIBCPP_INLINE_VISIBILITY inline
3830 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3831 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3833 return !(__lhs < __rhs);
3836 template<class _CharT, class _Traits, class _Allocator>
3837 _LIBCPP_INLINE_VISIBILITY inline
3839 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3840 const _CharT* __rhs) _NOEXCEPT
3842 return !(__lhs < __rhs);
3845 template<class _CharT, class _Traits, class _Allocator>
3846 _LIBCPP_INLINE_VISIBILITY inline
3848 operator>=(const _CharT* __lhs,
3849 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3851 return !(__lhs < __rhs);
3856 template<class _CharT, class _Traits, class _Allocator>
3857 basic_string<_CharT, _Traits, _Allocator>
3858 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3859 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3861 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3862 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3863 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3864 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3865 __r.append(__rhs.data(), __rhs_sz);
3869 template<class _CharT, class _Traits, class _Allocator>
3870 basic_string<_CharT, _Traits, _Allocator>
3871 operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3873 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3874 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3875 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3876 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3877 __r.append(__rhs.data(), __rhs_sz);
3881 template<class _CharT, class _Traits, class _Allocator>
3882 basic_string<_CharT, _Traits, _Allocator>
3883 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3885 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3886 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3887 __r.__init(&__lhs, 1, 1 + __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 basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3896 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3897 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3898 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3899 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3900 __r.append(__rhs, __rhs_sz);
3904 template<class _CharT, class _Traits, class _Allocator>
3905 basic_string<_CharT, _Traits, _Allocator>
3906 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3908 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3909 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3910 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3911 __r.push_back(__rhs);
3915 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3917 template<class _CharT, class _Traits, class _Allocator>
3918 _LIBCPP_INLINE_VISIBILITY inline
3919 basic_string<_CharT, _Traits, _Allocator>
3920 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3922 return _VSTD::move(__lhs.append(__rhs));
3925 template<class _CharT, class _Traits, class _Allocator>
3926 _LIBCPP_INLINE_VISIBILITY inline
3927 basic_string<_CharT, _Traits, _Allocator>
3928 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3930 return _VSTD::move(__rhs.insert(0, __lhs));
3933 template<class _CharT, class _Traits, class _Allocator>
3934 _LIBCPP_INLINE_VISIBILITY inline
3935 basic_string<_CharT, _Traits, _Allocator>
3936 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
3938 return _VSTD::move(__lhs.append(__rhs));
3941 template<class _CharT, class _Traits, class _Allocator>
3942 _LIBCPP_INLINE_VISIBILITY inline
3943 basic_string<_CharT, _Traits, _Allocator>
3944 operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3946 return _VSTD::move(__rhs.insert(0, __lhs));
3949 template<class _CharT, class _Traits, class _Allocator>
3950 _LIBCPP_INLINE_VISIBILITY inline
3951 basic_string<_CharT, _Traits, _Allocator>
3952 operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
3954 __rhs.insert(__rhs.begin(), __lhs);
3955 return _VSTD::move(__rhs);
3958 template<class _CharT, class _Traits, class _Allocator>
3959 _LIBCPP_INLINE_VISIBILITY inline
3960 basic_string<_CharT, _Traits, _Allocator>
3961 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
3963 return _VSTD::move(__lhs.append(__rhs));
3966 template<class _CharT, class _Traits, class _Allocator>
3967 _LIBCPP_INLINE_VISIBILITY inline
3968 basic_string<_CharT, _Traits, _Allocator>
3969 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
3971 __lhs.push_back(__rhs);
3972 return _VSTD::move(__lhs);
3975 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3979 template<class _CharT, class _Traits, class _Allocator>
3980 _LIBCPP_INLINE_VISIBILITY inline
3982 swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
3983 basic_string<_CharT, _Traits, _Allocator>& __rhs)
3984 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
3989 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
3991 typedef basic_string<char16_t> u16string;
3992 typedef basic_string<char32_t> u32string;
3994 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
3996 int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
3997 long stol (const string& __str, size_t* __idx = 0, int __base = 10);
3998 unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
3999 long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4000 unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4002 float stof (const string& __str, size_t* __idx = 0);
4003 double stod (const string& __str, size_t* __idx = 0);
4004 long double stold(const string& __str, size_t* __idx = 0);
4006 string to_string(int __val);
4007 string to_string(unsigned __val);
4008 string to_string(long __val);
4009 string to_string(unsigned long __val);
4010 string to_string(long long __val);
4011 string to_string(unsigned long long __val);
4012 string to_string(float __val);
4013 string to_string(double __val);
4014 string to_string(long double __val);
4016 int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4017 long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4018 unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4019 long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4020 unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4022 float stof (const wstring& __str, size_t* __idx = 0);
4023 double stod (const wstring& __str, size_t* __idx = 0);
4024 long double stold(const wstring& __str, size_t* __idx = 0);
4026 wstring to_wstring(int __val);
4027 wstring to_wstring(unsigned __val);
4028 wstring to_wstring(long __val);
4029 wstring to_wstring(unsigned long __val);
4030 wstring to_wstring(long long __val);
4031 wstring to_wstring(unsigned long long __val);
4032 wstring to_wstring(float __val);
4033 wstring to_wstring(double __val);
4034 wstring to_wstring(long double __val);
4036 template<class _CharT, class _Traits, class _Allocator>
4037 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4038 basic_string<_CharT, _Traits, _Allocator>::npos;
4040 template<class _Ptr>
4041 size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
4043 typedef typename iterator_traits<_Ptr>::value_type value_type;
4044 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
4047 template<class _CharT, class _Traits, class _Allocator>
4048 struct _LIBCPP_TYPE_VIS hash<basic_string<_CharT, _Traits, _Allocator> >
4049 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4052 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
4055 template<class _CharT, class _Traits, class _Allocator>
4057 hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
4058 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
4060 return __do_string_hash(__val.data(), __val.data() + __val.size());
4063 template<class _CharT, class _Traits, class _Allocator>
4064 basic_ostream<_CharT, _Traits>&
4065 operator<<(basic_ostream<_CharT, _Traits>& __os,
4066 const basic_string<_CharT, _Traits, _Allocator>& __str);
4068 template<class _CharT, class _Traits, class _Allocator>
4069 basic_istream<_CharT, _Traits>&
4070 operator>>(basic_istream<_CharT, _Traits>& __is,
4071 basic_string<_CharT, _Traits, _Allocator>& __str);
4073 template<class _CharT, class _Traits, class _Allocator>
4074 basic_istream<_CharT, _Traits>&
4075 getline(basic_istream<_CharT, _Traits>& __is,
4076 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4078 template<class _CharT, class _Traits, class _Allocator>
4079 inline _LIBCPP_INLINE_VISIBILITY
4080 basic_istream<_CharT, _Traits>&
4081 getline(basic_istream<_CharT, _Traits>& __is,
4082 basic_string<_CharT, _Traits, _Allocator>& __str);
4084 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4086 template<class _CharT, class _Traits, class _Allocator>
4087 inline _LIBCPP_INLINE_VISIBILITY
4088 basic_istream<_CharT, _Traits>&
4089 getline(basic_istream<_CharT, _Traits>&& __is,
4090 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4092 template<class _CharT, class _Traits, class _Allocator>
4093 inline _LIBCPP_INLINE_VISIBILITY
4094 basic_istream<_CharT, _Traits>&
4095 getline(basic_istream<_CharT, _Traits>&& __is,
4096 basic_string<_CharT, _Traits, _Allocator>& __str);
4098 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4100 _LIBCPP_EXTERN_TEMPLATE(class basic_string<char>)
4101 _LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>)
4105 operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
4107 _LIBCPP_END_NAMESPACE_STD
4109 #endif // _LIBCPP_STRING