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=npos); //C++14
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=npos); // C++14
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=npos); //C++14
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=npos); // C++14
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=npos) const; // C++14
265 int compare(const value_type* s) const noexcept;
266 int compare(size_type pos1, size_type n1, const value_type* s) const;
267 int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
269 bool __invariants() const;
272 template<class charT, class traits, class Allocator>
273 basic_string<charT, traits, Allocator>
274 operator+(const basic_string<charT, traits, Allocator>& lhs,
275 const basic_string<charT, traits, Allocator>& rhs);
277 template<class charT, class traits, class Allocator>
278 basic_string<charT, traits, Allocator>
279 operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
281 template<class charT, class traits, class Allocator>
282 basic_string<charT, traits, Allocator>
283 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
285 template<class charT, class traits, class Allocator>
286 basic_string<charT, traits, Allocator>
287 operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
289 template<class charT, class traits, class Allocator>
290 basic_string<charT, traits, Allocator>
291 operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
293 template<class charT, class traits, class Allocator>
294 bool operator==(const basic_string<charT, traits, Allocator>& lhs,
295 const basic_string<charT, traits, Allocator>& rhs) noexcept;
297 template<class charT, class traits, class Allocator>
298 bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
300 template<class charT, class traits, class Allocator>
301 bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
303 template<class charT, class traits, class Allocator>
304 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
305 const basic_string<charT, traits, Allocator>& rhs) noexcept;
307 template<class charT, class traits, class Allocator>
308 bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
310 template<class charT, class traits, class Allocator>
311 bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
313 template<class charT, class traits, class Allocator>
314 bool operator< (const basic_string<charT, traits, Allocator>& lhs,
315 const basic_string<charT, traits, Allocator>& rhs) noexcept;
317 template<class charT, class traits, class Allocator>
318 bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
320 template<class charT, class traits, class Allocator>
321 bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
323 template<class charT, class traits, class Allocator>
324 bool operator> (const basic_string<charT, traits, Allocator>& lhs,
325 const basic_string<charT, traits, Allocator>& rhs) noexcept;
327 template<class charT, class traits, class Allocator>
328 bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
330 template<class charT, class traits, class Allocator>
331 bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
333 template<class charT, class traits, class Allocator>
334 bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
335 const basic_string<charT, traits, Allocator>& rhs) noexcept;
337 template<class charT, class traits, class Allocator>
338 bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
340 template<class charT, class traits, class Allocator>
341 bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
343 template<class charT, class traits, class Allocator>
344 bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
345 const basic_string<charT, traits, Allocator>& rhs) noexcept;
347 template<class charT, class traits, class Allocator>
348 bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
350 template<class charT, class traits, class Allocator>
351 bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
353 template<class charT, class traits, class Allocator>
354 void swap(basic_string<charT, traits, Allocator>& lhs,
355 basic_string<charT, traits, Allocator>& rhs)
356 noexcept(noexcept(lhs.swap(rhs)));
358 template<class charT, class traits, class Allocator>
359 basic_istream<charT, traits>&
360 operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
362 template<class charT, class traits, class Allocator>
363 basic_ostream<charT, traits>&
364 operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
366 template<class charT, class traits, class Allocator>
367 basic_istream<charT, traits>&
368 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
371 template<class charT, class traits, class Allocator>
372 basic_istream<charT, traits>&
373 getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
375 typedef basic_string<char> string;
376 typedef basic_string<wchar_t> wstring;
377 typedef basic_string<char16_t> u16string;
378 typedef basic_string<char32_t> u32string;
380 int stoi (const string& str, size_t* idx = 0, int base = 10);
381 long stol (const string& str, size_t* idx = 0, int base = 10);
382 unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
383 long long stoll (const string& str, size_t* idx = 0, int base = 10);
384 unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
386 float stof (const string& str, size_t* idx = 0);
387 double stod (const string& str, size_t* idx = 0);
388 long double stold(const string& str, size_t* idx = 0);
390 string to_string(int val);
391 string to_string(unsigned val);
392 string to_string(long val);
393 string to_string(unsigned long val);
394 string to_string(long long val);
395 string to_string(unsigned long long val);
396 string to_string(float val);
397 string to_string(double val);
398 string to_string(long double val);
400 int stoi (const wstring& str, size_t* idx = 0, int base = 10);
401 long stol (const wstring& str, size_t* idx = 0, int base = 10);
402 unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
403 long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
404 unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
406 float stof (const wstring& str, size_t* idx = 0);
407 double stod (const wstring& str, size_t* idx = 0);
408 long double stold(const wstring& str, size_t* idx = 0);
410 wstring to_wstring(int val);
411 wstring to_wstring(unsigned val);
412 wstring to_wstring(long val);
413 wstring to_wstring(unsigned long val);
414 wstring to_wstring(long long val);
415 wstring to_wstring(unsigned long long val);
416 wstring to_wstring(float val);
417 wstring to_wstring(double val);
418 wstring to_wstring(long double val);
420 template <> struct hash<string>;
421 template <> struct hash<u16string>;
422 template <> struct hash<u32string>;
423 template <> struct hash<wstring>;
425 basic_string<char> operator "" s( const char *str, size_t len ); // C++14
426 basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
427 basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
428 basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
437 #include <cstdio> // For EOF.
444 #include <type_traits>
445 #include <initializer_list>
446 #include <__functional_base>
447 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
450 #if defined(_LIBCPP_NO_EXCEPTIONS)
454 #include <__undef_min_max>
458 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
459 #pragma GCC system_header
462 _LIBCPP_BEGIN_NAMESPACE_STD
466 template <class _StateT>
467 class _LIBCPP_TYPE_VIS_ONLY fpos
473 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
475 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
477 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
478 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
480 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
481 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
482 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
483 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
486 template <class _StateT>
487 inline _LIBCPP_INLINE_VISIBILITY
488 streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
489 {return streamoff(__x) - streamoff(__y);}
491 template <class _StateT>
492 inline _LIBCPP_INLINE_VISIBILITY
493 bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
494 {return streamoff(__x) == streamoff(__y);}
496 template <class _StateT>
497 inline _LIBCPP_INLINE_VISIBILITY
498 bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
499 {return streamoff(__x) != streamoff(__y);}
503 template <class _CharT>
504 struct _LIBCPP_TYPE_VIS_ONLY char_traits
506 typedef _CharT char_type;
507 typedef int int_type;
508 typedef streamoff off_type;
509 typedef streampos pos_type;
510 typedef mbstate_t state_type;
512 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
514 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
515 {return __c1 == __c2;}
516 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
517 {return __c1 < __c2;}
519 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
520 static size_t length(const char_type* __s);
521 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
522 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
523 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
524 static char_type* assign(char_type* __s, size_t __n, char_type __a);
526 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
527 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
528 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
529 {return char_type(__c);}
530 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
531 {return int_type(__c);}
532 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
533 {return __c1 == __c2;}
534 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
535 {return int_type(EOF);}
538 template <class _CharT>
540 char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
542 for (; __n; --__n, ++__s1, ++__s2)
544 if (lt(*__s1, *__s2))
546 if (lt(*__s2, *__s1))
552 template <class _CharT>
553 inline _LIBCPP_INLINE_VISIBILITY
555 char_traits<_CharT>::length(const char_type* __s)
558 for (; !eq(*__s, char_type(0)); ++__s)
563 template <class _CharT>
564 inline _LIBCPP_INLINE_VISIBILITY
566 char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
577 template <class _CharT>
579 char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
581 char_type* __r = __s1;
584 for (; __n; --__n, ++__s1, ++__s2)
585 assign(*__s1, *__s2);
587 else if (__s2 < __s1)
592 assign(*--__s1, *--__s2);
597 template <class _CharT>
598 inline _LIBCPP_INLINE_VISIBILITY
600 char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
602 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
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_ONLY 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 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
633 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
634 {return __c1 == __c2;}
635 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
636 {return (unsigned char)__c1 < (unsigned char)__c2;}
638 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
639 {return memcmp(__s1, __s2, __n);}
640 static inline size_t length(const char_type* __s) {return strlen(__s);}
641 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
642 {return (const char_type*)memchr(__s, to_int_type(__a), __n);}
643 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
644 {return (char_type*)memmove(__s1, __s2, __n);}
645 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
647 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
648 return (char_type*)memcpy(__s1, __s2, __n);
650 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
651 {return (char_type*)memset(__s, to_int_type(__a), __n);}
653 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
654 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
655 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
656 {return char_type(__c);}
657 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
658 {return int_type((unsigned char)__c);}
659 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
660 {return __c1 == __c2;}
661 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
662 {return int_type(EOF);}
665 // char_traits<wchar_t>
668 struct _LIBCPP_TYPE_VIS_ONLY char_traits<wchar_t>
670 typedef wchar_t char_type;
671 typedef wint_t int_type;
672 typedef streamoff off_type;
673 typedef streampos pos_type;
674 typedef mbstate_t state_type;
676 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
678 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
679 {return __c1 == __c2;}
680 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
681 {return __c1 < __c2;}
683 static inline int compare(const char_type* __s1, const char_type* __s2, size_t __n)
684 {return wmemcmp(__s1, __s2, __n);}
685 static inline size_t length(const char_type* __s)
686 {return wcslen(__s);}
687 static inline const char_type* find(const char_type* __s, size_t __n, const char_type& __a)
688 {return (const char_type*)wmemchr(__s, __a, __n);}
689 static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n)
690 {return (char_type*)wmemmove(__s1, __s2, __n);}
691 static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n)
693 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
694 return (char_type*)wmemcpy(__s1, __s2, __n);
696 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
697 {return (char_type*)wmemset(__s, __a, __n);}
699 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
700 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
701 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
702 {return char_type(__c);}
703 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
704 {return int_type(__c);}
705 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
706 {return __c1 == __c2;}
707 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
708 {return int_type(WEOF);}
711 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
714 struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t>
716 typedef char16_t char_type;
717 typedef uint_least16_t int_type;
718 typedef streamoff off_type;
719 typedef u16streampos pos_type;
720 typedef mbstate_t state_type;
722 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
724 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
725 {return __c1 == __c2;}
726 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
727 {return __c1 < __c2;}
729 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
730 static size_t length(const char_type* __s);
731 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
732 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
733 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
734 static char_type* assign(char_type* __s, size_t __n, char_type __a);
736 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
737 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
738 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
739 {return char_type(__c);}
740 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
741 {return int_type(__c);}
742 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
743 {return __c1 == __c2;}
744 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
745 {return int_type(0xDFFF);}
748 inline _LIBCPP_INLINE_VISIBILITY
750 char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
752 for (; __n; --__n, ++__s1, ++__s2)
754 if (lt(*__s1, *__s2))
756 if (lt(*__s2, *__s1))
762 inline _LIBCPP_INLINE_VISIBILITY
764 char_traits<char16_t>::length(const char_type* __s)
767 for (; !eq(*__s, char_type(0)); ++__s)
772 inline _LIBCPP_INLINE_VISIBILITY
774 char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a)
785 inline _LIBCPP_INLINE_VISIBILITY
787 char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
789 char_type* __r = __s1;
792 for (; __n; --__n, ++__s1, ++__s2)
793 assign(*__s1, *__s2);
795 else if (__s2 < __s1)
800 assign(*--__s1, *--__s2);
805 inline _LIBCPP_INLINE_VISIBILITY
807 char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
809 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
810 char_type* __r = __s1;
811 for (; __n; --__n, ++__s1, ++__s2)
812 assign(*__s1, *__s2);
816 inline _LIBCPP_INLINE_VISIBILITY
818 char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a)
820 char_type* __r = __s;
821 for (; __n; --__n, ++__s)
827 struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t>
829 typedef char32_t char_type;
830 typedef uint_least32_t int_type;
831 typedef streamoff off_type;
832 typedef u32streampos pos_type;
833 typedef mbstate_t state_type;
835 static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT
837 static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
838 {return __c1 == __c2;}
839 static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
840 {return __c1 < __c2;}
842 static int compare(const char_type* __s1, const char_type* __s2, size_t __n);
843 static size_t length(const char_type* __s);
844 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
845 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
846 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
847 static char_type* assign(char_type* __s, size_t __n, char_type __a);
849 static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
850 {return eq_int_type(__c, eof()) ? ~eof() : __c;}
851 static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
852 {return char_type(__c);}
853 static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
854 {return int_type(__c);}
855 static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
856 {return __c1 == __c2;}
857 static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
858 {return int_type(0xFFFFFFFF);}
861 inline _LIBCPP_INLINE_VISIBILITY
863 char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
865 for (; __n; --__n, ++__s1, ++__s2)
867 if (lt(*__s1, *__s2))
869 if (lt(*__s2, *__s1))
875 inline _LIBCPP_INLINE_VISIBILITY
877 char_traits<char32_t>::length(const char_type* __s)
880 for (; !eq(*__s, char_type(0)); ++__s)
885 inline _LIBCPP_INLINE_VISIBILITY
887 char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a)
898 inline _LIBCPP_INLINE_VISIBILITY
900 char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n)
902 char_type* __r = __s1;
905 for (; __n; --__n, ++__s1, ++__s2)
906 assign(*__s1, *__s2);
908 else if (__s2 < __s1)
913 assign(*--__s1, *--__s2);
918 inline _LIBCPP_INLINE_VISIBILITY
920 char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n)
922 _LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
923 char_type* __r = __s1;
924 for (; __n; --__n, ++__s1, ++__s2)
925 assign(*__s1, *__s2);
929 inline _LIBCPP_INLINE_VISIBILITY
931 char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
933 char_type* __r = __s;
934 for (; __n; --__n, ++__s)
939 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
941 // helper fns for basic_string
944 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
945 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
946 __str_find(const _CharT *__p, _SizeT __sz,
947 _CharT __c, _SizeT __pos) _NOEXCEPT
951 const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
954 return static_cast<_SizeT>(__r - __p);
957 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
958 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
959 __str_find(const _CharT *__p, _SizeT __sz,
960 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
962 if (__pos > __sz || __sz - __pos < __n)
967 _VSTD::__search(__p + __pos, __p + __sz,
968 __s, __s + __n, _Traits::eq,
969 random_access_iterator_tag(), random_access_iterator_tag());
970 if (__r == __p + __sz)
972 return static_cast<_SizeT>(__r - __p);
978 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
979 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
980 __str_rfind(const _CharT *__p, _SizeT __sz,
981 _CharT __c, _SizeT __pos) _NOEXCEPT
989 for (const _CharT* __ps = __p + __pos; __ps != __p;)
991 if (_Traits::eq(*--__ps, __c))
992 return static_cast<_SizeT>(__ps - __p);
997 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
998 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
999 __str_rfind(const _CharT *__p, _SizeT __sz,
1000 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1002 __pos = _VSTD::min(__pos, __sz);
1003 if (__n < __sz - __pos)
1007 const _CharT* __r = _VSTD::__find_end(
1008 __p, __p + __pos, __s, __s + __n, _Traits::eq,
1009 random_access_iterator_tag(), random_access_iterator_tag());
1010 if (__n > 0 && __r == __p + __pos)
1012 return static_cast<_SizeT>(__r - __p);
1015 // __str_find_first_of
1016 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1017 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1018 __str_find_first_of(const _CharT *__p, _SizeT __sz,
1019 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1021 if (__pos >= __sz || __n == 0)
1023 const _CharT* __r = _VSTD::__find_first_of_ce
1024 (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
1025 if (__r == __p + __sz)
1027 return static_cast<_SizeT>(__r - __p);
1031 // __str_find_last_of
1032 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1033 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1034 __str_find_last_of(const _CharT *__p, _SizeT __sz,
1035 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1043 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1045 const _CharT* __r = _Traits::find(__s, __n, *--__ps);
1047 return static_cast<_SizeT>(__ps - __p);
1054 // __str_find_first_not_of
1055 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1056 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1057 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
1058 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1062 const _CharT* __pe = __p + __sz;
1063 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1064 if (_Traits::find(__s, __n, *__ps) == 0)
1065 return static_cast<_SizeT>(__ps - __p);
1071 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1072 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1073 __str_find_first_not_of(const _CharT *__p, _SizeT __sz,
1074 _CharT __c, _SizeT __pos) _NOEXCEPT
1078 const _CharT* __pe = __p + __sz;
1079 for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
1080 if (!_Traits::eq(*__ps, __c))
1081 return static_cast<_SizeT>(__ps - __p);
1087 // __str_find_last_not_of
1088 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1089 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1090 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
1091 const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1097 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1098 if (_Traits::find(__s, __n, *--__ps) == 0)
1099 return static_cast<_SizeT>(__ps - __p);
1104 template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
1105 _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1106 __str_find_last_not_of(const _CharT *__p, _SizeT __sz,
1107 _CharT __c, _SizeT __pos) _NOEXCEPT
1113 for (const _CharT* __ps = __p + __pos; __ps != __p;)
1114 if (!_Traits::eq(*--__ps, __c))
1115 return static_cast<_SizeT>(__ps - __p);
1119 template<class _Ptr>
1120 size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
1122 typedef typename iterator_traits<_Ptr>::value_type value_type;
1123 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
1128 template<class _CharT, class _Traits, class _Allocator>
1129 basic_string<_CharT, _Traits, _Allocator>
1130 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
1131 const basic_string<_CharT, _Traits, _Allocator>& __y);
1133 template<class _CharT, class _Traits, class _Allocator>
1134 basic_string<_CharT, _Traits, _Allocator>
1135 operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
1137 template<class _CharT, class _Traits, class _Allocator>
1138 basic_string<_CharT, _Traits, _Allocator>
1139 operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
1141 template<class _CharT, class _Traits, class _Allocator>
1142 basic_string<_CharT, _Traits, _Allocator>
1143 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
1145 template<class _CharT, class _Traits, class _Allocator>
1146 basic_string<_CharT, _Traits, _Allocator>
1147 operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
1150 class _LIBCPP_TYPE_VIS_ONLY __basic_string_common
1153 void __throw_length_error() const;
1154 void __throw_out_of_range() const;
1159 __basic_string_common<__b>::__throw_length_error() const
1161 #ifndef _LIBCPP_NO_EXCEPTIONS
1162 throw length_error("basic_string");
1164 assert(!"basic_string length_error");
1170 __basic_string_common<__b>::__throw_out_of_range() const
1172 #ifndef _LIBCPP_NO_EXCEPTIONS
1173 throw out_of_range("basic_string");
1175 assert(!"basic_string out_of_range");
1180 #pragma warning( push )
1181 #pragma warning( disable: 4231 )
1182 #endif // _LIBCPP_MSVC
1183 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>)
1185 #pragma warning( pop )
1186 #endif // _LIBCPP_MSVC
1188 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1190 template <class _CharT, size_t = sizeof(_CharT)>
1193 unsigned char __xx[sizeof(_CharT)-1];
1196 template <class _CharT>
1197 struct __padding<_CharT, 1>
1201 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1203 template<class _CharT, class _Traits, class _Allocator>
1204 class _LIBCPP_TYPE_VIS_ONLY basic_string
1205 : private __basic_string_common<true>
1208 typedef basic_string __self;
1209 typedef _Traits traits_type;
1210 typedef typename traits_type::char_type value_type;
1211 typedef _Allocator allocator_type;
1212 typedef allocator_traits<allocator_type> __alloc_traits;
1213 typedef typename __alloc_traits::size_type size_type;
1214 typedef typename __alloc_traits::difference_type difference_type;
1215 typedef value_type& reference;
1216 typedef const value_type& const_reference;
1217 typedef typename __alloc_traits::pointer pointer;
1218 typedef typename __alloc_traits::const_pointer const_pointer;
1220 static_assert(is_pod<value_type>::value, "Character type of basic_string must be a POD");
1221 static_assert((is_same<_CharT, value_type>::value),
1222 "traits_type::char_type must be the same type as CharT");
1223 static_assert((is_same<typename allocator_type::value_type, value_type>::value),
1224 "Allocator::value_type must be same type as value_type");
1225 #if defined(_LIBCPP_RAW_ITERATORS)
1226 typedef pointer iterator;
1227 typedef const_pointer const_iterator;
1228 #else // defined(_LIBCPP_RAW_ITERATORS)
1229 typedef __wrap_iter<pointer> iterator;
1230 typedef __wrap_iter<const_pointer> const_iterator;
1231 #endif // defined(_LIBCPP_RAW_ITERATORS)
1232 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
1233 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
1237 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1246 #if _LIBCPP_BIG_ENDIAN
1247 enum {__short_mask = 0x01};
1248 enum {__long_mask = 0x1ul};
1249 #else // _LIBCPP_BIG_ENDIAN
1250 enum {__short_mask = 0x80};
1251 enum {__long_mask = ~(size_type(~0) >> 1)};
1252 #endif // _LIBCPP_BIG_ENDIAN
1254 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1255 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1259 value_type __data_[__min_cap];
1261 : __padding<value_type>
1263 unsigned char __size_;
1276 #if _LIBCPP_BIG_ENDIAN
1277 enum {__short_mask = 0x80};
1278 enum {__long_mask = ~(size_type(~0) >> 1)};
1279 #else // _LIBCPP_BIG_ENDIAN
1280 enum {__short_mask = 0x01};
1281 enum {__long_mask = 0x1ul};
1282 #endif // _LIBCPP_BIG_ENDIAN
1284 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
1285 (sizeof(__long) - 1)/sizeof(value_type) : 2};
1291 unsigned char __size_;
1294 value_type __data_[__min_cap];
1297 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1299 union __ulx{__long __lx; __short __lxx;};
1301 enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
1305 size_type __words[__n_words];
1318 __compressed_pair<__rep, allocator_type> __r_;
1321 static const size_type npos = -1;
1323 _LIBCPP_INLINE_VISIBILITY basic_string()
1324 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
1325 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a);
1326 basic_string(const basic_string& __str);
1327 basic_string(const basic_string& __str, const allocator_type& __a);
1328 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1329 _LIBCPP_INLINE_VISIBILITY
1330 basic_string(basic_string&& __str)
1331 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
1332 _LIBCPP_INLINE_VISIBILITY
1333 basic_string(basic_string&& __str, const allocator_type& __a);
1334 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1335 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
1336 _LIBCPP_INLINE_VISIBILITY
1337 basic_string(const value_type* __s, const allocator_type& __a);
1338 _LIBCPP_INLINE_VISIBILITY
1339 basic_string(const value_type* __s, size_type __n);
1340 _LIBCPP_INLINE_VISIBILITY
1341 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
1342 _LIBCPP_INLINE_VISIBILITY
1343 basic_string(size_type __n, value_type __c);
1344 _LIBCPP_INLINE_VISIBILITY
1345 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1346 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1347 const allocator_type& __a = allocator_type());
1348 template<class _InputIterator>
1349 _LIBCPP_INLINE_VISIBILITY
1350 basic_string(_InputIterator __first, _InputIterator __last);
1351 template<class _InputIterator>
1352 _LIBCPP_INLINE_VISIBILITY
1353 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
1354 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1355 _LIBCPP_INLINE_VISIBILITY
1356 basic_string(initializer_list<value_type> __il);
1357 _LIBCPP_INLINE_VISIBILITY
1358 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
1359 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1363 basic_string& operator=(const basic_string& __str);
1364 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1365 _LIBCPP_INLINE_VISIBILITY
1366 basic_string& operator=(basic_string&& __str)
1367 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1368 is_nothrow_move_assignable<allocator_type>::value);
1370 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
1371 basic_string& operator=(value_type __c);
1372 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1373 _LIBCPP_INLINE_VISIBILITY
1374 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1375 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1377 #if _LIBCPP_DEBUG_LEVEL >= 2
1378 _LIBCPP_INLINE_VISIBILITY
1379 iterator begin() _NOEXCEPT
1380 {return iterator(this, __get_pointer());}
1381 _LIBCPP_INLINE_VISIBILITY
1382 const_iterator begin() const _NOEXCEPT
1383 {return const_iterator(this, __get_pointer());}
1384 _LIBCPP_INLINE_VISIBILITY
1385 iterator end() _NOEXCEPT
1386 {return iterator(this, __get_pointer() + size());}
1387 _LIBCPP_INLINE_VISIBILITY
1388 const_iterator end() const _NOEXCEPT
1389 {return const_iterator(this, __get_pointer() + size());}
1391 _LIBCPP_INLINE_VISIBILITY
1392 iterator begin() _NOEXCEPT
1393 {return iterator(__get_pointer());}
1394 _LIBCPP_INLINE_VISIBILITY
1395 const_iterator begin() const _NOEXCEPT
1396 {return const_iterator(__get_pointer());}
1397 _LIBCPP_INLINE_VISIBILITY
1398 iterator end() _NOEXCEPT
1399 {return iterator(__get_pointer() + size());}
1400 _LIBCPP_INLINE_VISIBILITY
1401 const_iterator end() const _NOEXCEPT
1402 {return const_iterator(__get_pointer() + size());}
1403 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1404 _LIBCPP_INLINE_VISIBILITY
1405 reverse_iterator rbegin() _NOEXCEPT
1406 {return reverse_iterator(end());}
1407 _LIBCPP_INLINE_VISIBILITY
1408 const_reverse_iterator rbegin() const _NOEXCEPT
1409 {return const_reverse_iterator(end());}
1410 _LIBCPP_INLINE_VISIBILITY
1411 reverse_iterator rend() _NOEXCEPT
1412 {return reverse_iterator(begin());}
1413 _LIBCPP_INLINE_VISIBILITY
1414 const_reverse_iterator rend() const _NOEXCEPT
1415 {return const_reverse_iterator(begin());}
1417 _LIBCPP_INLINE_VISIBILITY
1418 const_iterator cbegin() const _NOEXCEPT
1420 _LIBCPP_INLINE_VISIBILITY
1421 const_iterator cend() const _NOEXCEPT
1423 _LIBCPP_INLINE_VISIBILITY
1424 const_reverse_iterator crbegin() const _NOEXCEPT
1426 _LIBCPP_INLINE_VISIBILITY
1427 const_reverse_iterator crend() const _NOEXCEPT
1430 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
1431 {return __is_long() ? __get_long_size() : __get_short_size();}
1432 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1433 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1434 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
1435 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;}
1437 void resize(size_type __n, value_type __c);
1438 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1440 void reserve(size_type res_arg = 0);
1441 _LIBCPP_INLINE_VISIBILITY
1442 void shrink_to_fit() _NOEXCEPT {reserve();}
1443 _LIBCPP_INLINE_VISIBILITY
1444 void clear() _NOEXCEPT;
1445 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
1447 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1448 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1450 const_reference at(size_type __n) const;
1451 reference at(size_type __n);
1453 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1454 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
1455 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1456 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1457 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1458 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1460 _LIBCPP_INLINE_VISIBILITY
1461 basic_string& append(const basic_string& __str);
1462 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
1463 basic_string& append(const value_type* __s, size_type __n);
1464 basic_string& append(const value_type* __s);
1465 basic_string& append(size_type __n, value_type __c);
1466 template<class _InputIterator>
1469 __is_input_iterator <_InputIterator>::value &&
1470 !__is_forward_iterator<_InputIterator>::value,
1473 append(_InputIterator __first, _InputIterator __last);
1474 template<class _ForwardIterator>
1477 __is_forward_iterator<_ForwardIterator>::value,
1480 append(_ForwardIterator __first, _ForwardIterator __last);
1481 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1482 _LIBCPP_INLINE_VISIBILITY
1483 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
1484 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1486 void push_back(value_type __c);
1487 _LIBCPP_INLINE_VISIBILITY
1489 _LIBCPP_INLINE_VISIBILITY reference front();
1490 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1491 _LIBCPP_INLINE_VISIBILITY reference back();
1492 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
1494 _LIBCPP_INLINE_VISIBILITY
1495 basic_string& assign(const basic_string& __str);
1496 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1497 _LIBCPP_INLINE_VISIBILITY
1498 basic_string& assign(basic_string&& str)
1499 {*this = _VSTD::move(str); return *this;}
1501 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
1502 basic_string& assign(const value_type* __s, size_type __n);
1503 basic_string& assign(const value_type* __s);
1504 basic_string& assign(size_type __n, value_type __c);
1505 template<class _InputIterator>
1508 __is_input_iterator <_InputIterator>::value &&
1509 !__is_forward_iterator<_InputIterator>::value,
1512 assign(_InputIterator __first, _InputIterator __last);
1513 template<class _ForwardIterator>
1516 __is_forward_iterator<_ForwardIterator>::value,
1519 assign(_ForwardIterator __first, _ForwardIterator __last);
1520 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1521 _LIBCPP_INLINE_VISIBILITY
1522 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1523 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1525 _LIBCPP_INLINE_VISIBILITY
1526 basic_string& insert(size_type __pos1, const basic_string& __str);
1527 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
1528 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1529 basic_string& insert(size_type __pos, const value_type* __s);
1530 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1531 iterator insert(const_iterator __pos, value_type __c);
1532 _LIBCPP_INLINE_VISIBILITY
1533 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1534 template<class _InputIterator>
1537 __is_input_iterator <_InputIterator>::value &&
1538 !__is_forward_iterator<_InputIterator>::value,
1541 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1542 template<class _ForwardIterator>
1545 __is_forward_iterator<_ForwardIterator>::value,
1548 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1549 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1550 _LIBCPP_INLINE_VISIBILITY
1551 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1552 {return insert(__pos, __il.begin(), __il.end());}
1553 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1555 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1556 _LIBCPP_INLINE_VISIBILITY
1557 iterator erase(const_iterator __pos);
1558 _LIBCPP_INLINE_VISIBILITY
1559 iterator erase(const_iterator __first, const_iterator __last);
1561 _LIBCPP_INLINE_VISIBILITY
1562 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1563 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
1564 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1565 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1566 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1567 _LIBCPP_INLINE_VISIBILITY
1568 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1569 _LIBCPP_INLINE_VISIBILITY
1570 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1571 _LIBCPP_INLINE_VISIBILITY
1572 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1573 _LIBCPP_INLINE_VISIBILITY
1574 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1575 template<class _InputIterator>
1578 __is_input_iterator<_InputIterator>::value,
1581 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1582 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1583 _LIBCPP_INLINE_VISIBILITY
1584 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1585 {return replace(__i1, __i2, __il.begin(), __il.end());}
1586 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1588 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1589 _LIBCPP_INLINE_VISIBILITY
1590 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1592 _LIBCPP_INLINE_VISIBILITY
1593 void swap(basic_string& __str)
1594 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1595 __is_nothrow_swappable<allocator_type>::value);
1597 _LIBCPP_INLINE_VISIBILITY
1598 const value_type* c_str() const _NOEXCEPT {return data();}
1599 _LIBCPP_INLINE_VISIBILITY
1600 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1602 _LIBCPP_INLINE_VISIBILITY
1603 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
1605 _LIBCPP_INLINE_VISIBILITY
1606 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1607 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1608 _LIBCPP_INLINE_VISIBILITY
1609 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1610 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1612 _LIBCPP_INLINE_VISIBILITY
1613 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1614 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1615 _LIBCPP_INLINE_VISIBILITY
1616 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1617 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1619 _LIBCPP_INLINE_VISIBILITY
1620 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1621 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1622 _LIBCPP_INLINE_VISIBILITY
1623 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1624 _LIBCPP_INLINE_VISIBILITY
1625 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1627 _LIBCPP_INLINE_VISIBILITY
1628 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1629 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1630 _LIBCPP_INLINE_VISIBILITY
1631 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1632 _LIBCPP_INLINE_VISIBILITY
1633 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1635 _LIBCPP_INLINE_VISIBILITY
1636 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1637 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1638 _LIBCPP_INLINE_VISIBILITY
1639 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1640 _LIBCPP_INLINE_VISIBILITY
1641 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1643 _LIBCPP_INLINE_VISIBILITY
1644 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1645 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1646 _LIBCPP_INLINE_VISIBILITY
1647 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1648 _LIBCPP_INLINE_VISIBILITY
1649 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1651 _LIBCPP_INLINE_VISIBILITY
1652 int compare(const basic_string& __str) const _NOEXCEPT;
1653 _LIBCPP_INLINE_VISIBILITY
1654 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1655 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
1656 int compare(const value_type* __s) const _NOEXCEPT;
1657 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1658 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1660 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1662 _LIBCPP_INLINE_VISIBILITY
1663 bool __is_long() const _NOEXCEPT
1664 {return bool(__r_.first().__s.__size_ & __short_mask);}
1666 #if _LIBCPP_DEBUG_LEVEL >= 2
1668 bool __dereferenceable(const const_iterator* __i) const;
1669 bool __decrementable(const const_iterator* __i) const;
1670 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1671 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1673 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1676 _LIBCPP_INLINE_VISIBILITY
1677 allocator_type& __alloc() _NOEXCEPT
1678 {return __r_.second();}
1679 _LIBCPP_INLINE_VISIBILITY
1680 const allocator_type& __alloc() const _NOEXCEPT
1681 {return __r_.second();}
1683 #ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
1685 _LIBCPP_INLINE_VISIBILITY
1686 void __set_short_size(size_type __s) _NOEXCEPT
1687 # if _LIBCPP_BIG_ENDIAN
1688 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1690 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1693 _LIBCPP_INLINE_VISIBILITY
1694 size_type __get_short_size() const _NOEXCEPT
1695 # if _LIBCPP_BIG_ENDIAN
1696 {return __r_.first().__s.__size_ >> 1;}
1698 {return __r_.first().__s.__size_;}
1701 #else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1703 _LIBCPP_INLINE_VISIBILITY
1704 void __set_short_size(size_type __s) _NOEXCEPT
1705 # if _LIBCPP_BIG_ENDIAN
1706 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1708 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1711 _LIBCPP_INLINE_VISIBILITY
1712 size_type __get_short_size() const _NOEXCEPT
1713 # if _LIBCPP_BIG_ENDIAN
1714 {return __r_.first().__s.__size_;}
1716 {return __r_.first().__s.__size_ >> 1;}
1719 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1721 _LIBCPP_INLINE_VISIBILITY
1722 void __set_long_size(size_type __s) _NOEXCEPT
1723 {__r_.first().__l.__size_ = __s;}
1724 _LIBCPP_INLINE_VISIBILITY
1725 size_type __get_long_size() const _NOEXCEPT
1726 {return __r_.first().__l.__size_;}
1727 _LIBCPP_INLINE_VISIBILITY
1728 void __set_size(size_type __s) _NOEXCEPT
1729 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1731 _LIBCPP_INLINE_VISIBILITY
1732 void __set_long_cap(size_type __s) _NOEXCEPT
1733 {__r_.first().__l.__cap_ = __long_mask | __s;}
1734 _LIBCPP_INLINE_VISIBILITY
1735 size_type __get_long_cap() const _NOEXCEPT
1736 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1738 _LIBCPP_INLINE_VISIBILITY
1739 void __set_long_pointer(pointer __p) _NOEXCEPT
1740 {__r_.first().__l.__data_ = __p;}
1741 _LIBCPP_INLINE_VISIBILITY
1742 pointer __get_long_pointer() _NOEXCEPT
1743 {return __r_.first().__l.__data_;}
1744 _LIBCPP_INLINE_VISIBILITY
1745 const_pointer __get_long_pointer() const _NOEXCEPT
1746 {return __r_.first().__l.__data_;}
1747 _LIBCPP_INLINE_VISIBILITY
1748 pointer __get_short_pointer() _NOEXCEPT
1749 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1750 _LIBCPP_INLINE_VISIBILITY
1751 const_pointer __get_short_pointer() const _NOEXCEPT
1752 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1753 _LIBCPP_INLINE_VISIBILITY
1754 pointer __get_pointer() _NOEXCEPT
1755 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1756 _LIBCPP_INLINE_VISIBILITY
1757 const_pointer __get_pointer() const _NOEXCEPT
1758 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1760 _LIBCPP_INLINE_VISIBILITY
1761 void __zero() _NOEXCEPT
1763 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1764 for (unsigned __i = 0; __i < __n_words; ++__i)
1768 template <size_type __a> static
1769 _LIBCPP_INLINE_VISIBILITY
1770 size_type __align_it(size_type __s) _NOEXCEPT
1771 {return __s + (__a-1) & ~(__a-1);}
1772 enum {__alignment = 16};
1773 static _LIBCPP_INLINE_VISIBILITY
1774 size_type __recommend(size_type __s) _NOEXCEPT
1775 {return (__s < __min_cap ? __min_cap :
1776 __align_it<sizeof(value_type) < __alignment ?
1777 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
1779 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1780 void __init(const value_type* __s, size_type __sz);
1781 void __init(size_type __n, value_type __c);
1783 template <class _InputIterator>
1786 __is_input_iterator <_InputIterator>::value &&
1787 !__is_forward_iterator<_InputIterator>::value,
1790 __init(_InputIterator __first, _InputIterator __last);
1792 template <class _ForwardIterator>
1795 __is_forward_iterator<_ForwardIterator>::value,
1798 __init(_ForwardIterator __first, _ForwardIterator __last);
1800 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1801 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1802 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1803 size_type __n_copy, size_type __n_del,
1804 size_type __n_add, const value_type* __p_new_stuff);
1806 _LIBCPP_INLINE_VISIBILITY
1807 void __erase_to_end(size_type __pos);
1809 _LIBCPP_INLINE_VISIBILITY
1810 void __copy_assign_alloc(const basic_string& __str)
1811 {__copy_assign_alloc(__str, integral_constant<bool,
1812 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1814 _LIBCPP_INLINE_VISIBILITY
1815 void __copy_assign_alloc(const basic_string& __str, true_type)
1817 if (__alloc() != __str.__alloc())
1822 __alloc() = __str.__alloc();
1825 _LIBCPP_INLINE_VISIBILITY
1826 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
1829 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1830 _LIBCPP_INLINE_VISIBILITY
1831 void __move_assign(basic_string& __str, false_type);
1832 _LIBCPP_INLINE_VISIBILITY
1833 void __move_assign(basic_string& __str, true_type)
1834 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1837 _LIBCPP_INLINE_VISIBILITY
1839 __move_assign_alloc(basic_string& __str)
1841 !__alloc_traits::propagate_on_container_move_assignment::value ||
1842 is_nothrow_move_assignable<allocator_type>::value)
1843 {__move_assign_alloc(__str, integral_constant<bool,
1844 __alloc_traits::propagate_on_container_move_assignment::value>());}
1846 _LIBCPP_INLINE_VISIBILITY
1847 void __move_assign_alloc(basic_string& __c, true_type)
1848 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1850 __alloc() = _VSTD::move(__c.__alloc());
1853 _LIBCPP_INLINE_VISIBILITY
1854 void __move_assign_alloc(basic_string&, false_type)
1858 _LIBCPP_INLINE_VISIBILITY
1859 static void __swap_alloc(allocator_type& __x, allocator_type& __y)
1860 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1861 __is_nothrow_swappable<allocator_type>::value)
1862 {__swap_alloc(__x, __y, integral_constant<bool,
1863 __alloc_traits::propagate_on_container_swap::value>());}
1865 _LIBCPP_INLINE_VISIBILITY
1866 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type)
1867 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value)
1872 _LIBCPP_INLINE_VISIBILITY
1873 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT
1876 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
1877 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
1879 friend basic_string operator+<>(const basic_string&, const basic_string&);
1880 friend basic_string operator+<>(const value_type*, const basic_string&);
1881 friend basic_string operator+<>(value_type, const basic_string&);
1882 friend basic_string operator+<>(const basic_string&, const value_type*);
1883 friend basic_string operator+<>(const basic_string&, value_type);
1886 template <class _CharT, class _Traits, class _Allocator>
1887 inline _LIBCPP_INLINE_VISIBILITY
1889 basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
1891 #if _LIBCPP_DEBUG_LEVEL >= 2
1892 __get_db()->__invalidate_all(this);
1893 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1896 template <class _CharT, class _Traits, class _Allocator>
1897 inline _LIBCPP_INLINE_VISIBILITY
1899 basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
1900 #if _LIBCPP_DEBUG_LEVEL >= 2
1905 #if _LIBCPP_DEBUG_LEVEL >= 2
1906 __c_node* __c = __get_db()->__find_c_and_lock(this);
1909 const_pointer __new_last = __get_pointer() + __pos;
1910 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1913 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
1914 if (__i->base() > __new_last)
1916 (*__p)->__c_ = nullptr;
1917 if (--__c->end_ != __p)
1918 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1921 __get_db()->unlock();
1923 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1926 template <class _CharT, class _Traits, class _Allocator>
1927 inline _LIBCPP_INLINE_VISIBILITY
1928 basic_string<_CharT, _Traits, _Allocator>::basic_string()
1929 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
1931 #if _LIBCPP_DEBUG_LEVEL >= 2
1932 __get_db()->__insert_c(this);
1937 template <class _CharT, class _Traits, class _Allocator>
1938 inline _LIBCPP_INLINE_VISIBILITY
1939 basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
1942 #if _LIBCPP_DEBUG_LEVEL >= 2
1943 __get_db()->__insert_c(this);
1948 template <class _CharT, class _Traits, class _Allocator>
1950 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
1952 if (__reserve > max_size())
1953 this->__throw_length_error();
1955 if (__reserve < __min_cap)
1957 __set_short_size(__sz);
1958 __p = __get_short_pointer();
1962 size_type __cap = __recommend(__reserve);
1963 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1964 __set_long_pointer(__p);
1965 __set_long_cap(__cap+1);
1966 __set_long_size(__sz);
1968 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1969 traits_type::assign(__p[__sz], value_type());
1972 template <class _CharT, class _Traits, class _Allocator>
1974 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1976 if (__sz > max_size())
1977 this->__throw_length_error();
1979 if (__sz < __min_cap)
1981 __set_short_size(__sz);
1982 __p = __get_short_pointer();
1986 size_type __cap = __recommend(__sz);
1987 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1988 __set_long_pointer(__p);
1989 __set_long_cap(__cap+1);
1990 __set_long_size(__sz);
1992 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1993 traits_type::assign(__p[__sz], value_type());
1996 template <class _CharT, class _Traits, class _Allocator>
1997 inline _LIBCPP_INLINE_VISIBILITY
1998 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
2000 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
2001 __init(__s, traits_type::length(__s));
2002 #if _LIBCPP_DEBUG_LEVEL >= 2
2003 __get_db()->__insert_c(this);
2007 template <class _CharT, class _Traits, class _Allocator>
2008 inline _LIBCPP_INLINE_VISIBILITY
2009 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
2012 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
2013 __init(__s, traits_type::length(__s));
2014 #if _LIBCPP_DEBUG_LEVEL >= 2
2015 __get_db()->__insert_c(this);
2019 template <class _CharT, class _Traits, class _Allocator>
2020 inline _LIBCPP_INLINE_VISIBILITY
2021 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
2023 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
2025 #if _LIBCPP_DEBUG_LEVEL >= 2
2026 __get_db()->__insert_c(this);
2030 template <class _CharT, class _Traits, class _Allocator>
2031 inline _LIBCPP_INLINE_VISIBILITY
2032 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
2035 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
2037 #if _LIBCPP_DEBUG_LEVEL >= 2
2038 __get_db()->__insert_c(this);
2042 template <class _CharT, class _Traits, class _Allocator>
2043 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
2044 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
2046 if (!__str.__is_long())
2047 __r_.first().__r = __str.__r_.first().__r;
2049 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
2050 #if _LIBCPP_DEBUG_LEVEL >= 2
2051 __get_db()->__insert_c(this);
2055 template <class _CharT, class _Traits, class _Allocator>
2056 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2059 if (!__str.__is_long())
2060 __r_.first().__r = __str.__r_.first().__r;
2062 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
2063 #if _LIBCPP_DEBUG_LEVEL >= 2
2064 __get_db()->__insert_c(this);
2068 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2070 template <class _CharT, class _Traits, class _Allocator>
2071 inline _LIBCPP_INLINE_VISIBILITY
2072 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
2073 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2074 : __r_(_VSTD::move(__str.__r_))
2077 #if _LIBCPP_DEBUG_LEVEL >= 2
2078 __get_db()->__insert_c(this);
2080 __get_db()->swap(this, &__str);
2084 template <class _CharT, class _Traits, class _Allocator>
2085 inline _LIBCPP_INLINE_VISIBILITY
2086 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
2089 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
2090 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
2093 __r_.first().__r = __str.__r_.first().__r;
2096 #if _LIBCPP_DEBUG_LEVEL >= 2
2097 __get_db()->__insert_c(this);
2099 __get_db()->swap(this, &__str);
2103 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2105 template <class _CharT, class _Traits, class _Allocator>
2107 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2109 if (__n > max_size())
2110 this->__throw_length_error();
2112 if (__n < __min_cap)
2114 __set_short_size(__n);
2115 __p = __get_short_pointer();
2119 size_type __cap = __recommend(__n);
2120 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2121 __set_long_pointer(__p);
2122 __set_long_cap(__cap+1);
2123 __set_long_size(__n);
2125 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
2126 traits_type::assign(__p[__n], value_type());
2129 template <class _CharT, class _Traits, class _Allocator>
2130 inline _LIBCPP_INLINE_VISIBILITY
2131 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
2134 #if _LIBCPP_DEBUG_LEVEL >= 2
2135 __get_db()->__insert_c(this);
2139 template <class _CharT, class _Traits, class _Allocator>
2140 inline _LIBCPP_INLINE_VISIBILITY
2141 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2145 #if _LIBCPP_DEBUG_LEVEL >= 2
2146 __get_db()->__insert_c(this);
2150 template <class _CharT, class _Traits, class _Allocator>
2151 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2152 const allocator_type& __a)
2155 size_type __str_sz = __str.size();
2156 if (__pos > __str_sz)
2157 this->__throw_out_of_range();
2158 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2159 #if _LIBCPP_DEBUG_LEVEL >= 2
2160 __get_db()->__insert_c(this);
2164 template <class _CharT, class _Traits, class _Allocator>
2165 template <class _InputIterator>
2168 __is_input_iterator <_InputIterator>::value &&
2169 !__is_forward_iterator<_InputIterator>::value,
2172 basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2175 #ifndef _LIBCPP_NO_EXCEPTIONS
2178 #endif // _LIBCPP_NO_EXCEPTIONS
2179 for (; __first != __last; ++__first)
2180 push_back(*__first);
2181 #ifndef _LIBCPP_NO_EXCEPTIONS
2186 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2189 #endif // _LIBCPP_NO_EXCEPTIONS
2192 template <class _CharT, class _Traits, class _Allocator>
2193 template <class _ForwardIterator>
2196 __is_forward_iterator<_ForwardIterator>::value,
2199 basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2201 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
2202 if (__sz > max_size())
2203 this->__throw_length_error();
2205 if (__sz < __min_cap)
2207 __set_short_size(__sz);
2208 __p = __get_short_pointer();
2212 size_type __cap = __recommend(__sz);
2213 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2214 __set_long_pointer(__p);
2215 __set_long_cap(__cap+1);
2216 __set_long_size(__sz);
2218 for (; __first != __last; ++__first, (void) ++__p)
2219 traits_type::assign(*__p, *__first);
2220 traits_type::assign(*__p, value_type());
2223 template <class _CharT, class _Traits, class _Allocator>
2224 template<class _InputIterator>
2225 inline _LIBCPP_INLINE_VISIBILITY
2226 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2228 __init(__first, __last);
2229 #if _LIBCPP_DEBUG_LEVEL >= 2
2230 __get_db()->__insert_c(this);
2234 template <class _CharT, class _Traits, class _Allocator>
2235 template<class _InputIterator>
2236 inline _LIBCPP_INLINE_VISIBILITY
2237 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2238 const allocator_type& __a)
2241 __init(__first, __last);
2242 #if _LIBCPP_DEBUG_LEVEL >= 2
2243 __get_db()->__insert_c(this);
2247 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2249 template <class _CharT, class _Traits, class _Allocator>
2250 inline _LIBCPP_INLINE_VISIBILITY
2251 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2253 __init(__il.begin(), __il.end());
2254 #if _LIBCPP_DEBUG_LEVEL >= 2
2255 __get_db()->__insert_c(this);
2259 template <class _CharT, class _Traits, class _Allocator>
2260 inline _LIBCPP_INLINE_VISIBILITY
2261 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2264 __init(__il.begin(), __il.end());
2265 #if _LIBCPP_DEBUG_LEVEL >= 2
2266 __get_db()->__insert_c(this);
2270 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2272 template <class _CharT, class _Traits, class _Allocator>
2273 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2275 #if _LIBCPP_DEBUG_LEVEL >= 2
2276 __get_db()->__erase_c(this);
2279 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2282 template <class _CharT, class _Traits, class _Allocator>
2284 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2285 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2286 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
2288 size_type __ms = max_size();
2289 if (__delta_cap > __ms - __old_cap - 1)
2290 this->__throw_length_error();
2291 pointer __old_p = __get_pointer();
2292 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2293 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2295 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2296 __invalidate_all_iterators();
2298 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2299 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2301 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
2302 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2303 if (__sec_cp_sz != 0)
2304 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2305 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2306 if (__old_cap+1 != __min_cap)
2307 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2308 __set_long_pointer(__p);
2309 __set_long_cap(__cap+1);
2310 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2311 __set_long_size(__old_sz);
2312 traits_type::assign(__p[__old_sz], value_type());
2315 template <class _CharT, class _Traits, class _Allocator>
2317 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2318 size_type __n_copy, size_type __n_del, size_type __n_add)
2320 size_type __ms = max_size();
2321 if (__delta_cap > __ms - __old_cap)
2322 this->__throw_length_error();
2323 pointer __old_p = __get_pointer();
2324 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2325 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2327 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2328 __invalidate_all_iterators();
2330 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2331 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2332 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2333 if (__sec_cp_sz != 0)
2334 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2335 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2337 if (__old_cap+1 != __min_cap)
2338 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2339 __set_long_pointer(__p);
2340 __set_long_cap(__cap+1);
2345 template <class _CharT, class _Traits, class _Allocator>
2346 basic_string<_CharT, _Traits, _Allocator>&
2347 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2349 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2350 size_type __cap = capacity();
2353 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2354 traits_type::move(__p, __s, __n);
2355 traits_type::assign(__p[__n], value_type());
2357 __invalidate_iterators_past(__n);
2361 size_type __sz = size();
2362 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2367 template <class _CharT, class _Traits, class _Allocator>
2368 basic_string<_CharT, _Traits, _Allocator>&
2369 basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2371 size_type __cap = capacity();
2374 size_type __sz = size();
2375 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2378 __invalidate_iterators_past(__n);
2379 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2380 traits_type::assign(__p, __n, __c);
2381 traits_type::assign(__p[__n], value_type());
2386 template <class _CharT, class _Traits, class _Allocator>
2387 basic_string<_CharT, _Traits, _Allocator>&
2388 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2393 __p = __get_long_pointer();
2398 __p = __get_short_pointer();
2399 __set_short_size(1);
2401 traits_type::assign(*__p, __c);
2402 traits_type::assign(*++__p, value_type());
2403 __invalidate_iterators_past(1);
2407 template <class _CharT, class _Traits, class _Allocator>
2408 basic_string<_CharT, _Traits, _Allocator>&
2409 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2413 __copy_assign_alloc(__str);
2419 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2421 template <class _CharT, class _Traits, class _Allocator>
2422 inline _LIBCPP_INLINE_VISIBILITY
2424 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2426 if (__alloc() != __str.__alloc())
2429 __move_assign(__str, true_type());
2432 template <class _CharT, class _Traits, class _Allocator>
2433 inline _LIBCPP_INLINE_VISIBILITY
2435 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2436 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2440 __r_.first() = __str.__r_.first();
2441 __move_assign_alloc(__str);
2445 template <class _CharT, class _Traits, class _Allocator>
2446 inline _LIBCPP_INLINE_VISIBILITY
2447 basic_string<_CharT, _Traits, _Allocator>&
2448 basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2449 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2450 is_nothrow_move_assignable<allocator_type>::value)
2452 __move_assign(__str, integral_constant<bool,
2453 __alloc_traits::propagate_on_container_move_assignment::value>());
2459 template <class _CharT, class _Traits, class _Allocator>
2460 template<class _InputIterator>
2463 __is_input_iterator <_InputIterator>::value &&
2464 !__is_forward_iterator<_InputIterator>::value,
2465 basic_string<_CharT, _Traits, _Allocator>&
2467 basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2470 for (; __first != __last; ++__first)
2471 push_back(*__first);
2475 template <class _CharT, class _Traits, class _Allocator>
2476 template<class _ForwardIterator>
2479 __is_forward_iterator<_ForwardIterator>::value,
2480 basic_string<_CharT, _Traits, _Allocator>&
2482 basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2484 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2485 size_type __cap = capacity();
2488 size_type __sz = size();
2489 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2492 __invalidate_iterators_past(__n);
2493 pointer __p = __get_pointer();
2494 for (; __first != __last; ++__first, ++__p)
2495 traits_type::assign(*__p, *__first);
2496 traits_type::assign(*__p, value_type());
2501 template <class _CharT, class _Traits, class _Allocator>
2502 inline _LIBCPP_INLINE_VISIBILITY
2503 basic_string<_CharT, _Traits, _Allocator>&
2504 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2506 return assign(__str.data(), __str.size());
2509 template <class _CharT, class _Traits, class _Allocator>
2510 basic_string<_CharT, _Traits, _Allocator>&
2511 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2513 size_type __sz = __str.size();
2515 this->__throw_out_of_range();
2516 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2519 template <class _CharT, class _Traits, class _Allocator>
2520 basic_string<_CharT, _Traits, _Allocator>&
2521 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2523 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2524 return assign(__s, traits_type::length(__s));
2529 template <class _CharT, class _Traits, class _Allocator>
2530 basic_string<_CharT, _Traits, _Allocator>&
2531 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2533 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
2534 size_type __cap = capacity();
2535 size_type __sz = size();
2536 if (__cap - __sz >= __n)
2540 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2541 traits_type::copy(__p + __sz, __s, __n);
2544 traits_type::assign(__p[__sz], value_type());
2548 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2552 template <class _CharT, class _Traits, class _Allocator>
2553 basic_string<_CharT, _Traits, _Allocator>&
2554 basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2558 size_type __cap = capacity();
2559 size_type __sz = size();
2560 if (__cap - __sz < __n)
2561 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2562 pointer __p = __get_pointer();
2563 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
2566 traits_type::assign(__p[__sz], value_type());
2571 template <class _CharT, class _Traits, class _Allocator>
2573 basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2575 bool __is_short = !__is_long();
2580 __cap = __min_cap - 1;
2581 __sz = __get_short_size();
2585 __cap = __get_long_cap() - 1;
2586 __sz = __get_long_size();
2590 __grow_by(__cap, 1, __sz, __sz, 0);
2591 __is_short = !__is_long();
2596 __p = __get_short_pointer() + __sz;
2597 __set_short_size(__sz+1);
2601 __p = __get_long_pointer() + __sz;
2602 __set_long_size(__sz+1);
2604 traits_type::assign(*__p, __c);
2605 traits_type::assign(*++__p, value_type());
2608 template <class _CharT, class _Traits, class _Allocator>
2609 template<class _InputIterator>
2612 __is_input_iterator <_InputIterator>::value &&
2613 !__is_forward_iterator<_InputIterator>::value,
2614 basic_string<_CharT, _Traits, _Allocator>&
2616 basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2618 for (; __first != __last; ++__first)
2619 push_back(*__first);
2623 template <class _CharT, class _Traits, class _Allocator>
2624 template<class _ForwardIterator>
2627 __is_forward_iterator<_ForwardIterator>::value,
2628 basic_string<_CharT, _Traits, _Allocator>&
2630 basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2632 size_type __sz = size();
2633 size_type __cap = capacity();
2634 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2637 if (__cap - __sz < __n)
2638 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2639 pointer __p = __get_pointer() + __sz;
2640 for (; __first != __last; ++__p, ++__first)
2641 traits_type::assign(*__p, *__first);
2642 traits_type::assign(*__p, value_type());
2643 __set_size(__sz + __n);
2648 template <class _CharT, class _Traits, class _Allocator>
2649 inline _LIBCPP_INLINE_VISIBILITY
2650 basic_string<_CharT, _Traits, _Allocator>&
2651 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2653 return append(__str.data(), __str.size());
2656 template <class _CharT, class _Traits, class _Allocator>
2657 basic_string<_CharT, _Traits, _Allocator>&
2658 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2660 size_type __sz = __str.size();
2662 this->__throw_out_of_range();
2663 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2666 template <class _CharT, class _Traits, class _Allocator>
2667 basic_string<_CharT, _Traits, _Allocator>&
2668 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2670 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
2671 return append(__s, traits_type::length(__s));
2676 template <class _CharT, class _Traits, class _Allocator>
2677 basic_string<_CharT, _Traits, _Allocator>&
2678 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2680 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
2681 size_type __sz = size();
2683 this->__throw_out_of_range();
2684 size_type __cap = capacity();
2685 if (__cap - __sz >= __n)
2689 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2690 size_type __n_move = __sz - __pos;
2693 if (__p + __pos <= __s && __s < __p + __sz)
2695 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2697 traits_type::move(__p + __pos, __s, __n);
2700 traits_type::assign(__p[__sz], value_type());
2704 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2708 template <class _CharT, class _Traits, class _Allocator>
2709 basic_string<_CharT, _Traits, _Allocator>&
2710 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2712 size_type __sz = size();
2714 this->__throw_out_of_range();
2717 size_type __cap = capacity();
2719 if (__cap - __sz >= __n)
2721 __p = _VSTD::__to_raw_pointer(__get_pointer());
2722 size_type __n_move = __sz - __pos;
2724 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2728 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2729 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2731 traits_type::assign(__p + __pos, __n, __c);
2734 traits_type::assign(__p[__sz], value_type());
2739 template <class _CharT, class _Traits, class _Allocator>
2740 template<class _InputIterator>
2743 __is_input_iterator <_InputIterator>::value &&
2744 !__is_forward_iterator<_InputIterator>::value,
2745 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2747 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2749 #if _LIBCPP_DEBUG_LEVEL >= 2
2750 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2751 "string::insert(iterator, range) called with an iterator not"
2752 " referring to this string");
2754 size_type __old_sz = size();
2755 difference_type __ip = __pos - begin();
2756 for (; __first != __last; ++__first)
2757 push_back(*__first);
2758 pointer __p = __get_pointer();
2759 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
2760 #if _LIBCPP_DEBUG_LEVEL >= 2
2761 return iterator(this, __p + __ip);
2763 return iterator(__p + __ip);
2767 template <class _CharT, class _Traits, class _Allocator>
2768 template<class _ForwardIterator>
2771 __is_forward_iterator<_ForwardIterator>::value,
2772 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2774 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2776 #if _LIBCPP_DEBUG_LEVEL >= 2
2777 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2778 "string::insert(iterator, range) called with an iterator not"
2779 " referring to this string");
2781 size_type __ip = static_cast<size_type>(__pos - begin());
2782 size_type __sz = size();
2783 size_type __cap = capacity();
2784 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2788 if (__cap - __sz >= __n)
2790 __p = _VSTD::__to_raw_pointer(__get_pointer());
2791 size_type __n_move = __sz - __ip;
2793 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2797 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2798 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2802 traits_type::assign(__p[__sz], value_type());
2803 for (__p += __ip; __first != __last; ++__p, ++__first)
2804 traits_type::assign(*__p, *__first);
2806 return begin() + __ip;
2809 template <class _CharT, class _Traits, class _Allocator>
2810 inline _LIBCPP_INLINE_VISIBILITY
2811 basic_string<_CharT, _Traits, _Allocator>&
2812 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2814 return insert(__pos1, __str.data(), __str.size());
2817 template <class _CharT, class _Traits, class _Allocator>
2818 basic_string<_CharT, _Traits, _Allocator>&
2819 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2820 size_type __pos2, size_type __n)
2822 size_type __str_sz = __str.size();
2823 if (__pos2 > __str_sz)
2824 this->__throw_out_of_range();
2825 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2828 template <class _CharT, class _Traits, class _Allocator>
2829 basic_string<_CharT, _Traits, _Allocator>&
2830 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2832 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
2833 return insert(__pos, __s, traits_type::length(__s));
2836 template <class _CharT, class _Traits, class _Allocator>
2837 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2838 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2840 size_type __ip = static_cast<size_type>(__pos - begin());
2841 size_type __sz = size();
2842 size_type __cap = capacity();
2846 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2847 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2851 __p = _VSTD::__to_raw_pointer(__get_pointer());
2852 size_type __n_move = __sz - __ip;
2854 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2856 traits_type::assign(__p[__ip], __c);
2857 traits_type::assign(__p[++__sz], value_type());
2859 return begin() + static_cast<difference_type>(__ip);
2862 template <class _CharT, class _Traits, class _Allocator>
2863 inline _LIBCPP_INLINE_VISIBILITY
2864 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2865 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2867 #if _LIBCPP_DEBUG_LEVEL >= 2
2868 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2869 "string::insert(iterator, n, value) called with an iterator not"
2870 " referring to this string");
2872 difference_type __p = __pos - begin();
2873 insert(static_cast<size_type>(__p), __n, __c);
2874 return begin() + __p;
2879 template <class _CharT, class _Traits, class _Allocator>
2880 basic_string<_CharT, _Traits, _Allocator>&
2881 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2883 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
2884 size_type __sz = size();
2886 this->__throw_out_of_range();
2887 __n1 = _VSTD::min(__n1, __sz - __pos);
2888 size_type __cap = capacity();
2889 if (__cap - __sz + __n1 >= __n2)
2891 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2894 size_type __n_move = __sz - __pos - __n1;
2899 traits_type::move(__p + __pos, __s, __n2);
2900 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2903 if (__p + __pos < __s && __s < __p + __sz)
2905 if (__p + __pos + __n1 <= __s)
2907 else // __p + __pos < __s < __p + __pos + __n1
2909 traits_type::move(__p + __pos, __s, __n1);
2916 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2919 traits_type::move(__p + __pos, __s, __n2);
2921 __sz += __n2 - __n1;
2923 __invalidate_iterators_past(__sz);
2924 traits_type::assign(__p[__sz], value_type());
2927 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2931 template <class _CharT, class _Traits, class _Allocator>
2932 basic_string<_CharT, _Traits, _Allocator>&
2933 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2935 size_type __sz = size();
2937 this->__throw_out_of_range();
2938 __n1 = _VSTD::min(__n1, __sz - __pos);
2939 size_type __cap = capacity();
2941 if (__cap - __sz + __n1 >= __n2)
2943 __p = _VSTD::__to_raw_pointer(__get_pointer());
2946 size_type __n_move = __sz - __pos - __n1;
2948 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2953 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2954 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2956 traits_type::assign(__p + __pos, __n2, __c);
2957 __sz += __n2 - __n1;
2959 __invalidate_iterators_past(__sz);
2960 traits_type::assign(__p[__sz], value_type());
2964 template <class _CharT, class _Traits, class _Allocator>
2965 template<class _InputIterator>
2968 __is_input_iterator<_InputIterator>::value,
2969 basic_string<_CharT, _Traits, _Allocator>&
2971 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
2972 _InputIterator __j1, _InputIterator __j2)
2974 for (; true; ++__i1, ++__j1)
2979 insert(__i1, __j1, __j2);
2987 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
2992 template <class _CharT, class _Traits, class _Allocator>
2993 inline _LIBCPP_INLINE_VISIBILITY
2994 basic_string<_CharT, _Traits, _Allocator>&
2995 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
2997 return replace(__pos1, __n1, __str.data(), __str.size());
3000 template <class _CharT, class _Traits, class _Allocator>
3001 basic_string<_CharT, _Traits, _Allocator>&
3002 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3003 size_type __pos2, size_type __n2)
3005 size_type __str_sz = __str.size();
3006 if (__pos2 > __str_sz)
3007 this->__throw_out_of_range();
3008 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3011 template <class _CharT, class _Traits, class _Allocator>
3012 basic_string<_CharT, _Traits, _Allocator>&
3013 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
3015 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
3016 return replace(__pos, __n1, __s, traits_type::length(__s));
3019 template <class _CharT, class _Traits, class _Allocator>
3020 inline _LIBCPP_INLINE_VISIBILITY
3021 basic_string<_CharT, _Traits, _Allocator>&
3022 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
3024 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3025 __str.data(), __str.size());
3028 template <class _CharT, class _Traits, class _Allocator>
3029 inline _LIBCPP_INLINE_VISIBILITY
3030 basic_string<_CharT, _Traits, _Allocator>&
3031 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
3033 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3036 template <class _CharT, class _Traits, class _Allocator>
3037 inline _LIBCPP_INLINE_VISIBILITY
3038 basic_string<_CharT, _Traits, _Allocator>&
3039 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
3041 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3044 template <class _CharT, class _Traits, class _Allocator>
3045 inline _LIBCPP_INLINE_VISIBILITY
3046 basic_string<_CharT, _Traits, _Allocator>&
3047 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
3049 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3054 template <class _CharT, class _Traits, class _Allocator>
3055 basic_string<_CharT, _Traits, _Allocator>&
3056 basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3058 size_type __sz = size();
3060 this->__throw_out_of_range();
3063 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
3064 __n = _VSTD::min(__n, __sz - __pos);
3065 size_type __n_move = __sz - __pos - __n;
3067 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3070 __invalidate_iterators_past(__sz);
3071 traits_type::assign(__p[__sz], value_type());
3076 template <class _CharT, class _Traits, class _Allocator>
3077 inline _LIBCPP_INLINE_VISIBILITY
3078 typename basic_string<_CharT, _Traits, _Allocator>::iterator
3079 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3081 #if _LIBCPP_DEBUG_LEVEL >= 2
3082 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3083 "string::erase(iterator) called with an iterator not"
3084 " referring to this string");
3086 _LIBCPP_ASSERT(__pos != end(),
3087 "string::erase(iterator) called with a non-dereferenceable iterator");
3088 iterator __b = begin();
3089 size_type __r = static_cast<size_type>(__pos - __b);
3091 return __b + static_cast<difference_type>(__r);
3094 template <class _CharT, class _Traits, class _Allocator>
3095 inline _LIBCPP_INLINE_VISIBILITY
3096 typename basic_string<_CharT, _Traits, _Allocator>::iterator
3097 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3099 #if _LIBCPP_DEBUG_LEVEL >= 2
3100 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3101 "string::erase(iterator, iterator) called with an iterator not"
3102 " referring to this string");
3104 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
3105 iterator __b = begin();
3106 size_type __r = static_cast<size_type>(__first - __b);
3107 erase(__r, static_cast<size_type>(__last - __first));
3108 return __b + static_cast<difference_type>(__r);
3111 template <class _CharT, class _Traits, class _Allocator>
3112 inline _LIBCPP_INLINE_VISIBILITY
3114 basic_string<_CharT, _Traits, _Allocator>::pop_back()
3116 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
3120 __sz = __get_long_size() - 1;
3121 __set_long_size(__sz);
3122 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3126 __sz = __get_short_size() - 1;
3127 __set_short_size(__sz);
3128 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3130 __invalidate_iterators_past(__sz);
3133 template <class _CharT, class _Traits, class _Allocator>
3134 inline _LIBCPP_INLINE_VISIBILITY
3136 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
3138 __invalidate_all_iterators();
3141 traits_type::assign(*__get_long_pointer(), value_type());
3146 traits_type::assign(*__get_short_pointer(), value_type());
3147 __set_short_size(0);
3151 template <class _CharT, class _Traits, class _Allocator>
3152 inline _LIBCPP_INLINE_VISIBILITY
3154 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3158 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3159 __set_long_size(__pos);
3163 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3164 __set_short_size(__pos);
3166 __invalidate_iterators_past(__pos);
3169 template <class _CharT, class _Traits, class _Allocator>
3171 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3173 size_type __sz = size();
3175 append(__n - __sz, __c);
3177 __erase_to_end(__n);
3180 template <class _CharT, class _Traits, class _Allocator>
3181 inline _LIBCPP_INLINE_VISIBILITY
3182 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3183 basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
3185 size_type __m = __alloc_traits::max_size(__alloc());
3186 #if _LIBCPP_BIG_ENDIAN
3187 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
3189 return __m - __alignment;
3193 template <class _CharT, class _Traits, class _Allocator>
3195 basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3197 if (__res_arg > max_size())
3198 this->__throw_length_error();
3199 size_type __cap = capacity();
3200 size_type __sz = size();
3201 __res_arg = _VSTD::max(__res_arg, __sz);
3202 __res_arg = __recommend(__res_arg);
3203 if (__res_arg != __cap)
3205 pointer __new_data, __p;
3206 bool __was_long, __now_long;
3207 if (__res_arg == __min_cap - 1)
3211 __new_data = __get_short_pointer();
3212 __p = __get_long_pointer();
3216 if (__res_arg > __cap)
3217 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3220 #ifndef _LIBCPP_NO_EXCEPTIONS
3223 #endif // _LIBCPP_NO_EXCEPTIONS
3224 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3225 #ifndef _LIBCPP_NO_EXCEPTIONS
3231 #else // _LIBCPP_NO_EXCEPTIONS
3232 if (__new_data == nullptr)
3234 #endif // _LIBCPP_NO_EXCEPTIONS
3237 __was_long = __is_long();
3238 __p = __get_pointer();
3240 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3241 _VSTD::__to_raw_pointer(__p), size()+1);
3243 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3246 __set_long_cap(__res_arg+1);
3247 __set_long_size(__sz);
3248 __set_long_pointer(__new_data);
3251 __set_short_size(__sz);
3252 __invalidate_all_iterators();
3256 template <class _CharT, class _Traits, class _Allocator>
3257 inline _LIBCPP_INLINE_VISIBILITY
3258 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3259 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3261 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3262 return *(data() + __pos);
3265 template <class _CharT, class _Traits, class _Allocator>
3266 inline _LIBCPP_INLINE_VISIBILITY
3267 typename basic_string<_CharT, _Traits, _Allocator>::reference
3268 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3270 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3271 return *(__get_pointer() + __pos);
3274 template <class _CharT, class _Traits, class _Allocator>
3275 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3276 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3279 this->__throw_out_of_range();
3280 return (*this)[__n];
3283 template <class _CharT, class _Traits, class _Allocator>
3284 typename basic_string<_CharT, _Traits, _Allocator>::reference
3285 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3288 this->__throw_out_of_range();
3289 return (*this)[__n];
3292 template <class _CharT, class _Traits, class _Allocator>
3293 inline _LIBCPP_INLINE_VISIBILITY
3294 typename basic_string<_CharT, _Traits, _Allocator>::reference
3295 basic_string<_CharT, _Traits, _Allocator>::front()
3297 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3298 return *__get_pointer();
3301 template <class _CharT, class _Traits, class _Allocator>
3302 inline _LIBCPP_INLINE_VISIBILITY
3303 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3304 basic_string<_CharT, _Traits, _Allocator>::front() const
3306 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3310 template <class _CharT, class _Traits, class _Allocator>
3311 inline _LIBCPP_INLINE_VISIBILITY
3312 typename basic_string<_CharT, _Traits, _Allocator>::reference
3313 basic_string<_CharT, _Traits, _Allocator>::back()
3315 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3316 return *(__get_pointer() + size() - 1);
3319 template <class _CharT, class _Traits, class _Allocator>
3320 inline _LIBCPP_INLINE_VISIBILITY
3321 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3322 basic_string<_CharT, _Traits, _Allocator>::back() const
3324 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3325 return *(data() + size() - 1);
3328 template <class _CharT, class _Traits, class _Allocator>
3329 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3330 basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3332 size_type __sz = size();
3334 this->__throw_out_of_range();
3335 size_type __rlen = _VSTD::min(__n, __sz - __pos);
3336 traits_type::copy(__s, data() + __pos, __rlen);
3340 template <class _CharT, class _Traits, class _Allocator>
3341 inline _LIBCPP_INLINE_VISIBILITY
3342 basic_string<_CharT, _Traits, _Allocator>
3343 basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3345 return basic_string(*this, __pos, __n, __alloc());
3348 template <class _CharT, class _Traits, class _Allocator>
3349 inline _LIBCPP_INLINE_VISIBILITY
3351 basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3352 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3353 __is_nothrow_swappable<allocator_type>::value)
3355 #if _LIBCPP_DEBUG_LEVEL >= 2
3357 __get_db()->__invalidate_all(this);
3358 if (!__str.__is_long())
3359 __get_db()->__invalidate_all(&__str);
3360 __get_db()->swap(this, &__str);
3362 _VSTD::swap(__r_.first(), __str.__r_.first());
3363 __swap_alloc(__alloc(), __str.__alloc());
3368 template <class _Traits>
3369 struct _LIBCPP_HIDDEN __traits_eq
3371 typedef typename _Traits::char_type char_type;
3372 _LIBCPP_INLINE_VISIBILITY
3373 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3374 {return _Traits::eq(__x, __y);}
3377 template<class _CharT, class _Traits, class _Allocator>
3378 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3379 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3381 size_type __n) const _NOEXCEPT
3383 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
3384 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3385 (data(), size(), __s, __pos, __n);
3388 template<class _CharT, class _Traits, class _Allocator>
3389 inline _LIBCPP_INLINE_VISIBILITY
3390 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3391 basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3392 size_type __pos) const _NOEXCEPT
3394 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3395 (data(), size(), __str.data(), __pos, __str.size());
3398 template<class _CharT, class _Traits, class _Allocator>
3399 inline _LIBCPP_INLINE_VISIBILITY
3400 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3401 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3402 size_type __pos) const _NOEXCEPT
3404 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
3405 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3406 (data(), size(), __s, __pos, traits_type::length(__s));
3409 template<class _CharT, class _Traits, class _Allocator>
3410 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3411 basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3412 size_type __pos) const _NOEXCEPT
3414 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3415 (data(), size(), __c, __pos);
3420 template<class _CharT, class _Traits, class _Allocator>
3421 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3422 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3424 size_type __n) const _NOEXCEPT
3426 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
3427 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3428 (data(), size(), __s, __pos, __n);
3431 template<class _CharT, class _Traits, class _Allocator>
3432 inline _LIBCPP_INLINE_VISIBILITY
3433 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3434 basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3435 size_type __pos) const _NOEXCEPT
3437 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3438 (data(), size(), __str.data(), __pos, __str.size());
3441 template<class _CharT, class _Traits, class _Allocator>
3442 inline _LIBCPP_INLINE_VISIBILITY
3443 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3444 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3445 size_type __pos) const _NOEXCEPT
3447 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
3448 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3449 (data(), size(), __s, __pos, traits_type::length(__s));
3452 template<class _CharT, class _Traits, class _Allocator>
3453 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3454 basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3455 size_type __pos) const _NOEXCEPT
3457 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3458 (data(), size(), __c, __pos);
3463 template<class _CharT, class _Traits, class _Allocator>
3464 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3465 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3467 size_type __n) const _NOEXCEPT
3469 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
3470 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
3471 (data(), size(), __s, __pos, __n);
3474 template<class _CharT, class _Traits, class _Allocator>
3475 inline _LIBCPP_INLINE_VISIBILITY
3476 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3477 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3478 size_type __pos) const _NOEXCEPT
3480 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
3481 (data(), size(), __str.data(), __pos, __str.size());
3484 template<class _CharT, class _Traits, class _Allocator>
3485 inline _LIBCPP_INLINE_VISIBILITY
3486 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3487 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3488 size_type __pos) const _NOEXCEPT
3490 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
3491 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
3492 (data(), size(), __s, __pos, traits_type::length(__s));
3495 template<class _CharT, class _Traits, class _Allocator>
3496 inline _LIBCPP_INLINE_VISIBILITY
3497 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3498 basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3499 size_type __pos) const _NOEXCEPT
3501 return find(__c, __pos);
3506 template<class _CharT, class _Traits, class _Allocator>
3507 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3508 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3510 size_type __n) const _NOEXCEPT
3512 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
3513 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
3514 (data(), size(), __s, __pos, __n);
3517 template<class _CharT, class _Traits, class _Allocator>
3518 inline _LIBCPP_INLINE_VISIBILITY
3519 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3520 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3521 size_type __pos) const _NOEXCEPT
3523 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
3524 (data(), size(), __str.data(), __pos, __str.size());
3527 template<class _CharT, class _Traits, class _Allocator>
3528 inline _LIBCPP_INLINE_VISIBILITY
3529 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3530 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3531 size_type __pos) const _NOEXCEPT
3533 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
3534 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
3535 (data(), size(), __s, __pos, traits_type::length(__s));
3538 template<class _CharT, class _Traits, class _Allocator>
3539 inline _LIBCPP_INLINE_VISIBILITY
3540 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3541 basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3542 size_type __pos) const _NOEXCEPT
3544 return rfind(__c, __pos);
3547 // find_first_not_of
3549 template<class _CharT, class _Traits, class _Allocator>
3550 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3551 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3553 size_type __n) const _NOEXCEPT
3555 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
3556 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3557 (data(), size(), __s, __pos, __n);
3560 template<class _CharT, class _Traits, class _Allocator>
3561 inline _LIBCPP_INLINE_VISIBILITY
3562 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3563 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3564 size_type __pos) const _NOEXCEPT
3566 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3567 (data(), size(), __str.data(), __pos, __str.size());
3570 template<class _CharT, class _Traits, class _Allocator>
3571 inline _LIBCPP_INLINE_VISIBILITY
3572 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3573 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3574 size_type __pos) const _NOEXCEPT
3576 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
3577 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3578 (data(), size(), __s, __pos, traits_type::length(__s));
3581 template<class _CharT, class _Traits, class _Allocator>
3582 inline _LIBCPP_INLINE_VISIBILITY
3583 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3584 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3585 size_type __pos) const _NOEXCEPT
3587 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3588 (data(), size(), __c, __pos);
3593 template<class _CharT, class _Traits, class _Allocator>
3594 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3595 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3597 size_type __n) const _NOEXCEPT
3599 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
3600 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3601 (data(), size(), __s, __pos, __n);
3604 template<class _CharT, class _Traits, class _Allocator>
3605 inline _LIBCPP_INLINE_VISIBILITY
3606 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3607 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3608 size_type __pos) const _NOEXCEPT
3610 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3611 (data(), size(), __str.data(), __pos, __str.size());
3614 template<class _CharT, class _Traits, class _Allocator>
3615 inline _LIBCPP_INLINE_VISIBILITY
3616 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3617 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3618 size_type __pos) const _NOEXCEPT
3620 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
3621 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3622 (data(), size(), __s, __pos, traits_type::length(__s));
3625 template<class _CharT, class _Traits, class _Allocator>
3626 inline _LIBCPP_INLINE_VISIBILITY
3627 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3628 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3629 size_type __pos) const _NOEXCEPT
3631 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3632 (data(), size(), __c, __pos);
3637 template <class _CharT, class _Traits, class _Allocator>
3638 inline _LIBCPP_INLINE_VISIBILITY
3640 basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3642 size_t __lhs_sz = size();
3643 size_t __rhs_sz = __str.size();
3644 int __result = traits_type::compare(data(), __str.data(),
3645 _VSTD::min(__lhs_sz, __rhs_sz));
3648 if (__lhs_sz < __rhs_sz)
3650 if (__lhs_sz > __rhs_sz)
3655 template <class _CharT, class _Traits, class _Allocator>
3656 inline _LIBCPP_INLINE_VISIBILITY
3658 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3660 const basic_string& __str) const
3662 return compare(__pos1, __n1, __str.data(), __str.size());
3665 template <class _CharT, class _Traits, class _Allocator>
3667 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3669 const basic_string& __str,
3671 size_type __n2) const
3673 size_type __sz = __str.size();
3675 this->__throw_out_of_range();
3676 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
3680 template <class _CharT, class _Traits, class _Allocator>
3682 basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3684 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3685 return compare(0, npos, __s, traits_type::length(__s));
3688 template <class _CharT, class _Traits, class _Allocator>
3690 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3692 const value_type* __s) const
3694 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3695 return compare(__pos1, __n1, __s, traits_type::length(__s));
3698 template <class _CharT, class _Traits, class _Allocator>
3700 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3702 const value_type* __s,
3703 size_type __n2) const
3705 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
3706 size_type __sz = size();
3707 if (__pos1 > __sz || __n2 == npos)
3708 this->__throw_out_of_range();
3709 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3710 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
3715 else if (__rlen > __n2)
3723 template<class _CharT, class _Traits, class _Allocator>
3724 inline _LIBCPP_INLINE_VISIBILITY
3726 basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3728 if (size() > capacity())
3730 if (capacity() < __min_cap - 1)
3734 if (data()[size()] != value_type(0))
3741 template<class _CharT, class _Traits, class _Allocator>
3742 inline _LIBCPP_INLINE_VISIBILITY
3744 operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3745 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3747 size_t __lhs_sz = __lhs.size();
3748 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3753 template<class _Allocator>
3754 inline _LIBCPP_INLINE_VISIBILITY
3756 operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3757 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3759 size_t __lhs_sz = __lhs.size();
3760 if (__lhs_sz != __rhs.size())
3762 const char* __lp = __lhs.data();
3763 const char* __rp = __rhs.data();
3764 if (__lhs.__is_long())
3765 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3766 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3772 template<class _CharT, class _Traits, class _Allocator>
3773 inline _LIBCPP_INLINE_VISIBILITY
3775 operator==(const _CharT* __lhs,
3776 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3778 return __rhs.compare(__lhs) == 0;
3781 template<class _CharT, class _Traits, class _Allocator>
3782 inline _LIBCPP_INLINE_VISIBILITY
3784 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3785 const _CharT* __rhs) _NOEXCEPT
3787 return __lhs.compare(__rhs) == 0;
3792 template<class _CharT, class _Traits, class _Allocator>
3793 inline _LIBCPP_INLINE_VISIBILITY
3795 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3796 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3798 return !(__lhs == __rhs);
3801 template<class _CharT, class _Traits, class _Allocator>
3802 inline _LIBCPP_INLINE_VISIBILITY
3804 operator!=(const _CharT* __lhs,
3805 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3807 return !(__lhs == __rhs);
3810 template<class _CharT, class _Traits, class _Allocator>
3811 inline _LIBCPP_INLINE_VISIBILITY
3813 operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3814 const _CharT* __rhs) _NOEXCEPT
3816 return !(__lhs == __rhs);
3821 template<class _CharT, class _Traits, class _Allocator>
3822 inline _LIBCPP_INLINE_VISIBILITY
3824 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3825 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3827 return __lhs.compare(__rhs) < 0;
3830 template<class _CharT, class _Traits, class _Allocator>
3831 inline _LIBCPP_INLINE_VISIBILITY
3833 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3834 const _CharT* __rhs) _NOEXCEPT
3836 return __lhs.compare(__rhs) < 0;
3839 template<class _CharT, class _Traits, class _Allocator>
3840 inline _LIBCPP_INLINE_VISIBILITY
3842 operator< (const _CharT* __lhs,
3843 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3845 return __rhs.compare(__lhs) > 0;
3850 template<class _CharT, class _Traits, class _Allocator>
3851 inline _LIBCPP_INLINE_VISIBILITY
3853 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3854 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3856 return __rhs < __lhs;
3859 template<class _CharT, class _Traits, class _Allocator>
3860 inline _LIBCPP_INLINE_VISIBILITY
3862 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3863 const _CharT* __rhs) _NOEXCEPT
3865 return __rhs < __lhs;
3868 template<class _CharT, class _Traits, class _Allocator>
3869 inline _LIBCPP_INLINE_VISIBILITY
3871 operator> (const _CharT* __lhs,
3872 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3874 return __rhs < __lhs;
3879 template<class _CharT, class _Traits, class _Allocator>
3880 inline _LIBCPP_INLINE_VISIBILITY
3882 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3883 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3885 return !(__rhs < __lhs);
3888 template<class _CharT, class _Traits, class _Allocator>
3889 inline _LIBCPP_INLINE_VISIBILITY
3891 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3892 const _CharT* __rhs) _NOEXCEPT
3894 return !(__rhs < __lhs);
3897 template<class _CharT, class _Traits, class _Allocator>
3898 inline _LIBCPP_INLINE_VISIBILITY
3900 operator<=(const _CharT* __lhs,
3901 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3903 return !(__rhs < __lhs);
3908 template<class _CharT, class _Traits, class _Allocator>
3909 inline _LIBCPP_INLINE_VISIBILITY
3911 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3912 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3914 return !(__lhs < __rhs);
3917 template<class _CharT, class _Traits, class _Allocator>
3918 inline _LIBCPP_INLINE_VISIBILITY
3920 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3921 const _CharT* __rhs) _NOEXCEPT
3923 return !(__lhs < __rhs);
3926 template<class _CharT, class _Traits, class _Allocator>
3927 inline _LIBCPP_INLINE_VISIBILITY
3929 operator>=(const _CharT* __lhs,
3930 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3932 return !(__lhs < __rhs);
3937 template<class _CharT, class _Traits, class _Allocator>
3938 basic_string<_CharT, _Traits, _Allocator>
3939 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3940 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3942 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3943 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3944 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3945 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3946 __r.append(__rhs.data(), __rhs_sz);
3950 template<class _CharT, class _Traits, class _Allocator>
3951 basic_string<_CharT, _Traits, _Allocator>
3952 operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3954 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3955 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3956 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3957 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3958 __r.append(__rhs.data(), __rhs_sz);
3962 template<class _CharT, class _Traits, class _Allocator>
3963 basic_string<_CharT, _Traits, _Allocator>
3964 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3966 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3967 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3968 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3969 __r.append(__rhs.data(), __rhs_sz);
3973 template<class _CharT, class _Traits, class _Allocator>
3974 basic_string<_CharT, _Traits, _Allocator>
3975 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3977 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3978 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3979 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3980 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3981 __r.append(__rhs, __rhs_sz);
3985 template<class _CharT, class _Traits, class _Allocator>
3986 basic_string<_CharT, _Traits, _Allocator>
3987 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
3989 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3990 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3991 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
3992 __r.push_back(__rhs);
3996 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3998 template<class _CharT, class _Traits, class _Allocator>
3999 inline _LIBCPP_INLINE_VISIBILITY
4000 basic_string<_CharT, _Traits, _Allocator>
4001 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4003 return _VSTD::move(__lhs.append(__rhs));
4006 template<class _CharT, class _Traits, class _Allocator>
4007 inline _LIBCPP_INLINE_VISIBILITY
4008 basic_string<_CharT, _Traits, _Allocator>
4009 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4011 return _VSTD::move(__rhs.insert(0, __lhs));
4014 template<class _CharT, class _Traits, class _Allocator>
4015 inline _LIBCPP_INLINE_VISIBILITY
4016 basic_string<_CharT, _Traits, _Allocator>
4017 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4019 return _VSTD::move(__lhs.append(__rhs));
4022 template<class _CharT, class _Traits, class _Allocator>
4023 inline _LIBCPP_INLINE_VISIBILITY
4024 basic_string<_CharT, _Traits, _Allocator>
4025 operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4027 return _VSTD::move(__rhs.insert(0, __lhs));
4030 template<class _CharT, class _Traits, class _Allocator>
4031 inline _LIBCPP_INLINE_VISIBILITY
4032 basic_string<_CharT, _Traits, _Allocator>
4033 operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4035 __rhs.insert(__rhs.begin(), __lhs);
4036 return _VSTD::move(__rhs);
4039 template<class _CharT, class _Traits, class _Allocator>
4040 inline _LIBCPP_INLINE_VISIBILITY
4041 basic_string<_CharT, _Traits, _Allocator>
4042 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4044 return _VSTD::move(__lhs.append(__rhs));
4047 template<class _CharT, class _Traits, class _Allocator>
4048 inline _LIBCPP_INLINE_VISIBILITY
4049 basic_string<_CharT, _Traits, _Allocator>
4050 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4052 __lhs.push_back(__rhs);
4053 return _VSTD::move(__lhs);
4056 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4060 template<class _CharT, class _Traits, class _Allocator>
4061 inline _LIBCPP_INLINE_VISIBILITY
4063 swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
4064 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4065 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
4070 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4072 typedef basic_string<char16_t> u16string;
4073 typedef basic_string<char32_t> u32string;
4075 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
4077 _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4078 _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4079 _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4080 _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4081 _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4083 _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4084 _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4085 _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
4087 _LIBCPP_FUNC_VIS string to_string(int __val);
4088 _LIBCPP_FUNC_VIS string to_string(unsigned __val);
4089 _LIBCPP_FUNC_VIS string to_string(long __val);
4090 _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4091 _LIBCPP_FUNC_VIS string to_string(long long __val);
4092 _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4093 _LIBCPP_FUNC_VIS string to_string(float __val);
4094 _LIBCPP_FUNC_VIS string to_string(double __val);
4095 _LIBCPP_FUNC_VIS string to_string(long double __val);
4097 _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4098 _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4099 _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4100 _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4101 _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4103 _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4104 _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4105 _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
4107 _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4108 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4109 _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4110 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4111 _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4112 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4113 _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4114 _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4115 _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
4117 template<class _CharT, class _Traits, class _Allocator>
4118 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4119 basic_string<_CharT, _Traits, _Allocator>::npos;
4121 template<class _CharT, class _Traits, class _Allocator>
4122 struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
4123 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4126 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
4129 template<class _CharT, class _Traits, class _Allocator>
4131 hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
4132 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
4134 return __do_string_hash(__val.data(), __val.data() + __val.size());
4137 template<class _CharT, class _Traits, class _Allocator>
4138 basic_ostream<_CharT, _Traits>&
4139 operator<<(basic_ostream<_CharT, _Traits>& __os,
4140 const basic_string<_CharT, _Traits, _Allocator>& __str);
4142 template<class _CharT, class _Traits, class _Allocator>
4143 basic_istream<_CharT, _Traits>&
4144 operator>>(basic_istream<_CharT, _Traits>& __is,
4145 basic_string<_CharT, _Traits, _Allocator>& __str);
4147 template<class _CharT, class _Traits, class _Allocator>
4148 basic_istream<_CharT, _Traits>&
4149 getline(basic_istream<_CharT, _Traits>& __is,
4150 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4152 template<class _CharT, class _Traits, class _Allocator>
4153 inline _LIBCPP_INLINE_VISIBILITY
4154 basic_istream<_CharT, _Traits>&
4155 getline(basic_istream<_CharT, _Traits>& __is,
4156 basic_string<_CharT, _Traits, _Allocator>& __str);
4158 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4160 template<class _CharT, class _Traits, class _Allocator>
4161 inline _LIBCPP_INLINE_VISIBILITY
4162 basic_istream<_CharT, _Traits>&
4163 getline(basic_istream<_CharT, _Traits>&& __is,
4164 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4166 template<class _CharT, class _Traits, class _Allocator>
4167 inline _LIBCPP_INLINE_VISIBILITY
4168 basic_istream<_CharT, _Traits>&
4169 getline(basic_istream<_CharT, _Traits>&& __is,
4170 basic_string<_CharT, _Traits, _Allocator>& __str);
4172 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4174 #if _LIBCPP_DEBUG_LEVEL >= 2
4176 template<class _CharT, class _Traits, class _Allocator>
4178 basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4180 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4181 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4184 template<class _CharT, class _Traits, class _Allocator>
4186 basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4188 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4189 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4192 template<class _CharT, class _Traits, class _Allocator>
4194 basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4196 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4197 return this->data() <= __p && __p <= this->data() + this->size();
4200 template<class _CharT, class _Traits, class _Allocator>
4202 basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4204 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4205 return this->data() <= __p && __p < this->data() + this->size();
4208 #endif // _LIBCPP_DEBUG_LEVEL >= 2
4210 #if _LIBCPP_STD_VER > 11
4211 // Literal suffixes for basic_string [basic.string.literals]
4212 inline namespace literals
4214 inline namespace string_literals
4216 inline _LIBCPP_INLINE_VISIBILITY
4217 basic_string<char> operator "" s( const char *__str, size_t __len )
4219 return basic_string<char> (__str, __len);
4222 inline _LIBCPP_INLINE_VISIBILITY
4223 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4225 return basic_string<wchar_t> (__str, __len);
4228 inline _LIBCPP_INLINE_VISIBILITY
4229 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4231 return basic_string<char16_t> (__str, __len);
4234 inline _LIBCPP_INLINE_VISIBILITY
4235 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4237 return basic_string<char32_t> (__str, __len);
4243 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4244 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
4245 _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
4247 _LIBCPP_END_NAMESPACE_STD
4249 #endif // _LIBCPP_STRING