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_traits<allocator_type>::propagate_on_container_swap::value ||
224 allocator_traits<allocator_type>::is_always_equal::value); // C++17
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 __n == 0 ? 0 : 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 __n == 0 ? NULL : (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 __n == 0 ? __s1 : (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 __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
650 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
651 {return __n == 0 ? __s : (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 __n == 0 ? 0 : 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 __n == 0 ? NULL : (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 __n == 0 ? __s1 : (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 __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
696 static inline char_type* assign(char_type* __s, size_t __n, char_type __a)
697 {return __n == 0 ? __s : (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);
1326 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
1327 #if _LIBCPP_STD_VER <= 14
1328 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
1333 basic_string(const basic_string& __str);
1334 basic_string(const basic_string& __str, const allocator_type& __a);
1336 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1337 _LIBCPP_INLINE_VISIBILITY
1338 basic_string(basic_string&& __str)
1339 #if _LIBCPP_STD_VER <= 14
1340 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
1345 _LIBCPP_INLINE_VISIBILITY
1346 basic_string(basic_string&& __str, const allocator_type& __a);
1347 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1348 _LIBCPP_INLINE_VISIBILITY basic_string(const value_type* __s);
1349 _LIBCPP_INLINE_VISIBILITY
1350 basic_string(const value_type* __s, const allocator_type& __a);
1351 _LIBCPP_INLINE_VISIBILITY
1352 basic_string(const value_type* __s, size_type __n);
1353 _LIBCPP_INLINE_VISIBILITY
1354 basic_string(const value_type* __s, size_type __n, const allocator_type& __a);
1355 _LIBCPP_INLINE_VISIBILITY
1356 basic_string(size_type __n, value_type __c);
1357 _LIBCPP_INLINE_VISIBILITY
1358 basic_string(size_type __n, value_type __c, const allocator_type& __a);
1359 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos,
1360 const allocator_type& __a = allocator_type());
1361 template<class _InputIterator>
1362 _LIBCPP_INLINE_VISIBILITY
1363 basic_string(_InputIterator __first, _InputIterator __last);
1364 template<class _InputIterator>
1365 _LIBCPP_INLINE_VISIBILITY
1366 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
1367 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1368 _LIBCPP_INLINE_VISIBILITY
1369 basic_string(initializer_list<value_type> __il);
1370 _LIBCPP_INLINE_VISIBILITY
1371 basic_string(initializer_list<value_type> __il, const allocator_type& __a);
1372 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1376 basic_string& operator=(const basic_string& __str);
1377 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1378 _LIBCPP_INLINE_VISIBILITY
1379 basic_string& operator=(basic_string&& __str)
1380 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
1381 is_nothrow_move_assignable<allocator_type>::value);
1383 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
1384 basic_string& operator=(value_type __c);
1385 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1386 _LIBCPP_INLINE_VISIBILITY
1387 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1388 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1390 #if _LIBCPP_DEBUG_LEVEL >= 2
1391 _LIBCPP_INLINE_VISIBILITY
1392 iterator begin() _NOEXCEPT
1393 {return iterator(this, __get_pointer());}
1394 _LIBCPP_INLINE_VISIBILITY
1395 const_iterator begin() const _NOEXCEPT
1396 {return const_iterator(this, __get_pointer());}
1397 _LIBCPP_INLINE_VISIBILITY
1398 iterator end() _NOEXCEPT
1399 {return iterator(this, __get_pointer() + size());}
1400 _LIBCPP_INLINE_VISIBILITY
1401 const_iterator end() const _NOEXCEPT
1402 {return const_iterator(this, __get_pointer() + size());}
1404 _LIBCPP_INLINE_VISIBILITY
1405 iterator begin() _NOEXCEPT
1406 {return iterator(__get_pointer());}
1407 _LIBCPP_INLINE_VISIBILITY
1408 const_iterator begin() const _NOEXCEPT
1409 {return const_iterator(__get_pointer());}
1410 _LIBCPP_INLINE_VISIBILITY
1411 iterator end() _NOEXCEPT
1412 {return iterator(__get_pointer() + size());}
1413 _LIBCPP_INLINE_VISIBILITY
1414 const_iterator end() const _NOEXCEPT
1415 {return const_iterator(__get_pointer() + size());}
1416 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1417 _LIBCPP_INLINE_VISIBILITY
1418 reverse_iterator rbegin() _NOEXCEPT
1419 {return reverse_iterator(end());}
1420 _LIBCPP_INLINE_VISIBILITY
1421 const_reverse_iterator rbegin() const _NOEXCEPT
1422 {return const_reverse_iterator(end());}
1423 _LIBCPP_INLINE_VISIBILITY
1424 reverse_iterator rend() _NOEXCEPT
1425 {return reverse_iterator(begin());}
1426 _LIBCPP_INLINE_VISIBILITY
1427 const_reverse_iterator rend() const _NOEXCEPT
1428 {return const_reverse_iterator(begin());}
1430 _LIBCPP_INLINE_VISIBILITY
1431 const_iterator cbegin() const _NOEXCEPT
1433 _LIBCPP_INLINE_VISIBILITY
1434 const_iterator cend() const _NOEXCEPT
1436 _LIBCPP_INLINE_VISIBILITY
1437 const_reverse_iterator crbegin() const _NOEXCEPT
1439 _LIBCPP_INLINE_VISIBILITY
1440 const_reverse_iterator crend() const _NOEXCEPT
1443 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
1444 {return __is_long() ? __get_long_size() : __get_short_size();}
1445 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
1446 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
1447 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
1448 {return (__is_long() ? __get_long_cap()
1449 : static_cast<size_type>(__min_cap)) - 1;}
1451 void resize(size_type __n, value_type __c);
1452 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
1454 void reserve(size_type res_arg = 0);
1455 _LIBCPP_INLINE_VISIBILITY
1456 void shrink_to_fit() _NOEXCEPT {reserve();}
1457 _LIBCPP_INLINE_VISIBILITY
1458 void clear() _NOEXCEPT;
1459 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;}
1461 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const;
1462 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos);
1464 const_reference at(size_type __n) const;
1465 reference at(size_type __n);
1467 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
1468 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
1469 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
1470 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1471 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
1472 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1474 _LIBCPP_INLINE_VISIBILITY
1475 basic_string& append(const basic_string& __str);
1476 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
1477 basic_string& append(const value_type* __s, size_type __n);
1478 basic_string& append(const value_type* __s);
1479 basic_string& append(size_type __n, value_type __c);
1480 template<class _InputIterator>
1483 __is_input_iterator <_InputIterator>::value &&
1484 !__is_forward_iterator<_InputIterator>::value,
1487 append(_InputIterator __first, _InputIterator __last);
1488 template<class _ForwardIterator>
1491 __is_forward_iterator<_ForwardIterator>::value,
1494 append(_ForwardIterator __first, _ForwardIterator __last);
1495 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1496 _LIBCPP_INLINE_VISIBILITY
1497 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
1498 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1500 void push_back(value_type __c);
1501 _LIBCPP_INLINE_VISIBILITY
1503 _LIBCPP_INLINE_VISIBILITY reference front();
1504 _LIBCPP_INLINE_VISIBILITY const_reference front() const;
1505 _LIBCPP_INLINE_VISIBILITY reference back();
1506 _LIBCPP_INLINE_VISIBILITY const_reference back() const;
1508 _LIBCPP_INLINE_VISIBILITY
1509 basic_string& assign(const basic_string& __str);
1510 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1511 _LIBCPP_INLINE_VISIBILITY
1512 basic_string& assign(basic_string&& str)
1513 {*this = _VSTD::move(str); return *this;}
1515 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
1516 basic_string& assign(const value_type* __s, size_type __n);
1517 basic_string& assign(const value_type* __s);
1518 basic_string& assign(size_type __n, value_type __c);
1519 template<class _InputIterator>
1522 __is_input_iterator <_InputIterator>::value &&
1523 !__is_forward_iterator<_InputIterator>::value,
1526 assign(_InputIterator __first, _InputIterator __last);
1527 template<class _ForwardIterator>
1530 __is_forward_iterator<_ForwardIterator>::value,
1533 assign(_ForwardIterator __first, _ForwardIterator __last);
1534 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1535 _LIBCPP_INLINE_VISIBILITY
1536 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
1537 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1539 _LIBCPP_INLINE_VISIBILITY
1540 basic_string& insert(size_type __pos1, const basic_string& __str);
1541 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
1542 basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
1543 basic_string& insert(size_type __pos, const value_type* __s);
1544 basic_string& insert(size_type __pos, size_type __n, value_type __c);
1545 iterator insert(const_iterator __pos, value_type __c);
1546 _LIBCPP_INLINE_VISIBILITY
1547 iterator insert(const_iterator __pos, size_type __n, value_type __c);
1548 template<class _InputIterator>
1551 __is_input_iterator <_InputIterator>::value &&
1552 !__is_forward_iterator<_InputIterator>::value,
1555 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
1556 template<class _ForwardIterator>
1559 __is_forward_iterator<_ForwardIterator>::value,
1562 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
1563 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1564 _LIBCPP_INLINE_VISIBILITY
1565 iterator insert(const_iterator __pos, initializer_list<value_type> __il)
1566 {return insert(__pos, __il.begin(), __il.end());}
1567 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1569 basic_string& erase(size_type __pos = 0, size_type __n = npos);
1570 _LIBCPP_INLINE_VISIBILITY
1571 iterator erase(const_iterator __pos);
1572 _LIBCPP_INLINE_VISIBILITY
1573 iterator erase(const_iterator __first, const_iterator __last);
1575 _LIBCPP_INLINE_VISIBILITY
1576 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
1577 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
1578 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
1579 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
1580 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
1581 _LIBCPP_INLINE_VISIBILITY
1582 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
1583 _LIBCPP_INLINE_VISIBILITY
1584 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
1585 _LIBCPP_INLINE_VISIBILITY
1586 basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
1587 _LIBCPP_INLINE_VISIBILITY
1588 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
1589 template<class _InputIterator>
1592 __is_input_iterator<_InputIterator>::value,
1595 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
1596 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1597 _LIBCPP_INLINE_VISIBILITY
1598 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
1599 {return replace(__i1, __i2, __il.begin(), __il.end());}
1600 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1602 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
1603 _LIBCPP_INLINE_VISIBILITY
1604 basic_string substr(size_type __pos = 0, size_type __n = npos) const;
1606 _LIBCPP_INLINE_VISIBILITY
1607 void swap(basic_string& __str)
1608 #if _LIBCPP_STD_VER >= 14
1611 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
1612 __is_nothrow_swappable<allocator_type>::value);
1615 _LIBCPP_INLINE_VISIBILITY
1616 const value_type* c_str() const _NOEXCEPT {return data();}
1617 _LIBCPP_INLINE_VISIBILITY
1618 const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
1620 _LIBCPP_INLINE_VISIBILITY
1621 allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
1623 _LIBCPP_INLINE_VISIBILITY
1624 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1625 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1626 _LIBCPP_INLINE_VISIBILITY
1627 size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1628 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1630 _LIBCPP_INLINE_VISIBILITY
1631 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1632 size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1633 _LIBCPP_INLINE_VISIBILITY
1634 size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1635 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1637 _LIBCPP_INLINE_VISIBILITY
1638 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1639 size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1640 _LIBCPP_INLINE_VISIBILITY
1641 size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1642 _LIBCPP_INLINE_VISIBILITY
1643 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1645 _LIBCPP_INLINE_VISIBILITY
1646 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1647 size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1648 _LIBCPP_INLINE_VISIBILITY
1649 size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1650 _LIBCPP_INLINE_VISIBILITY
1651 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1653 _LIBCPP_INLINE_VISIBILITY
1654 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
1655 size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1656 _LIBCPP_INLINE_VISIBILITY
1657 size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
1658 _LIBCPP_INLINE_VISIBILITY
1659 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
1661 _LIBCPP_INLINE_VISIBILITY
1662 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
1663 size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
1664 _LIBCPP_INLINE_VISIBILITY
1665 size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
1666 _LIBCPP_INLINE_VISIBILITY
1667 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
1669 _LIBCPP_INLINE_VISIBILITY
1670 int compare(const basic_string& __str) const _NOEXCEPT;
1671 _LIBCPP_INLINE_VISIBILITY
1672 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
1673 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
1674 int compare(const value_type* __s) const _NOEXCEPT;
1675 int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
1676 int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
1678 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
1680 _LIBCPP_INLINE_VISIBILITY
1681 bool __is_long() const _NOEXCEPT
1682 {return bool(__r_.first().__s.__size_ & __short_mask);}
1684 #if _LIBCPP_DEBUG_LEVEL >= 2
1686 bool __dereferenceable(const const_iterator* __i) const;
1687 bool __decrementable(const const_iterator* __i) const;
1688 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1689 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1691 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1694 _LIBCPP_INLINE_VISIBILITY
1695 allocator_type& __alloc() _NOEXCEPT
1696 {return __r_.second();}
1697 _LIBCPP_INLINE_VISIBILITY
1698 const allocator_type& __alloc() const _NOEXCEPT
1699 {return __r_.second();}
1701 #ifdef _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 << 1);}
1708 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1711 _LIBCPP_INLINE_VISIBILITY
1712 size_type __get_short_size() const _NOEXCEPT
1713 # if _LIBCPP_BIG_ENDIAN
1714 {return __r_.first().__s.__size_ >> 1;}
1716 {return __r_.first().__s.__size_;}
1719 #else // _LIBCPP_ALTERNATE_STRING_LAYOUT
1721 _LIBCPP_INLINE_VISIBILITY
1722 void __set_short_size(size_type __s) _NOEXCEPT
1723 # if _LIBCPP_BIG_ENDIAN
1724 {__r_.first().__s.__size_ = (unsigned char)(__s);}
1726 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
1729 _LIBCPP_INLINE_VISIBILITY
1730 size_type __get_short_size() const _NOEXCEPT
1731 # if _LIBCPP_BIG_ENDIAN
1732 {return __r_.first().__s.__size_;}
1734 {return __r_.first().__s.__size_ >> 1;}
1737 #endif // _LIBCPP_ALTERNATE_STRING_LAYOUT
1739 _LIBCPP_INLINE_VISIBILITY
1740 void __set_long_size(size_type __s) _NOEXCEPT
1741 {__r_.first().__l.__size_ = __s;}
1742 _LIBCPP_INLINE_VISIBILITY
1743 size_type __get_long_size() const _NOEXCEPT
1744 {return __r_.first().__l.__size_;}
1745 _LIBCPP_INLINE_VISIBILITY
1746 void __set_size(size_type __s) _NOEXCEPT
1747 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
1749 _LIBCPP_INLINE_VISIBILITY
1750 void __set_long_cap(size_type __s) _NOEXCEPT
1751 {__r_.first().__l.__cap_ = __long_mask | __s;}
1752 _LIBCPP_INLINE_VISIBILITY
1753 size_type __get_long_cap() const _NOEXCEPT
1754 {return __r_.first().__l.__cap_ & size_type(~__long_mask);}
1756 _LIBCPP_INLINE_VISIBILITY
1757 void __set_long_pointer(pointer __p) _NOEXCEPT
1758 {__r_.first().__l.__data_ = __p;}
1759 _LIBCPP_INLINE_VISIBILITY
1760 pointer __get_long_pointer() _NOEXCEPT
1761 {return __r_.first().__l.__data_;}
1762 _LIBCPP_INLINE_VISIBILITY
1763 const_pointer __get_long_pointer() const _NOEXCEPT
1764 {return __r_.first().__l.__data_;}
1765 _LIBCPP_INLINE_VISIBILITY
1766 pointer __get_short_pointer() _NOEXCEPT
1767 {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1768 _LIBCPP_INLINE_VISIBILITY
1769 const_pointer __get_short_pointer() const _NOEXCEPT
1770 {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
1771 _LIBCPP_INLINE_VISIBILITY
1772 pointer __get_pointer() _NOEXCEPT
1773 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1774 _LIBCPP_INLINE_VISIBILITY
1775 const_pointer __get_pointer() const _NOEXCEPT
1776 {return __is_long() ? __get_long_pointer() : __get_short_pointer();}
1778 _LIBCPP_INLINE_VISIBILITY
1779 void __zero() _NOEXCEPT
1781 size_type (&__a)[__n_words] = __r_.first().__r.__words;
1782 for (unsigned __i = 0; __i < __n_words; ++__i)
1786 template <size_type __a> static
1787 _LIBCPP_INLINE_VISIBILITY
1788 size_type __align_it(size_type __s) _NOEXCEPT
1789 {return (__s + (__a-1)) & ~(__a-1);}
1790 enum {__alignment = 16};
1791 static _LIBCPP_INLINE_VISIBILITY
1792 size_type __recommend(size_type __s) _NOEXCEPT
1793 {return (__s < __min_cap ? static_cast<size_type>(__min_cap) :
1794 __align_it<sizeof(value_type) < __alignment ?
1795 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
1797 void __init(const value_type* __s, size_type __sz, size_type __reserve);
1798 void __init(const value_type* __s, size_type __sz);
1799 void __init(size_type __n, value_type __c);
1801 template <class _InputIterator>
1804 __is_input_iterator <_InputIterator>::value &&
1805 !__is_forward_iterator<_InputIterator>::value,
1808 __init(_InputIterator __first, _InputIterator __last);
1810 template <class _ForwardIterator>
1813 __is_forward_iterator<_ForwardIterator>::value,
1816 __init(_ForwardIterator __first, _ForwardIterator __last);
1818 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1819 size_type __n_copy, size_type __n_del, size_type __n_add = 0);
1820 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
1821 size_type __n_copy, size_type __n_del,
1822 size_type __n_add, const value_type* __p_new_stuff);
1824 _LIBCPP_INLINE_VISIBILITY
1825 void __erase_to_end(size_type __pos);
1827 _LIBCPP_INLINE_VISIBILITY
1828 void __copy_assign_alloc(const basic_string& __str)
1829 {__copy_assign_alloc(__str, integral_constant<bool,
1830 __alloc_traits::propagate_on_container_copy_assignment::value>());}
1832 _LIBCPP_INLINE_VISIBILITY
1833 void __copy_assign_alloc(const basic_string& __str, true_type)
1835 if (__alloc() != __str.__alloc())
1840 __alloc() = __str.__alloc();
1843 _LIBCPP_INLINE_VISIBILITY
1844 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
1847 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1848 _LIBCPP_INLINE_VISIBILITY
1849 void __move_assign(basic_string& __str, false_type);
1850 _LIBCPP_INLINE_VISIBILITY
1851 void __move_assign(basic_string& __str, true_type)
1852 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
1855 _LIBCPP_INLINE_VISIBILITY
1857 __move_assign_alloc(basic_string& __str)
1859 !__alloc_traits::propagate_on_container_move_assignment::value ||
1860 is_nothrow_move_assignable<allocator_type>::value)
1861 {__move_assign_alloc(__str, integral_constant<bool,
1862 __alloc_traits::propagate_on_container_move_assignment::value>());}
1864 _LIBCPP_INLINE_VISIBILITY
1865 void __move_assign_alloc(basic_string& __c, true_type)
1866 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
1868 __alloc() = _VSTD::move(__c.__alloc());
1871 _LIBCPP_INLINE_VISIBILITY
1872 void __move_assign_alloc(basic_string&, false_type)
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)
1940 #if _LIBCPP_STD_VER <= 14
1941 _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
1947 #if _LIBCPP_DEBUG_LEVEL >= 2
1948 __get_db()->__insert_c(this);
1953 template <class _CharT, class _Traits, class _Allocator>
1955 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
1957 if (__reserve > max_size())
1958 this->__throw_length_error();
1960 if (__reserve < __min_cap)
1962 __set_short_size(__sz);
1963 __p = __get_short_pointer();
1967 size_type __cap = __recommend(__reserve);
1968 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1969 __set_long_pointer(__p);
1970 __set_long_cap(__cap+1);
1971 __set_long_size(__sz);
1973 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1974 traits_type::assign(__p[__sz], value_type());
1977 template <class _CharT, class _Traits, class _Allocator>
1979 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
1981 if (__sz > max_size())
1982 this->__throw_length_error();
1984 if (__sz < __min_cap)
1986 __set_short_size(__sz);
1987 __p = __get_short_pointer();
1991 size_type __cap = __recommend(__sz);
1992 __p = __alloc_traits::allocate(__alloc(), __cap+1);
1993 __set_long_pointer(__p);
1994 __set_long_cap(__cap+1);
1995 __set_long_size(__sz);
1997 traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
1998 traits_type::assign(__p[__sz], value_type());
2001 template <class _CharT, class _Traits, class _Allocator>
2002 inline _LIBCPP_INLINE_VISIBILITY
2003 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s)
2005 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
2006 __init(__s, traits_type::length(__s));
2007 #if _LIBCPP_DEBUG_LEVEL >= 2
2008 __get_db()->__insert_c(this);
2012 template <class _CharT, class _Traits, class _Allocator>
2013 inline _LIBCPP_INLINE_VISIBILITY
2014 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, const allocator_type& __a)
2017 _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
2018 __init(__s, traits_type::length(__s));
2019 #if _LIBCPP_DEBUG_LEVEL >= 2
2020 __get_db()->__insert_c(this);
2024 template <class _CharT, class _Traits, class _Allocator>
2025 inline _LIBCPP_INLINE_VISIBILITY
2026 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n)
2028 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
2030 #if _LIBCPP_DEBUG_LEVEL >= 2
2031 __get_db()->__insert_c(this);
2035 template <class _CharT, class _Traits, class _Allocator>
2036 inline _LIBCPP_INLINE_VISIBILITY
2037 basic_string<_CharT, _Traits, _Allocator>::basic_string(const value_type* __s, size_type __n, const allocator_type& __a)
2040 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
2042 #if _LIBCPP_DEBUG_LEVEL >= 2
2043 __get_db()->__insert_c(this);
2047 template <class _CharT, class _Traits, class _Allocator>
2048 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
2049 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc()))
2051 if (!__str.__is_long())
2052 __r_.first().__r = __str.__r_.first().__r;
2054 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
2055 #if _LIBCPP_DEBUG_LEVEL >= 2
2056 __get_db()->__insert_c(this);
2060 template <class _CharT, class _Traits, class _Allocator>
2061 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a)
2064 if (!__str.__is_long())
2065 __r_.first().__r = __str.__r_.first().__r;
2067 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
2068 #if _LIBCPP_DEBUG_LEVEL >= 2
2069 __get_db()->__insert_c(this);
2073 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2075 template <class _CharT, class _Traits, class _Allocator>
2076 inline _LIBCPP_INLINE_VISIBILITY
2077 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
2078 #if _LIBCPP_STD_VER <= 14
2079 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
2083 : __r_(_VSTD::move(__str.__r_))
2086 #if _LIBCPP_DEBUG_LEVEL >= 2
2087 __get_db()->__insert_c(this);
2089 __get_db()->swap(this, &__str);
2093 template <class _CharT, class _Traits, class _Allocator>
2094 inline _LIBCPP_INLINE_VISIBILITY
2095 basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
2098 if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
2099 __init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
2102 __r_.first().__r = __str.__r_.first().__r;
2105 #if _LIBCPP_DEBUG_LEVEL >= 2
2106 __get_db()->__insert_c(this);
2108 __get_db()->swap(this, &__str);
2112 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2114 template <class _CharT, class _Traits, class _Allocator>
2116 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
2118 if (__n > max_size())
2119 this->__throw_length_error();
2121 if (__n < __min_cap)
2123 __set_short_size(__n);
2124 __p = __get_short_pointer();
2128 size_type __cap = __recommend(__n);
2129 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2130 __set_long_pointer(__p);
2131 __set_long_cap(__cap+1);
2132 __set_long_size(__n);
2134 traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
2135 traits_type::assign(__p[__n], value_type());
2138 template <class _CharT, class _Traits, class _Allocator>
2139 inline _LIBCPP_INLINE_VISIBILITY
2140 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c)
2143 #if _LIBCPP_DEBUG_LEVEL >= 2
2144 __get_db()->__insert_c(this);
2148 template <class _CharT, class _Traits, class _Allocator>
2149 inline _LIBCPP_INLINE_VISIBILITY
2150 basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a)
2154 #if _LIBCPP_DEBUG_LEVEL >= 2
2155 __get_db()->__insert_c(this);
2159 template <class _CharT, class _Traits, class _Allocator>
2160 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n,
2161 const allocator_type& __a)
2164 size_type __str_sz = __str.size();
2165 if (__pos > __str_sz)
2166 this->__throw_out_of_range();
2167 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
2168 #if _LIBCPP_DEBUG_LEVEL >= 2
2169 __get_db()->__insert_c(this);
2173 template <class _CharT, class _Traits, class _Allocator>
2174 template <class _InputIterator>
2177 __is_input_iterator <_InputIterator>::value &&
2178 !__is_forward_iterator<_InputIterator>::value,
2181 basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
2184 #ifndef _LIBCPP_NO_EXCEPTIONS
2187 #endif // _LIBCPP_NO_EXCEPTIONS
2188 for (; __first != __last; ++__first)
2189 push_back(*__first);
2190 #ifndef _LIBCPP_NO_EXCEPTIONS
2195 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2198 #endif // _LIBCPP_NO_EXCEPTIONS
2201 template <class _CharT, class _Traits, class _Allocator>
2202 template <class _ForwardIterator>
2205 __is_forward_iterator<_ForwardIterator>::value,
2208 basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
2210 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
2211 if (__sz > max_size())
2212 this->__throw_length_error();
2214 if (__sz < __min_cap)
2216 __set_short_size(__sz);
2217 __p = __get_short_pointer();
2221 size_type __cap = __recommend(__sz);
2222 __p = __alloc_traits::allocate(__alloc(), __cap+1);
2223 __set_long_pointer(__p);
2224 __set_long_cap(__cap+1);
2225 __set_long_size(__sz);
2227 for (; __first != __last; ++__first, (void) ++__p)
2228 traits_type::assign(*__p, *__first);
2229 traits_type::assign(*__p, value_type());
2232 template <class _CharT, class _Traits, class _Allocator>
2233 template<class _InputIterator>
2234 inline _LIBCPP_INLINE_VISIBILITY
2235 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
2237 __init(__first, __last);
2238 #if _LIBCPP_DEBUG_LEVEL >= 2
2239 __get_db()->__insert_c(this);
2243 template <class _CharT, class _Traits, class _Allocator>
2244 template<class _InputIterator>
2245 inline _LIBCPP_INLINE_VISIBILITY
2246 basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
2247 const allocator_type& __a)
2250 __init(__first, __last);
2251 #if _LIBCPP_DEBUG_LEVEL >= 2
2252 __get_db()->__insert_c(this);
2256 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2258 template <class _CharT, class _Traits, class _Allocator>
2259 inline _LIBCPP_INLINE_VISIBILITY
2260 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il)
2262 __init(__il.begin(), __il.end());
2263 #if _LIBCPP_DEBUG_LEVEL >= 2
2264 __get_db()->__insert_c(this);
2268 template <class _CharT, class _Traits, class _Allocator>
2269 inline _LIBCPP_INLINE_VISIBILITY
2270 basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a)
2273 __init(__il.begin(), __il.end());
2274 #if _LIBCPP_DEBUG_LEVEL >= 2
2275 __get_db()->__insert_c(this);
2279 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2281 template <class _CharT, class _Traits, class _Allocator>
2282 basic_string<_CharT, _Traits, _Allocator>::~basic_string()
2284 #if _LIBCPP_DEBUG_LEVEL >= 2
2285 __get_db()->__erase_c(this);
2288 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
2291 template <class _CharT, class _Traits, class _Allocator>
2293 basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
2294 (size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2295 size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
2297 size_type __ms = max_size();
2298 if (__delta_cap > __ms - __old_cap - 1)
2299 this->__throw_length_error();
2300 pointer __old_p = __get_pointer();
2301 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2302 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2304 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2305 __invalidate_all_iterators();
2307 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2308 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2310 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
2311 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2312 if (__sec_cp_sz != 0)
2313 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2314 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
2315 if (__old_cap+1 != __min_cap)
2316 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2317 __set_long_pointer(__p);
2318 __set_long_cap(__cap+1);
2319 __old_sz = __n_copy + __n_add + __sec_cp_sz;
2320 __set_long_size(__old_sz);
2321 traits_type::assign(__p[__old_sz], value_type());
2324 template <class _CharT, class _Traits, class _Allocator>
2326 basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
2327 size_type __n_copy, size_type __n_del, size_type __n_add)
2329 size_type __ms = max_size();
2330 if (__delta_cap > __ms - __old_cap)
2331 this->__throw_length_error();
2332 pointer __old_p = __get_pointer();
2333 size_type __cap = __old_cap < __ms / 2 - __alignment ?
2334 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
2336 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
2337 __invalidate_all_iterators();
2339 traits_type::copy(_VSTD::__to_raw_pointer(__p),
2340 _VSTD::__to_raw_pointer(__old_p), __n_copy);
2341 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
2342 if (__sec_cp_sz != 0)
2343 traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
2344 _VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
2346 if (__old_cap+1 != __min_cap)
2347 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
2348 __set_long_pointer(__p);
2349 __set_long_cap(__cap+1);
2354 template <class _CharT, class _Traits, class _Allocator>
2355 basic_string<_CharT, _Traits, _Allocator>&
2356 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
2358 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
2359 size_type __cap = capacity();
2362 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2363 traits_type::move(__p, __s, __n);
2364 traits_type::assign(__p[__n], value_type());
2366 __invalidate_iterators_past(__n);
2370 size_type __sz = size();
2371 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
2376 template <class _CharT, class _Traits, class _Allocator>
2377 basic_string<_CharT, _Traits, _Allocator>&
2378 basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
2380 size_type __cap = capacity();
2383 size_type __sz = size();
2384 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2387 __invalidate_iterators_past(__n);
2388 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2389 traits_type::assign(__p, __n, __c);
2390 traits_type::assign(__p[__n], value_type());
2395 template <class _CharT, class _Traits, class _Allocator>
2396 basic_string<_CharT, _Traits, _Allocator>&
2397 basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
2402 __p = __get_long_pointer();
2407 __p = __get_short_pointer();
2408 __set_short_size(1);
2410 traits_type::assign(*__p, __c);
2411 traits_type::assign(*++__p, value_type());
2412 __invalidate_iterators_past(1);
2416 template <class _CharT, class _Traits, class _Allocator>
2417 basic_string<_CharT, _Traits, _Allocator>&
2418 basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
2422 __copy_assign_alloc(__str);
2428 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2430 template <class _CharT, class _Traits, class _Allocator>
2431 inline _LIBCPP_INLINE_VISIBILITY
2433 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
2435 if (__alloc() != __str.__alloc())
2438 __move_assign(__str, true_type());
2441 template <class _CharT, class _Traits, class _Allocator>
2442 inline _LIBCPP_INLINE_VISIBILITY
2444 basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
2445 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
2449 __r_.first() = __str.__r_.first();
2450 __move_assign_alloc(__str);
2454 template <class _CharT, class _Traits, class _Allocator>
2455 inline _LIBCPP_INLINE_VISIBILITY
2456 basic_string<_CharT, _Traits, _Allocator>&
2457 basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
2458 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
2459 is_nothrow_move_assignable<allocator_type>::value)
2461 __move_assign(__str, integral_constant<bool,
2462 __alloc_traits::propagate_on_container_move_assignment::value>());
2468 template <class _CharT, class _Traits, class _Allocator>
2469 template<class _InputIterator>
2472 __is_input_iterator <_InputIterator>::value &&
2473 !__is_forward_iterator<_InputIterator>::value,
2474 basic_string<_CharT, _Traits, _Allocator>&
2476 basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
2479 for (; __first != __last; ++__first)
2480 push_back(*__first);
2484 template <class _CharT, class _Traits, class _Allocator>
2485 template<class _ForwardIterator>
2488 __is_forward_iterator<_ForwardIterator>::value,
2489 basic_string<_CharT, _Traits, _Allocator>&
2491 basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
2493 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2494 size_type __cap = capacity();
2497 size_type __sz = size();
2498 __grow_by(__cap, __n - __cap, __sz, 0, __sz);
2501 __invalidate_iterators_past(__n);
2502 pointer __p = __get_pointer();
2503 for (; __first != __last; ++__first, ++__p)
2504 traits_type::assign(*__p, *__first);
2505 traits_type::assign(*__p, value_type());
2510 template <class _CharT, class _Traits, class _Allocator>
2511 inline _LIBCPP_INLINE_VISIBILITY
2512 basic_string<_CharT, _Traits, _Allocator>&
2513 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str)
2515 return assign(__str.data(), __str.size());
2518 template <class _CharT, class _Traits, class _Allocator>
2519 basic_string<_CharT, _Traits, _Allocator>&
2520 basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
2522 size_type __sz = __str.size();
2524 this->__throw_out_of_range();
2525 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2528 template <class _CharT, class _Traits, class _Allocator>
2529 basic_string<_CharT, _Traits, _Allocator>&
2530 basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
2532 _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
2533 return assign(__s, traits_type::length(__s));
2538 template <class _CharT, class _Traits, class _Allocator>
2539 basic_string<_CharT, _Traits, _Allocator>&
2540 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
2542 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
2543 size_type __cap = capacity();
2544 size_type __sz = size();
2545 if (__cap - __sz >= __n)
2549 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2550 traits_type::copy(__p + __sz, __s, __n);
2553 traits_type::assign(__p[__sz], value_type());
2557 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
2561 template <class _CharT, class _Traits, class _Allocator>
2562 basic_string<_CharT, _Traits, _Allocator>&
2563 basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
2567 size_type __cap = capacity();
2568 size_type __sz = size();
2569 if (__cap - __sz < __n)
2570 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2571 pointer __p = __get_pointer();
2572 traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
2575 traits_type::assign(__p[__sz], value_type());
2580 template <class _CharT, class _Traits, class _Allocator>
2582 basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
2584 bool __is_short = !__is_long();
2589 __cap = __min_cap - 1;
2590 __sz = __get_short_size();
2594 __cap = __get_long_cap() - 1;
2595 __sz = __get_long_size();
2599 __grow_by(__cap, 1, __sz, __sz, 0);
2600 __is_short = !__is_long();
2605 __p = __get_short_pointer() + __sz;
2606 __set_short_size(__sz+1);
2610 __p = __get_long_pointer() + __sz;
2611 __set_long_size(__sz+1);
2613 traits_type::assign(*__p, __c);
2614 traits_type::assign(*++__p, value_type());
2617 template <class _CharT, class _Traits, class _Allocator>
2618 template<class _InputIterator>
2621 __is_input_iterator <_InputIterator>::value &&
2622 !__is_forward_iterator<_InputIterator>::value,
2623 basic_string<_CharT, _Traits, _Allocator>&
2625 basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last)
2627 for (; __first != __last; ++__first)
2628 push_back(*__first);
2632 template <class _CharT, class _Traits, class _Allocator>
2633 template<class _ForwardIterator>
2636 __is_forward_iterator<_ForwardIterator>::value,
2637 basic_string<_CharT, _Traits, _Allocator>&
2639 basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last)
2641 size_type __sz = size();
2642 size_type __cap = capacity();
2643 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2646 if (__cap - __sz < __n)
2647 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
2648 pointer __p = __get_pointer() + __sz;
2649 for (; __first != __last; ++__p, ++__first)
2650 traits_type::assign(*__p, *__first);
2651 traits_type::assign(*__p, value_type());
2652 __set_size(__sz + __n);
2657 template <class _CharT, class _Traits, class _Allocator>
2658 inline _LIBCPP_INLINE_VISIBILITY
2659 basic_string<_CharT, _Traits, _Allocator>&
2660 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
2662 return append(__str.data(), __str.size());
2665 template <class _CharT, class _Traits, class _Allocator>
2666 basic_string<_CharT, _Traits, _Allocator>&
2667 basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
2669 size_type __sz = __str.size();
2671 this->__throw_out_of_range();
2672 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
2675 template <class _CharT, class _Traits, class _Allocator>
2676 basic_string<_CharT, _Traits, _Allocator>&
2677 basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
2679 _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
2680 return append(__s, traits_type::length(__s));
2685 template <class _CharT, class _Traits, class _Allocator>
2686 basic_string<_CharT, _Traits, _Allocator>&
2687 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
2689 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
2690 size_type __sz = size();
2692 this->__throw_out_of_range();
2693 size_type __cap = capacity();
2694 if (__cap - __sz >= __n)
2698 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2699 size_type __n_move = __sz - __pos;
2702 if (__p + __pos <= __s && __s < __p + __sz)
2704 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2706 traits_type::move(__p + __pos, __s, __n);
2709 traits_type::assign(__p[__sz], value_type());
2713 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
2717 template <class _CharT, class _Traits, class _Allocator>
2718 basic_string<_CharT, _Traits, _Allocator>&
2719 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
2721 size_type __sz = size();
2723 this->__throw_out_of_range();
2726 size_type __cap = capacity();
2728 if (__cap - __sz >= __n)
2730 __p = _VSTD::__to_raw_pointer(__get_pointer());
2731 size_type __n_move = __sz - __pos;
2733 traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
2737 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
2738 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2740 traits_type::assign(__p + __pos, __n, __c);
2743 traits_type::assign(__p[__sz], value_type());
2748 template <class _CharT, class _Traits, class _Allocator>
2749 template<class _InputIterator>
2752 __is_input_iterator <_InputIterator>::value &&
2753 !__is_forward_iterator<_InputIterator>::value,
2754 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2756 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
2758 #if _LIBCPP_DEBUG_LEVEL >= 2
2759 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2760 "string::insert(iterator, range) called with an iterator not"
2761 " referring to this string");
2763 size_type __old_sz = size();
2764 difference_type __ip = __pos - begin();
2765 for (; __first != __last; ++__first)
2766 push_back(*__first);
2767 pointer __p = __get_pointer();
2768 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size());
2769 #if _LIBCPP_DEBUG_LEVEL >= 2
2770 return iterator(this, __p + __ip);
2772 return iterator(__p + __ip);
2776 template <class _CharT, class _Traits, class _Allocator>
2777 template<class _ForwardIterator>
2780 __is_forward_iterator<_ForwardIterator>::value,
2781 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2783 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
2785 #if _LIBCPP_DEBUG_LEVEL >= 2
2786 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2787 "string::insert(iterator, range) called with an iterator not"
2788 " referring to this string");
2790 size_type __ip = static_cast<size_type>(__pos - begin());
2791 size_type __sz = size();
2792 size_type __cap = capacity();
2793 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
2797 if (__cap - __sz >= __n)
2799 __p = _VSTD::__to_raw_pointer(__get_pointer());
2800 size_type __n_move = __sz - __ip;
2802 traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
2806 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
2807 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2811 traits_type::assign(__p[__sz], value_type());
2812 for (__p += __ip; __first != __last; ++__p, ++__first)
2813 traits_type::assign(*__p, *__first);
2815 return begin() + __ip;
2818 template <class _CharT, class _Traits, class _Allocator>
2819 inline _LIBCPP_INLINE_VISIBILITY
2820 basic_string<_CharT, _Traits, _Allocator>&
2821 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
2823 return insert(__pos1, __str.data(), __str.size());
2826 template <class _CharT, class _Traits, class _Allocator>
2827 basic_string<_CharT, _Traits, _Allocator>&
2828 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
2829 size_type __pos2, size_type __n)
2831 size_type __str_sz = __str.size();
2832 if (__pos2 > __str_sz)
2833 this->__throw_out_of_range();
2834 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
2837 template <class _CharT, class _Traits, class _Allocator>
2838 basic_string<_CharT, _Traits, _Allocator>&
2839 basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
2841 _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
2842 return insert(__pos, __s, traits_type::length(__s));
2845 template <class _CharT, class _Traits, class _Allocator>
2846 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2847 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
2849 size_type __ip = static_cast<size_type>(__pos - begin());
2850 size_type __sz = size();
2851 size_type __cap = capacity();
2855 __grow_by(__cap, 1, __sz, __ip, 0, 1);
2856 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2860 __p = _VSTD::__to_raw_pointer(__get_pointer());
2861 size_type __n_move = __sz - __ip;
2863 traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
2865 traits_type::assign(__p[__ip], __c);
2866 traits_type::assign(__p[++__sz], value_type());
2868 return begin() + static_cast<difference_type>(__ip);
2871 template <class _CharT, class _Traits, class _Allocator>
2872 inline _LIBCPP_INLINE_VISIBILITY
2873 typename basic_string<_CharT, _Traits, _Allocator>::iterator
2874 basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
2876 #if _LIBCPP_DEBUG_LEVEL >= 2
2877 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
2878 "string::insert(iterator, n, value) called with an iterator not"
2879 " referring to this string");
2881 difference_type __p = __pos - begin();
2882 insert(static_cast<size_type>(__p), __n, __c);
2883 return begin() + __p;
2888 template <class _CharT, class _Traits, class _Allocator>
2889 basic_string<_CharT, _Traits, _Allocator>&
2890 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
2892 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
2893 size_type __sz = size();
2895 this->__throw_out_of_range();
2896 __n1 = _VSTD::min(__n1, __sz - __pos);
2897 size_type __cap = capacity();
2898 if (__cap - __sz + __n1 >= __n2)
2900 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
2903 size_type __n_move = __sz - __pos - __n1;
2908 traits_type::move(__p + __pos, __s, __n2);
2909 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2912 if (__p + __pos < __s && __s < __p + __sz)
2914 if (__p + __pos + __n1 <= __s)
2916 else // __p + __pos < __s < __p + __pos + __n1
2918 traits_type::move(__p + __pos, __s, __n1);
2925 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2928 traits_type::move(__p + __pos, __s, __n2);
2930 __sz += __n2 - __n1;
2932 __invalidate_iterators_past(__sz);
2933 traits_type::assign(__p[__sz], value_type());
2936 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
2940 template <class _CharT, class _Traits, class _Allocator>
2941 basic_string<_CharT, _Traits, _Allocator>&
2942 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
2944 size_type __sz = size();
2946 this->__throw_out_of_range();
2947 __n1 = _VSTD::min(__n1, __sz - __pos);
2948 size_type __cap = capacity();
2950 if (__cap - __sz + __n1 >= __n2)
2952 __p = _VSTD::__to_raw_pointer(__get_pointer());
2955 size_type __n_move = __sz - __pos - __n1;
2957 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
2962 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
2963 __p = _VSTD::__to_raw_pointer(__get_long_pointer());
2965 traits_type::assign(__p + __pos, __n2, __c);
2966 __sz += __n2 - __n1;
2968 __invalidate_iterators_past(__sz);
2969 traits_type::assign(__p[__sz], value_type());
2973 template <class _CharT, class _Traits, class _Allocator>
2974 template<class _InputIterator>
2977 __is_input_iterator<_InputIterator>::value,
2978 basic_string<_CharT, _Traits, _Allocator>&
2980 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
2981 _InputIterator __j1, _InputIterator __j2)
2983 for (; true; ++__i1, ++__j1)
2988 insert(__i1, __j1, __j2);
2996 traits_type::assign(const_cast<value_type&>(*__i1), *__j1);
3001 template <class _CharT, class _Traits, class _Allocator>
3002 inline _LIBCPP_INLINE_VISIBILITY
3003 basic_string<_CharT, _Traits, _Allocator>&
3004 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
3006 return replace(__pos1, __n1, __str.data(), __str.size());
3009 template <class _CharT, class _Traits, class _Allocator>
3010 basic_string<_CharT, _Traits, _Allocator>&
3011 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
3012 size_type __pos2, size_type __n2)
3014 size_type __str_sz = __str.size();
3015 if (__pos2 > __str_sz)
3016 this->__throw_out_of_range();
3017 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
3020 template <class _CharT, class _Traits, class _Allocator>
3021 basic_string<_CharT, _Traits, _Allocator>&
3022 basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
3024 _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
3025 return replace(__pos, __n1, __s, traits_type::length(__s));
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 basic_string& __str)
3033 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
3034 __str.data(), __str.size());
3037 template <class _CharT, class _Traits, class _Allocator>
3038 inline _LIBCPP_INLINE_VISIBILITY
3039 basic_string<_CharT, _Traits, _Allocator>&
3040 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
3042 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
3045 template <class _CharT, class _Traits, class _Allocator>
3046 inline _LIBCPP_INLINE_VISIBILITY
3047 basic_string<_CharT, _Traits, _Allocator>&
3048 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
3050 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
3053 template <class _CharT, class _Traits, class _Allocator>
3054 inline _LIBCPP_INLINE_VISIBILITY
3055 basic_string<_CharT, _Traits, _Allocator>&
3056 basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
3058 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
3063 template <class _CharT, class _Traits, class _Allocator>
3064 basic_string<_CharT, _Traits, _Allocator>&
3065 basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
3067 size_type __sz = size();
3069 this->__throw_out_of_range();
3072 value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
3073 __n = _VSTD::min(__n, __sz - __pos);
3074 size_type __n_move = __sz - __pos - __n;
3076 traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
3079 __invalidate_iterators_past(__sz);
3080 traits_type::assign(__p[__sz], value_type());
3085 template <class _CharT, class _Traits, class _Allocator>
3086 inline _LIBCPP_INLINE_VISIBILITY
3087 typename basic_string<_CharT, _Traits, _Allocator>::iterator
3088 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
3090 #if _LIBCPP_DEBUG_LEVEL >= 2
3091 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
3092 "string::erase(iterator) called with an iterator not"
3093 " referring to this string");
3095 _LIBCPP_ASSERT(__pos != end(),
3096 "string::erase(iterator) called with a non-dereferenceable iterator");
3097 iterator __b = begin();
3098 size_type __r = static_cast<size_type>(__pos - __b);
3100 return __b + static_cast<difference_type>(__r);
3103 template <class _CharT, class _Traits, class _Allocator>
3104 inline _LIBCPP_INLINE_VISIBILITY
3105 typename basic_string<_CharT, _Traits, _Allocator>::iterator
3106 basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
3108 #if _LIBCPP_DEBUG_LEVEL >= 2
3109 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
3110 "string::erase(iterator, iterator) called with an iterator not"
3111 " referring to this string");
3113 _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
3114 iterator __b = begin();
3115 size_type __r = static_cast<size_type>(__first - __b);
3116 erase(__r, static_cast<size_type>(__last - __first));
3117 return __b + static_cast<difference_type>(__r);
3120 template <class _CharT, class _Traits, class _Allocator>
3121 inline _LIBCPP_INLINE_VISIBILITY
3123 basic_string<_CharT, _Traits, _Allocator>::pop_back()
3125 _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
3129 __sz = __get_long_size() - 1;
3130 __set_long_size(__sz);
3131 traits_type::assign(*(__get_long_pointer() + __sz), value_type());
3135 __sz = __get_short_size() - 1;
3136 __set_short_size(__sz);
3137 traits_type::assign(*(__get_short_pointer() + __sz), value_type());
3139 __invalidate_iterators_past(__sz);
3142 template <class _CharT, class _Traits, class _Allocator>
3143 inline _LIBCPP_INLINE_VISIBILITY
3145 basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
3147 __invalidate_all_iterators();
3150 traits_type::assign(*__get_long_pointer(), value_type());
3155 traits_type::assign(*__get_short_pointer(), value_type());
3156 __set_short_size(0);
3160 template <class _CharT, class _Traits, class _Allocator>
3161 inline _LIBCPP_INLINE_VISIBILITY
3163 basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
3167 traits_type::assign(*(__get_long_pointer() + __pos), value_type());
3168 __set_long_size(__pos);
3172 traits_type::assign(*(__get_short_pointer() + __pos), value_type());
3173 __set_short_size(__pos);
3175 __invalidate_iterators_past(__pos);
3178 template <class _CharT, class _Traits, class _Allocator>
3180 basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
3182 size_type __sz = size();
3184 append(__n - __sz, __c);
3186 __erase_to_end(__n);
3189 template <class _CharT, class _Traits, class _Allocator>
3190 inline _LIBCPP_INLINE_VISIBILITY
3191 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3192 basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
3194 size_type __m = __alloc_traits::max_size(__alloc());
3195 #if _LIBCPP_BIG_ENDIAN
3196 return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
3198 return __m - __alignment;
3202 template <class _CharT, class _Traits, class _Allocator>
3204 basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
3206 if (__res_arg > max_size())
3207 this->__throw_length_error();
3208 size_type __cap = capacity();
3209 size_type __sz = size();
3210 __res_arg = _VSTD::max(__res_arg, __sz);
3211 __res_arg = __recommend(__res_arg);
3212 if (__res_arg != __cap)
3214 pointer __new_data, __p;
3215 bool __was_long, __now_long;
3216 if (__res_arg == __min_cap - 1)
3220 __new_data = __get_short_pointer();
3221 __p = __get_long_pointer();
3225 if (__res_arg > __cap)
3226 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3229 #ifndef _LIBCPP_NO_EXCEPTIONS
3232 #endif // _LIBCPP_NO_EXCEPTIONS
3233 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
3234 #ifndef _LIBCPP_NO_EXCEPTIONS
3240 #else // _LIBCPP_NO_EXCEPTIONS
3241 if (__new_data == nullptr)
3243 #endif // _LIBCPP_NO_EXCEPTIONS
3246 __was_long = __is_long();
3247 __p = __get_pointer();
3249 traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
3250 _VSTD::__to_raw_pointer(__p), size()+1);
3252 __alloc_traits::deallocate(__alloc(), __p, __cap+1);
3255 __set_long_cap(__res_arg+1);
3256 __set_long_size(__sz);
3257 __set_long_pointer(__new_data);
3260 __set_short_size(__sz);
3261 __invalidate_all_iterators();
3265 template <class _CharT, class _Traits, class _Allocator>
3266 inline _LIBCPP_INLINE_VISIBILITY
3267 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3268 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const
3270 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3271 return *(data() + __pos);
3274 template <class _CharT, class _Traits, class _Allocator>
3275 inline _LIBCPP_INLINE_VISIBILITY
3276 typename basic_string<_CharT, _Traits, _Allocator>::reference
3277 basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos)
3279 _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
3280 return *(__get_pointer() + __pos);
3283 template <class _CharT, class _Traits, class _Allocator>
3284 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3285 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
3288 this->__throw_out_of_range();
3289 return (*this)[__n];
3292 template <class _CharT, class _Traits, class _Allocator>
3293 typename basic_string<_CharT, _Traits, _Allocator>::reference
3294 basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
3297 this->__throw_out_of_range();
3298 return (*this)[__n];
3301 template <class _CharT, class _Traits, class _Allocator>
3302 inline _LIBCPP_INLINE_VISIBILITY
3303 typename basic_string<_CharT, _Traits, _Allocator>::reference
3304 basic_string<_CharT, _Traits, _Allocator>::front()
3306 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3307 return *__get_pointer();
3310 template <class _CharT, class _Traits, class _Allocator>
3311 inline _LIBCPP_INLINE_VISIBILITY
3312 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3313 basic_string<_CharT, _Traits, _Allocator>::front() const
3315 _LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
3319 template <class _CharT, class _Traits, class _Allocator>
3320 inline _LIBCPP_INLINE_VISIBILITY
3321 typename basic_string<_CharT, _Traits, _Allocator>::reference
3322 basic_string<_CharT, _Traits, _Allocator>::back()
3324 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3325 return *(__get_pointer() + size() - 1);
3328 template <class _CharT, class _Traits, class _Allocator>
3329 inline _LIBCPP_INLINE_VISIBILITY
3330 typename basic_string<_CharT, _Traits, _Allocator>::const_reference
3331 basic_string<_CharT, _Traits, _Allocator>::back() const
3333 _LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
3334 return *(data() + size() - 1);
3337 template <class _CharT, class _Traits, class _Allocator>
3338 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3339 basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
3341 size_type __sz = size();
3343 this->__throw_out_of_range();
3344 size_type __rlen = _VSTD::min(__n, __sz - __pos);
3345 traits_type::copy(__s, data() + __pos, __rlen);
3349 template <class _CharT, class _Traits, class _Allocator>
3350 inline _LIBCPP_INLINE_VISIBILITY
3351 basic_string<_CharT, _Traits, _Allocator>
3352 basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
3354 return basic_string(*this, __pos, __n, __alloc());
3357 template <class _CharT, class _Traits, class _Allocator>
3358 inline _LIBCPP_INLINE_VISIBILITY
3360 basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
3361 #if _LIBCPP_STD_VER >= 14
3364 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
3365 __is_nothrow_swappable<allocator_type>::value)
3368 #if _LIBCPP_DEBUG_LEVEL >= 2
3370 __get_db()->__invalidate_all(this);
3371 if (!__str.__is_long())
3372 __get_db()->__invalidate_all(&__str);
3373 __get_db()->swap(this, &__str);
3375 _VSTD::swap(__r_.first(), __str.__r_.first());
3376 __swap_allocator(__alloc(), __str.__alloc());
3381 template <class _Traits>
3382 struct _LIBCPP_HIDDEN __traits_eq
3384 typedef typename _Traits::char_type char_type;
3385 _LIBCPP_INLINE_VISIBILITY
3386 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
3387 {return _Traits::eq(__x, __y);}
3390 template<class _CharT, class _Traits, class _Allocator>
3391 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3392 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3394 size_type __n) const _NOEXCEPT
3396 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
3397 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3398 (data(), size(), __s, __pos, __n);
3401 template<class _CharT, class _Traits, class _Allocator>
3402 inline _LIBCPP_INLINE_VISIBILITY
3403 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3404 basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
3405 size_type __pos) const _NOEXCEPT
3407 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3408 (data(), size(), __str.data(), __pos, __str.size());
3411 template<class _CharT, class _Traits, class _Allocator>
3412 inline _LIBCPP_INLINE_VISIBILITY
3413 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3414 basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3415 size_type __pos) const _NOEXCEPT
3417 _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
3418 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3419 (data(), size(), __s, __pos, traits_type::length(__s));
3422 template<class _CharT, class _Traits, class _Allocator>
3423 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3424 basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
3425 size_type __pos) const _NOEXCEPT
3427 return _VSTD::__str_find<value_type, size_type, traits_type, npos>
3428 (data(), size(), __c, __pos);
3433 template<class _CharT, class _Traits, class _Allocator>
3434 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3435 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3437 size_type __n) const _NOEXCEPT
3439 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
3440 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3441 (data(), size(), __s, __pos, __n);
3444 template<class _CharT, class _Traits, class _Allocator>
3445 inline _LIBCPP_INLINE_VISIBILITY
3446 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3447 basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
3448 size_type __pos) const _NOEXCEPT
3450 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3451 (data(), size(), __str.data(), __pos, __str.size());
3454 template<class _CharT, class _Traits, class _Allocator>
3455 inline _LIBCPP_INLINE_VISIBILITY
3456 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3457 basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3458 size_type __pos) const _NOEXCEPT
3460 _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
3461 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3462 (data(), size(), __s, __pos, traits_type::length(__s));
3465 template<class _CharT, class _Traits, class _Allocator>
3466 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3467 basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
3468 size_type __pos) const _NOEXCEPT
3470 return _VSTD::__str_rfind<value_type, size_type, traits_type, npos>
3471 (data(), size(), __c, __pos);
3476 template<class _CharT, class _Traits, class _Allocator>
3477 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3478 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3480 size_type __n) const _NOEXCEPT
3482 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
3483 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
3484 (data(), size(), __s, __pos, __n);
3487 template<class _CharT, class _Traits, class _Allocator>
3488 inline _LIBCPP_INLINE_VISIBILITY
3489 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3490 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
3491 size_type __pos) const _NOEXCEPT
3493 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
3494 (data(), size(), __str.data(), __pos, __str.size());
3497 template<class _CharT, class _Traits, class _Allocator>
3498 inline _LIBCPP_INLINE_VISIBILITY
3499 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3500 basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
3501 size_type __pos) const _NOEXCEPT
3503 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
3504 return _VSTD::__str_find_first_of<value_type, size_type, traits_type, npos>
3505 (data(), size(), __s, __pos, traits_type::length(__s));
3508 template<class _CharT, class _Traits, class _Allocator>
3509 inline _LIBCPP_INLINE_VISIBILITY
3510 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3511 basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
3512 size_type __pos) const _NOEXCEPT
3514 return find(__c, __pos);
3519 template<class _CharT, class _Traits, class _Allocator>
3520 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3521 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3523 size_type __n) const _NOEXCEPT
3525 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
3526 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
3527 (data(), size(), __s, __pos, __n);
3530 template<class _CharT, class _Traits, class _Allocator>
3531 inline _LIBCPP_INLINE_VISIBILITY
3532 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3533 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
3534 size_type __pos) const _NOEXCEPT
3536 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
3537 (data(), size(), __str.data(), __pos, __str.size());
3540 template<class _CharT, class _Traits, class _Allocator>
3541 inline _LIBCPP_INLINE_VISIBILITY
3542 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3543 basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
3544 size_type __pos) const _NOEXCEPT
3546 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
3547 return _VSTD::__str_find_last_of<value_type, size_type, traits_type, npos>
3548 (data(), size(), __s, __pos, traits_type::length(__s));
3551 template<class _CharT, class _Traits, class _Allocator>
3552 inline _LIBCPP_INLINE_VISIBILITY
3553 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3554 basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
3555 size_type __pos) const _NOEXCEPT
3557 return rfind(__c, __pos);
3560 // find_first_not_of
3562 template<class _CharT, class _Traits, class _Allocator>
3563 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3564 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3566 size_type __n) const _NOEXCEPT
3568 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
3569 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3570 (data(), size(), __s, __pos, __n);
3573 template<class _CharT, class _Traits, class _Allocator>
3574 inline _LIBCPP_INLINE_VISIBILITY
3575 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3576 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
3577 size_type __pos) const _NOEXCEPT
3579 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3580 (data(), size(), __str.data(), __pos, __str.size());
3583 template<class _CharT, class _Traits, class _Allocator>
3584 inline _LIBCPP_INLINE_VISIBILITY
3585 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3586 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
3587 size_type __pos) const _NOEXCEPT
3589 _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
3590 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3591 (data(), size(), __s, __pos, traits_type::length(__s));
3594 template<class _CharT, class _Traits, class _Allocator>
3595 inline _LIBCPP_INLINE_VISIBILITY
3596 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3597 basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
3598 size_type __pos) const _NOEXCEPT
3600 return _VSTD::__str_find_first_not_of<value_type, size_type, traits_type, npos>
3601 (data(), size(), __c, __pos);
3606 template<class _CharT, class _Traits, class _Allocator>
3607 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3608 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3610 size_type __n) const _NOEXCEPT
3612 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
3613 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3614 (data(), size(), __s, __pos, __n);
3617 template<class _CharT, class _Traits, class _Allocator>
3618 inline _LIBCPP_INLINE_VISIBILITY
3619 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3620 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
3621 size_type __pos) const _NOEXCEPT
3623 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3624 (data(), size(), __str.data(), __pos, __str.size());
3627 template<class _CharT, class _Traits, class _Allocator>
3628 inline _LIBCPP_INLINE_VISIBILITY
3629 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3630 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
3631 size_type __pos) const _NOEXCEPT
3633 _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
3634 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3635 (data(), size(), __s, __pos, traits_type::length(__s));
3638 template<class _CharT, class _Traits, class _Allocator>
3639 inline _LIBCPP_INLINE_VISIBILITY
3640 typename basic_string<_CharT, _Traits, _Allocator>::size_type
3641 basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
3642 size_type __pos) const _NOEXCEPT
3644 return _VSTD::__str_find_last_not_of<value_type, size_type, traits_type, npos>
3645 (data(), size(), __c, __pos);
3650 template <class _CharT, class _Traits, class _Allocator>
3651 inline _LIBCPP_INLINE_VISIBILITY
3653 basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
3655 size_t __lhs_sz = size();
3656 size_t __rhs_sz = __str.size();
3657 int __result = traits_type::compare(data(), __str.data(),
3658 _VSTD::min(__lhs_sz, __rhs_sz));
3661 if (__lhs_sz < __rhs_sz)
3663 if (__lhs_sz > __rhs_sz)
3668 template <class _CharT, class _Traits, class _Allocator>
3669 inline _LIBCPP_INLINE_VISIBILITY
3671 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3673 const basic_string& __str) const
3675 return compare(__pos1, __n1, __str.data(), __str.size());
3678 template <class _CharT, class _Traits, class _Allocator>
3680 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3682 const basic_string& __str,
3684 size_type __n2) const
3686 size_type __sz = __str.size();
3688 this->__throw_out_of_range();
3689 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2,
3693 template <class _CharT, class _Traits, class _Allocator>
3695 basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
3697 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3698 return compare(0, npos, __s, traits_type::length(__s));
3701 template <class _CharT, class _Traits, class _Allocator>
3703 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3705 const value_type* __s) const
3707 _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
3708 return compare(__pos1, __n1, __s, traits_type::length(__s));
3711 template <class _CharT, class _Traits, class _Allocator>
3713 basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
3715 const value_type* __s,
3716 size_type __n2) const
3718 _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
3719 size_type __sz = size();
3720 if (__pos1 > __sz || __n2 == npos)
3721 this->__throw_out_of_range();
3722 size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
3723 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
3728 else if (__rlen > __n2)
3736 template<class _CharT, class _Traits, class _Allocator>
3737 inline _LIBCPP_INLINE_VISIBILITY
3739 basic_string<_CharT, _Traits, _Allocator>::__invariants() const
3741 if (size() > capacity())
3743 if (capacity() < __min_cap - 1)
3747 if (data()[size()] != value_type(0))
3754 template<class _CharT, class _Traits, class _Allocator>
3755 inline _LIBCPP_INLINE_VISIBILITY
3757 operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3758 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3760 size_t __lhs_sz = __lhs.size();
3761 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
3766 template<class _Allocator>
3767 inline _LIBCPP_INLINE_VISIBILITY
3769 operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
3770 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
3772 size_t __lhs_sz = __lhs.size();
3773 if (__lhs_sz != __rhs.size())
3775 const char* __lp = __lhs.data();
3776 const char* __rp = __rhs.data();
3777 if (__lhs.__is_long())
3778 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
3779 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
3785 template<class _CharT, class _Traits, class _Allocator>
3786 inline _LIBCPP_INLINE_VISIBILITY
3788 operator==(const _CharT* __lhs,
3789 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3791 return __rhs.compare(__lhs) == 0;
3794 template<class _CharT, class _Traits, class _Allocator>
3795 inline _LIBCPP_INLINE_VISIBILITY
3797 operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3798 const _CharT* __rhs) _NOEXCEPT
3800 return __lhs.compare(__rhs) == 0;
3805 template<class _CharT, class _Traits, class _Allocator>
3806 inline _LIBCPP_INLINE_VISIBILITY
3808 operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
3809 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3811 return !(__lhs == __rhs);
3814 template<class _CharT, class _Traits, class _Allocator>
3815 inline _LIBCPP_INLINE_VISIBILITY
3817 operator!=(const _CharT* __lhs,
3818 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3820 return !(__lhs == __rhs);
3823 template<class _CharT, class _Traits, class _Allocator>
3824 inline _LIBCPP_INLINE_VISIBILITY
3826 operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3827 const _CharT* __rhs) _NOEXCEPT
3829 return !(__lhs == __rhs);
3834 template<class _CharT, class _Traits, class _Allocator>
3835 inline _LIBCPP_INLINE_VISIBILITY
3837 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3838 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3840 return __lhs.compare(__rhs) < 0;
3843 template<class _CharT, class _Traits, class _Allocator>
3844 inline _LIBCPP_INLINE_VISIBILITY
3846 operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3847 const _CharT* __rhs) _NOEXCEPT
3849 return __lhs.compare(__rhs) < 0;
3852 template<class _CharT, class _Traits, class _Allocator>
3853 inline _LIBCPP_INLINE_VISIBILITY
3855 operator< (const _CharT* __lhs,
3856 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3858 return __rhs.compare(__lhs) > 0;
3863 template<class _CharT, class _Traits, class _Allocator>
3864 inline _LIBCPP_INLINE_VISIBILITY
3866 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3867 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3869 return __rhs < __lhs;
3872 template<class _CharT, class _Traits, class _Allocator>
3873 inline _LIBCPP_INLINE_VISIBILITY
3875 operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3876 const _CharT* __rhs) _NOEXCEPT
3878 return __rhs < __lhs;
3881 template<class _CharT, class _Traits, class _Allocator>
3882 inline _LIBCPP_INLINE_VISIBILITY
3884 operator> (const _CharT* __lhs,
3885 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3887 return __rhs < __lhs;
3892 template<class _CharT, class _Traits, class _Allocator>
3893 inline _LIBCPP_INLINE_VISIBILITY
3895 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3896 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3898 return !(__rhs < __lhs);
3901 template<class _CharT, class _Traits, class _Allocator>
3902 inline _LIBCPP_INLINE_VISIBILITY
3904 operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3905 const _CharT* __rhs) _NOEXCEPT
3907 return !(__rhs < __lhs);
3910 template<class _CharT, class _Traits, class _Allocator>
3911 inline _LIBCPP_INLINE_VISIBILITY
3913 operator<=(const _CharT* __lhs,
3914 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3916 return !(__rhs < __lhs);
3921 template<class _CharT, class _Traits, class _Allocator>
3922 inline _LIBCPP_INLINE_VISIBILITY
3924 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3925 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3927 return !(__lhs < __rhs);
3930 template<class _CharT, class _Traits, class _Allocator>
3931 inline _LIBCPP_INLINE_VISIBILITY
3933 operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3934 const _CharT* __rhs) _NOEXCEPT
3936 return !(__lhs < __rhs);
3939 template<class _CharT, class _Traits, class _Allocator>
3940 inline _LIBCPP_INLINE_VISIBILITY
3942 operator>=(const _CharT* __lhs,
3943 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
3945 return !(__lhs < __rhs);
3950 template<class _CharT, class _Traits, class _Allocator>
3951 basic_string<_CharT, _Traits, _Allocator>
3952 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
3953 const basic_string<_CharT, _Traits, _Allocator>& __rhs)
3955 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3956 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3957 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3958 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3959 __r.append(__rhs.data(), __rhs_sz);
3963 template<class _CharT, class _Traits, class _Allocator>
3964 basic_string<_CharT, _Traits, _Allocator>
3965 operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3967 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3968 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
3969 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3970 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
3971 __r.append(__rhs.data(), __rhs_sz);
3975 template<class _CharT, class _Traits, class _Allocator>
3976 basic_string<_CharT, _Traits, _Allocator>
3977 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
3979 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
3980 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
3981 __r.__init(&__lhs, 1, 1 + __rhs_sz);
3982 __r.append(__rhs.data(), __rhs_sz);
3986 template<class _CharT, class _Traits, class _Allocator>
3987 basic_string<_CharT, _Traits, _Allocator>
3988 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
3990 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
3991 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
3992 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
3993 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
3994 __r.append(__rhs, __rhs_sz);
3998 template<class _CharT, class _Traits, class _Allocator>
3999 basic_string<_CharT, _Traits, _Allocator>
4000 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
4002 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
4003 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
4004 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
4005 __r.push_back(__rhs);
4009 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4011 template<class _CharT, class _Traits, class _Allocator>
4012 inline _LIBCPP_INLINE_VISIBILITY
4013 basic_string<_CharT, _Traits, _Allocator>
4014 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
4016 return _VSTD::move(__lhs.append(__rhs));
4019 template<class _CharT, class _Traits, class _Allocator>
4020 inline _LIBCPP_INLINE_VISIBILITY
4021 basic_string<_CharT, _Traits, _Allocator>
4022 operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4024 return _VSTD::move(__rhs.insert(0, __lhs));
4027 template<class _CharT, class _Traits, class _Allocator>
4028 inline _LIBCPP_INLINE_VISIBILITY
4029 basic_string<_CharT, _Traits, _Allocator>
4030 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
4032 return _VSTD::move(__lhs.append(__rhs));
4035 template<class _CharT, class _Traits, class _Allocator>
4036 inline _LIBCPP_INLINE_VISIBILITY
4037 basic_string<_CharT, _Traits, _Allocator>
4038 operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4040 return _VSTD::move(__rhs.insert(0, __lhs));
4043 template<class _CharT, class _Traits, class _Allocator>
4044 inline _LIBCPP_INLINE_VISIBILITY
4045 basic_string<_CharT, _Traits, _Allocator>
4046 operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
4048 __rhs.insert(__rhs.begin(), __lhs);
4049 return _VSTD::move(__rhs);
4052 template<class _CharT, class _Traits, class _Allocator>
4053 inline _LIBCPP_INLINE_VISIBILITY
4054 basic_string<_CharT, _Traits, _Allocator>
4055 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
4057 return _VSTD::move(__lhs.append(__rhs));
4060 template<class _CharT, class _Traits, class _Allocator>
4061 inline _LIBCPP_INLINE_VISIBILITY
4062 basic_string<_CharT, _Traits, _Allocator>
4063 operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
4065 __lhs.push_back(__rhs);
4066 return _VSTD::move(__lhs);
4069 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4073 template<class _CharT, class _Traits, class _Allocator>
4074 inline _LIBCPP_INLINE_VISIBILITY
4076 swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
4077 basic_string<_CharT, _Traits, _Allocator>& __rhs)
4078 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
4083 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
4085 typedef basic_string<char16_t> u16string;
4086 typedef basic_string<char32_t> u32string;
4088 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
4090 _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
4091 _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
4092 _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
4093 _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
4094 _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
4096 _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
4097 _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
4098 _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
4100 _LIBCPP_FUNC_VIS string to_string(int __val);
4101 _LIBCPP_FUNC_VIS string to_string(unsigned __val);
4102 _LIBCPP_FUNC_VIS string to_string(long __val);
4103 _LIBCPP_FUNC_VIS string to_string(unsigned long __val);
4104 _LIBCPP_FUNC_VIS string to_string(long long __val);
4105 _LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
4106 _LIBCPP_FUNC_VIS string to_string(float __val);
4107 _LIBCPP_FUNC_VIS string to_string(double __val);
4108 _LIBCPP_FUNC_VIS string to_string(long double __val);
4110 _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
4111 _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
4112 _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
4113 _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
4114 _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
4116 _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
4117 _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
4118 _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
4120 _LIBCPP_FUNC_VIS wstring to_wstring(int __val);
4121 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
4122 _LIBCPP_FUNC_VIS wstring to_wstring(long __val);
4123 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
4124 _LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
4125 _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
4126 _LIBCPP_FUNC_VIS wstring to_wstring(float __val);
4127 _LIBCPP_FUNC_VIS wstring to_wstring(double __val);
4128 _LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
4130 template<class _CharT, class _Traits, class _Allocator>
4131 const typename basic_string<_CharT, _Traits, _Allocator>::size_type
4132 basic_string<_CharT, _Traits, _Allocator>::npos;
4134 template<class _CharT, class _Traits, class _Allocator>
4135 struct _LIBCPP_TYPE_VIS_ONLY hash<basic_string<_CharT, _Traits, _Allocator> >
4136 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t>
4139 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT;
4142 template<class _CharT, class _Traits, class _Allocator>
4144 hash<basic_string<_CharT, _Traits, _Allocator> >::operator()(
4145 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT
4147 return __do_string_hash(__val.data(), __val.data() + __val.size());
4150 template<class _CharT, class _Traits, class _Allocator>
4151 basic_ostream<_CharT, _Traits>&
4152 operator<<(basic_ostream<_CharT, _Traits>& __os,
4153 const basic_string<_CharT, _Traits, _Allocator>& __str);
4155 template<class _CharT, class _Traits, class _Allocator>
4156 basic_istream<_CharT, _Traits>&
4157 operator>>(basic_istream<_CharT, _Traits>& __is,
4158 basic_string<_CharT, _Traits, _Allocator>& __str);
4160 template<class _CharT, class _Traits, class _Allocator>
4161 basic_istream<_CharT, _Traits>&
4162 getline(basic_istream<_CharT, _Traits>& __is,
4163 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4165 template<class _CharT, class _Traits, class _Allocator>
4166 inline _LIBCPP_INLINE_VISIBILITY
4167 basic_istream<_CharT, _Traits>&
4168 getline(basic_istream<_CharT, _Traits>& __is,
4169 basic_string<_CharT, _Traits, _Allocator>& __str);
4171 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
4173 template<class _CharT, class _Traits, class _Allocator>
4174 inline _LIBCPP_INLINE_VISIBILITY
4175 basic_istream<_CharT, _Traits>&
4176 getline(basic_istream<_CharT, _Traits>&& __is,
4177 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
4179 template<class _CharT, class _Traits, class _Allocator>
4180 inline _LIBCPP_INLINE_VISIBILITY
4181 basic_istream<_CharT, _Traits>&
4182 getline(basic_istream<_CharT, _Traits>&& __is,
4183 basic_string<_CharT, _Traits, _Allocator>& __str);
4185 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
4187 #if _LIBCPP_DEBUG_LEVEL >= 2
4189 template<class _CharT, class _Traits, class _Allocator>
4191 basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
4193 return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
4194 _VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
4197 template<class _CharT, class _Traits, class _Allocator>
4199 basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
4201 return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
4202 _VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
4205 template<class _CharT, class _Traits, class _Allocator>
4207 basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
4209 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4210 return this->data() <= __p && __p <= this->data() + this->size();
4213 template<class _CharT, class _Traits, class _Allocator>
4215 basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
4217 const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
4218 return this->data() <= __p && __p < this->data() + this->size();
4221 #endif // _LIBCPP_DEBUG_LEVEL >= 2
4223 #if _LIBCPP_STD_VER > 11
4224 // Literal suffixes for basic_string [basic.string.literals]
4225 inline namespace literals
4227 inline namespace string_literals
4229 inline _LIBCPP_INLINE_VISIBILITY
4230 basic_string<char> operator "" s( const char *__str, size_t __len )
4232 return basic_string<char> (__str, __len);
4235 inline _LIBCPP_INLINE_VISIBILITY
4236 basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
4238 return basic_string<wchar_t> (__str, __len);
4241 inline _LIBCPP_INLINE_VISIBILITY
4242 basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
4244 return basic_string<char16_t> (__str, __len);
4247 inline _LIBCPP_INLINE_VISIBILITY
4248 basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
4250 return basic_string<char32_t> (__str, __len);
4256 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<char>)
4257 _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string<wchar_t>)
4258 _LIBCPP_EXTERN_TEMPLATE(string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
4260 _LIBCPP_END_NAMESPACE_STD
4262 #endif // _LIBCPP_STRING