1// -*- C++ -*- 2//===--------------------------- string -----------------------------------===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is distributed under the University of Illinois Open Source 7// License. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10 11#ifndef _LIBCPP_STRING 12#define _LIBCPP_STRING 13 14/* 15 string synopsis 16 17namespace std 18{ 19 20template <class stateT> 21class fpos 22{ 23private: 24 stateT st; 25public: 26 fpos(streamoff = streamoff()); 27 28 operator streamoff() const; 29 30 stateT state() const; 31 void state(stateT); 32 33 fpos& operator+=(streamoff); 34 fpos operator+ (streamoff) const; 35 fpos& operator-=(streamoff); 36 fpos operator- (streamoff) const; 37}; 38 39template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); 40 41template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); 42template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); 43 44template <class charT> 45struct char_traits 46{ 47 typedef charT char_type; 48 typedef ... int_type; 49 typedef streamoff off_type; 50 typedef streampos pos_type; 51 typedef mbstate_t state_type; 52 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; 56 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); 63 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; 69}; 70 71template <> struct char_traits<char>; 72template <> struct char_traits<wchar_t>; 73 74template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 75class basic_string 76{ 77public: 78// types: 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; 92 93 static const size_type npos = -1; 94 95 basic_string() 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_pointer s, const allocator_type& a = allocator_type()); 104 basic_string(const_pointer 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&); 112 113 ~basic_string(); 114 115 basic_string& operator=(const basic_string& str); 116 basic_string& operator=(basic_string&& str) 117 noexcept( 118 allocator_type::propagate_on_container_move_assignment::value && 119 is_nothrow_move_assignable<allocator_type>::value); 120 basic_string& operator=(const_pointer s); 121 basic_string& operator=(value_type c); 122 basic_string& operator=(initializer_list<value_type>); 123 124 iterator begin() noexcept; 125 const_iterator begin() const noexcept; 126 iterator end() noexcept; 127 const_iterator end() const noexcept; 128 129 reverse_iterator rbegin() noexcept; 130 const_reverse_iterator rbegin() const noexcept; 131 reverse_iterator rend() noexcept; 132 const_reverse_iterator rend() const noexcept; 133 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; 138 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; 143 144 void resize(size_type n, value_type c); 145 void resize(size_type n); 146 147 void reserve(size_type res_arg = 0); 148 void shrink_to_fit(); 149 void clear() noexcept; 150 bool empty() const noexcept; 151 152 const_reference operator[](size_type pos) const; 153 reference operator[](size_type pos); 154 155 const_reference at(size_type n) const; 156 reference at(size_type n); 157 158 basic_string& operator+=(const basic_string& str); 159 basic_string& operator+=(const_pointer s); 160 basic_string& operator+=(value_type c); 161 basic_string& operator+=(initializer_list<value_type>); 162 163 basic_string& append(const basic_string& str); 164 basic_string& append(const basic_string& str, size_type pos, size_type n); 165 basic_string& append(const_pointer s, size_type n); 166 basic_string& append(const_pointer 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>); 171 172 void push_back(value_type c); 173 void pop_back(); 174 reference front(); 175 const_reference front() const; 176 reference back(); 177 const_reference back() const; 178 179 basic_string& assign(const basic_string& str); 180 basic_string& assign(basic_string&& str); 181 basic_string& assign(const basic_string& str, size_type pos, size_type n); 182 basic_string& assign(const_pointer s, size_type n); 183 basic_string& assign(const_pointer 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>); 188 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_pointer s, size_type n); 193 basic_string& insert(size_type pos, const_pointer 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>); 200 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); 204 205 basic_string& replace(size_type pos1, size_type n1, const basic_string& str); 206 basic_string& replace(size_type pos1, size_type n1, const basic_string& str, 207 size_type pos2, size_type n2); 208 basic_string& replace(size_type pos, size_type n1, const_pointer s, size_type n2); 209 basic_string& replace(size_type pos, size_type n1, const_pointer 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_pointer s, size_type n); 213 basic_string& replace(const_iterator i1, const_iterator i2, const_pointer 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>); 218 219 size_type copy(pointer s, size_type n, size_type pos = 0) const; 220 basic_string substr(size_type pos = 0, size_type n = npos) const; 221 222 void swap(basic_string& str) 223 noexcept(!allocator_type::propagate_on_container_swap::value || 224 __is_nothrow_swappable<allocator_type>::value) 225 226 const_pointer c_str() const noexcept; 227 const_pointer data() const noexcept; 228 229 allocator_type get_allocator() const noexcept; 230 231 size_type find(const basic_string& str, size_type pos = 0) const noexcept; 232 size_type find(const_pointer s, size_type pos, size_type n) const noexcept; 233 size_type find(const_pointer s, size_type pos = 0) const noexcept; 234 size_type find(value_type c, size_type pos = 0) const noexcept; 235 236 size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; 237 size_type rfind(const_pointer s, size_type pos, size_type n) const noexcept; 238 size_type rfind(const_pointer s, size_type pos = npos) const noexcept; 239 size_type rfind(value_type c, size_type pos = npos) const noexcept; 240 241 size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; 242 size_type find_first_of(const_pointer s, size_type pos, size_type n) const noexcept; 243 size_type find_first_of(const_pointer s, size_type pos = 0) const noexcept; 244 size_type find_first_of(value_type c, size_type pos = 0) const noexcept; 245 246 size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; 247 size_type find_last_of(const_pointer s, size_type pos, size_type n) const noexcept; 248 size_type find_last_of(const_pointer s, size_type pos = npos) const noexcept; 249 size_type find_last_of(value_type c, size_type pos = npos) const noexcept; 250 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_pointer s, size_type pos, size_type n) const noexcept; 253 size_type find_first_not_of(const_pointer s, size_type pos = 0) const noexcept; 254 size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; 255 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_pointer s, size_type pos, size_type n) const noexcept; 258 size_type find_last_not_of(const_pointer s, size_type pos = npos) const noexcept; 259 size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; 260 261 int compare(const basic_string& str) const noexcept; 262 int compare(size_type pos1, size_type n1, const basic_string& str) const; 263 int compare(size_type pos1, size_type n1, const basic_string& str, 264 size_type pos2, size_type n2) const; 265 int compare(const_pointer s) const noexcept; 266 int compare(size_type pos1, size_type n1, const_pointer s) const; 267 int compare(size_type pos1, size_type n1, const_pointer s, size_type n2) const; 268 269 bool __invariants() const; 270}; 271 272template<class charT, class traits, class Allocator> 273basic_string<charT, traits, Allocator> 274operator+(const basic_string<charT, traits, Allocator>& lhs, 275 const basic_string<charT, traits, Allocator>& rhs); 276 277template<class charT, class traits, class Allocator> 278basic_string<charT, traits, Allocator> 279operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); 280 281template<class charT, class traits, class Allocator> 282basic_string<charT, traits, Allocator> 283operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); 284 285template<class charT, class traits, class Allocator> 286basic_string<charT, traits, Allocator> 287operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); 288 289template<class charT, class traits, class Allocator> 290basic_string<charT, traits, Allocator> 291operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); 292 293template<class charT, class traits, class Allocator> 294bool operator==(const basic_string<charT, traits, Allocator>& lhs, 295 const basic_string<charT, traits, Allocator>& rhs) noexcept; 296 297template<class charT, class traits, class Allocator> 298bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; 299 300template<class charT, class traits, class Allocator> 301bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; 302 303template<class charT, class traits, class Allocator> 304bool operator!=(const basic_string<charT,traits,Allocator>& lhs, 305 const basic_string<charT, traits, Allocator>& rhs) noexcept; 306 307template<class charT, class traits, class Allocator> 308bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; 309 310template<class charT, class traits, class Allocator> 311bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; 312 313template<class charT, class traits, class Allocator> 314bool operator< (const basic_string<charT, traits, Allocator>& lhs, 315 const basic_string<charT, traits, Allocator>& rhs) noexcept; 316 317template<class charT, class traits, class Allocator> 318bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; 319 320template<class charT, class traits, class Allocator> 321bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; 322 323template<class charT, class traits, class Allocator> 324bool operator> (const basic_string<charT, traits, Allocator>& lhs, 325 const basic_string<charT, traits, Allocator>& rhs) noexcept; 326 327template<class charT, class traits, class Allocator> 328bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; 329 330template<class charT, class traits, class Allocator> 331bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; 332 333template<class charT, class traits, class Allocator> 334bool operator<=(const basic_string<charT, traits, Allocator>& lhs, 335 const basic_string<charT, traits, Allocator>& rhs) noexcept; 336 337template<class charT, class traits, class Allocator> 338bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; 339 340template<class charT, class traits, class Allocator> 341bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; 342 343template<class charT, class traits, class Allocator> 344bool operator>=(const basic_string<charT, traits, Allocator>& lhs, 345 const basic_string<charT, traits, Allocator>& rhs) noexcept; 346 347template<class charT, class traits, class Allocator> 348bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; 349 350template<class charT, class traits, class Allocator> 351bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; 352 353template<class charT, class traits, class Allocator> 354void swap(basic_string<charT, traits, Allocator>& lhs, 355 basic_string<charT, traits, Allocator>& rhs) 356 noexcept(noexcept(lhs.swap(rhs))); 357 358template<class charT, class traits, class Allocator> 359basic_istream<charT, traits>& 360operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); 361 362template<class charT, class traits, class Allocator> 363basic_ostream<charT, traits>& 364operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); 365 366template<class charT, class traits, class Allocator> 367basic_istream<charT, traits>& 368getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, 369 charT delim); 370 371template<class charT, class traits, class Allocator> 372basic_istream<charT, traits>& 373getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); 374 375typedef basic_string<char> string; 376typedef basic_string<wchar_t> wstring; 377typedef basic_string<char16_t> u16string; 378typedef basic_string<char32_t> u32string; 379 380int stoi (const string& str, size_t* idx = 0, int base = 10); 381long stol (const string& str, size_t* idx = 0, int base = 10); 382unsigned long stoul (const string& str, size_t* idx = 0, int base = 10); 383long long stoll (const string& str, size_t* idx = 0, int base = 10); 384unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10); 385 386float stof (const string& str, size_t* idx = 0); 387double stod (const string& str, size_t* idx = 0); 388long double stold(const string& str, size_t* idx = 0); 389 390string to_string(int val); 391string to_string(unsigned val); 392string to_string(long val); 393string to_string(unsigned long val); 394string to_string(long long val); 395string to_string(unsigned long long val); 396string to_string(float val); 397string to_string(double val); 398string to_string(long double val); 399 400int stoi (const wstring& str, size_t* idx = 0, int base = 10); 401long stol (const wstring& str, size_t* idx = 0, int base = 10); 402unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10); 403long long stoll (const wstring& str, size_t* idx = 0, int base = 10); 404unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10); 405 406float stof (const wstring& str, size_t* idx = 0); 407double stod (const wstring& str, size_t* idx = 0); 408long double stold(const wstring& str, size_t* idx = 0); 409 410wstring to_wstring(int val); 411wstring to_wstring(unsigned val); 412wstring to_wstring(long val); 413wstring to_wstring(unsigned long val); 414wstring to_wstring(long long val); 415wstring to_wstring(unsigned long long val); 416wstring to_wstring(float val); 417wstring to_wstring(double val); 418wstring to_wstring(long double val); 419 420template <> struct hash<string>; 421template <> struct hash<u16string>; 422template <> struct hash<u32string>; 423template <> struct hash<wstring>; 424 425} // std 426 427*/ 428 429#include <__config> 430#include <iosfwd> 431#include <cstring> 432#include <cstdio> // For EOF. 433#include <cwchar> 434#include <algorithm> 435#include <iterator> 436#include <utility> 437#include <memory> 438#include <stdexcept> 439#include <type_traits> 440#include <initializer_list> 441#include <__functional_base> 442#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 443#include <cstdint> 444#endif 445#if defined(_LIBCPP_NO_EXCEPTIONS) || defined(_LIBCPP_DEBUG) 446#include <cassert> 447#endif 448 449#include <__undef_min_max> 450 451#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 452#pragma GCC system_header 453#endif 454 455_LIBCPP_BEGIN_NAMESPACE_STD 456 457// fpos 458 459template <class _StateT> 460class _LIBCPP_TYPE_VIS fpos 461{ 462private: 463 _StateT __st_; 464 streamoff __off_; 465public: 466 _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {} 467 468 _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;} 469 470 _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;} 471 _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;} 472 473 _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;} 474 _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;} 475 _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;} 476 _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;} 477}; 478 479template <class _StateT> 480inline _LIBCPP_INLINE_VISIBILITY 481streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) 482 {return streamoff(__x) - streamoff(__y);} 483 484template <class _StateT> 485inline _LIBCPP_INLINE_VISIBILITY 486bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) 487 {return streamoff(__x) == streamoff(__y);} 488 489template <class _StateT> 490inline _LIBCPP_INLINE_VISIBILITY 491bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) 492 {return streamoff(__x) != streamoff(__y);} 493 494// char_traits 495 496template <class _CharT> 497struct _LIBCPP_TYPE_VIS char_traits 498{ 499 typedef _CharT char_type; 500 typedef int int_type; 501 typedef streamoff off_type; 502 typedef streampos pos_type; 503 typedef mbstate_t state_type; 504 505 _LIBCPP_INLINE_VISIBILITY 506 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT 507 {__c1 = __c2;} 508 _LIBCPP_INLINE_VISIBILITY 509 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT 510 {return __c1 == __c2;} 511 _LIBCPP_INLINE_VISIBILITY 512 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT 513 {return __c1 < __c2;} 514 515 static int compare(const char_type* __s1, const char_type* __s2, size_t __n); 516 static size_t length(const char_type* __s); 517 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); 518 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); 519 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); 520 static char_type* assign(char_type* __s, size_t __n, char_type __a); 521 522 _LIBCPP_INLINE_VISIBILITY 523 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT 524 {return eq_int_type(__c, eof()) ? ~eof() : __c;} 525 _LIBCPP_INLINE_VISIBILITY 526 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT 527 {return char_type(__c);} 528 _LIBCPP_INLINE_VISIBILITY 529 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT 530 {return int_type(__c);} 531 _LIBCPP_INLINE_VISIBILITY 532 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT 533 {return __c1 == __c2;} 534 _LIBCPP_INLINE_VISIBILITY 535 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT 536 {return int_type(EOF);} 537}; 538 539template <class _CharT> 540int 541char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n) 542{ 543 for (; __n; --__n, ++__s1, ++__s2) 544 { 545 if (lt(*__s1, *__s2)) 546 return -1; 547 if (lt(*__s2, *__s1)) 548 return 1; 549 } 550 return 0; 551} 552 553template <class _CharT> 554inline _LIBCPP_INLINE_VISIBILITY 555size_t 556char_traits<_CharT>::length(const char_type* __s) 557{ 558 size_t __len = 0; 559 for (; !eq(*__s, char_type(0)); ++__s) 560 ++__len; 561 return __len; 562} 563 564template <class _CharT> 565inline _LIBCPP_INLINE_VISIBILITY 566const _CharT* 567char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a) 568{ 569 for (; __n; --__n) 570 { 571 if (eq(*__s, __a)) 572 return __s; 573 ++__s; 574 } 575 return 0; 576} 577 578template <class _CharT> 579_CharT* 580char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n) 581{ 582 char_type* __r = __s1; 583 if (__s1 < __s2) 584 { 585 for (; __n; --__n, ++__s1, ++__s2) 586 assign(*__s1, *__s2); 587 } 588 else if (__s2 < __s1) 589 { 590 __s1 += __n; 591 __s2 += __n; 592 for (; __n; --__n) 593 assign(*--__s1, *--__s2); 594 } 595 return __r; 596} 597 598template <class _CharT> 599inline _LIBCPP_INLINE_VISIBILITY 600_CharT* 601char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) 602{ 603 char_type* __r = __s1; 604 for (; __n; --__n, ++__s1, ++__s2) 605 assign(*__s1, *__s2); 606 return __r; 607} 608 609template <class _CharT> 610inline _LIBCPP_INLINE_VISIBILITY 611_CharT* 612char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) 613{ 614 char_type* __r = __s; 615 for (; __n; --__n, ++__s) 616 assign(*__s, __a); 617 return __r; 618} 619 620// char_traits<char> 621 622template <> 623struct _LIBCPP_TYPE_VIS char_traits<char> 624{ 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; 630 631 _LIBCPP_INLINE_VISIBILITY 632 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT 633 {__c1 = __c2;} 634 _LIBCPP_INLINE_VISIBILITY 635 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT 636 {return __c1 == __c2;} 637 _LIBCPP_INLINE_VISIBILITY 638 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT 639 {return (unsigned char)__c1 < (unsigned char)__c2;} 640 641 _LIBCPP_INLINE_VISIBILITY 642 static int compare(const char_type* __s1, const char_type* __s2, size_t __n) 643 {return memcmp(__s1, __s2, __n);} 644 _LIBCPP_INLINE_VISIBILITY 645 static size_t length(const char_type* __s) {return strlen(__s);} 646 _LIBCPP_INLINE_VISIBILITY 647 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a) 648 {return (const char_type*)memchr(__s, to_int_type(__a), __n);} 649 _LIBCPP_INLINE_VISIBILITY 650 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) 651 {return (char_type*)memmove(__s1, __s2, __n);} 652 _LIBCPP_INLINE_VISIBILITY 653 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) 654 {return (char_type*)memcpy(__s1, __s2, __n);} 655 _LIBCPP_INLINE_VISIBILITY 656 static char_type* assign(char_type* __s, size_t __n, char_type __a) 657 {return (char_type*)memset(__s, to_int_type(__a), __n);} 658 659 _LIBCPP_INLINE_VISIBILITY 660 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT 661 {return eq_int_type(__c, eof()) ? ~eof() : __c;} 662 _LIBCPP_INLINE_VISIBILITY 663 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT 664 {return char_type(__c);} 665 _LIBCPP_INLINE_VISIBILITY 666 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT 667 {return int_type((unsigned char)__c);} 668 _LIBCPP_INLINE_VISIBILITY 669 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT 670 {return __c1 == __c2;} 671 _LIBCPP_INLINE_VISIBILITY 672 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT 673 {return int_type(EOF);} 674}; 675 676// char_traits<wchar_t> 677 678template <> 679struct _LIBCPP_TYPE_VIS char_traits<wchar_t> 680{ 681 typedef wchar_t char_type; 682 typedef wint_t int_type; 683 typedef streamoff off_type; 684 typedef streampos pos_type; 685 typedef mbstate_t state_type; 686 687 _LIBCPP_INLINE_VISIBILITY 688 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT 689 {__c1 = __c2;} 690 _LIBCPP_INLINE_VISIBILITY 691 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT 692 {return __c1 == __c2;} 693 _LIBCPP_INLINE_VISIBILITY 694 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT 695 {return __c1 < __c2;} 696 697 _LIBCPP_INLINE_VISIBILITY 698 static int compare(const char_type* __s1, const char_type* __s2, size_t __n) 699 {return wmemcmp(__s1, __s2, __n);} 700 _LIBCPP_INLINE_VISIBILITY 701 static size_t length(const char_type* __s) 702 {return wcslen(__s);} 703 _LIBCPP_INLINE_VISIBILITY 704 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a) 705 {return (const char_type*)wmemchr(__s, __a, __n);} 706 _LIBCPP_INLINE_VISIBILITY 707 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) 708 {return (char_type*)wmemmove(__s1, __s2, __n);} 709 _LIBCPP_INLINE_VISIBILITY 710 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) 711 {return (char_type*)wmemcpy(__s1, __s2, __n);} 712 _LIBCPP_INLINE_VISIBILITY 713 static char_type* assign(char_type* __s, size_t __n, char_type __a) 714 {return (char_type*)wmemset(__s, __a, __n);} 715 716 _LIBCPP_INLINE_VISIBILITY 717 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT 718 {return eq_int_type(__c, eof()) ? ~eof() : __c;} 719 _LIBCPP_INLINE_VISIBILITY 720 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT 721 {return char_type(__c);} 722 _LIBCPP_INLINE_VISIBILITY 723 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT 724 {return int_type(__c);} 725 _LIBCPP_INLINE_VISIBILITY 726 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT 727 {return __c1 == __c2;} 728 _LIBCPP_INLINE_VISIBILITY 729 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT 730 {return int_type(WEOF);} 731}; 732 733#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 734 735template <> 736struct _LIBCPP_TYPE_VIS char_traits<char16_t> 737{ 738 typedef char16_t char_type; 739 typedef uint_least16_t int_type; 740 typedef streamoff off_type; 741 typedef u16streampos pos_type; 742 typedef mbstate_t state_type; 743 744 _LIBCPP_INLINE_VISIBILITY 745 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT 746 {__c1 = __c2;} 747 _LIBCPP_INLINE_VISIBILITY 748 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT 749 {return __c1 == __c2;} 750 _LIBCPP_INLINE_VISIBILITY 751 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT 752 {return __c1 < __c2;} 753 754 static int compare(const char_type* __s1, const char_type* __s2, size_t __n); 755 static size_t length(const char_type* __s); 756 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); 757 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); 758 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); 759 static char_type* assign(char_type* __s, size_t __n, char_type __a); 760 761 _LIBCPP_INLINE_VISIBILITY 762 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT 763 {return eq_int_type(__c, eof()) ? ~eof() : __c;} 764 _LIBCPP_INLINE_VISIBILITY 765 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT 766 {return char_type(__c);} 767 _LIBCPP_INLINE_VISIBILITY 768 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT 769 {return int_type(__c);} 770 _LIBCPP_INLINE_VISIBILITY 771 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT 772 {return __c1 == __c2;} 773 _LIBCPP_INLINE_VISIBILITY 774 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT 775 {return int_type(0xDFFF);} 776}; 777 778inline _LIBCPP_INLINE_VISIBILITY 779int 780char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) 781{ 782 for (; __n; --__n, ++__s1, ++__s2) 783 { 784 if (lt(*__s1, *__s2)) 785 return -1; 786 if (lt(*__s2, *__s1)) 787 return 1; 788 } 789 return 0; 790} 791 792inline _LIBCPP_INLINE_VISIBILITY 793size_t 794char_traits<char16_t>::length(const char_type* __s) 795{ 796 size_t __len = 0; 797 for (; !eq(*__s, char_type(0)); ++__s) 798 ++__len; 799 return __len; 800} 801 802inline _LIBCPP_INLINE_VISIBILITY 803const char16_t* 804char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) 805{ 806 for (; __n; --__n) 807 { 808 if (eq(*__s, __a)) 809 return __s; 810 ++__s; 811 } 812 return 0; 813} 814 815inline _LIBCPP_INLINE_VISIBILITY 816char16_t* 817char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) 818{ 819 char_type* __r = __s1; 820 if (__s1 < __s2) 821 { 822 for (; __n; --__n, ++__s1, ++__s2) 823 assign(*__s1, *__s2); 824 } 825 else if (__s2 < __s1) 826 { 827 __s1 += __n; 828 __s2 += __n; 829 for (; __n; --__n) 830 assign(*--__s1, *--__s2); 831 } 832 return __r; 833} 834 835inline _LIBCPP_INLINE_VISIBILITY 836char16_t* 837char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) 838{ 839 char_type* __r = __s1; 840 for (; __n; --__n, ++__s1, ++__s2) 841 assign(*__s1, *__s2); 842 return __r; 843} 844 845inline _LIBCPP_INLINE_VISIBILITY 846char16_t* 847char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) 848{ 849 char_type* __r = __s; 850 for (; __n; --__n, ++__s) 851 assign(*__s, __a); 852 return __r; 853} 854 855template <> 856struct _LIBCPP_TYPE_VIS char_traits<char32_t> 857{ 858 typedef char32_t char_type; 859 typedef uint_least32_t int_type; 860 typedef streamoff off_type; 861 typedef u32streampos pos_type; 862 typedef mbstate_t state_type; 863 864 _LIBCPP_INLINE_VISIBILITY 865 static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT 866 {__c1 = __c2;} 867 _LIBCPP_INLINE_VISIBILITY 868 static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT 869 {return __c1 == __c2;} 870 _LIBCPP_INLINE_VISIBILITY 871 static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT 872 {return __c1 < __c2;} 873 874 static int compare(const char_type* __s1, const char_type* __s2, size_t __n); 875 static size_t length(const char_type* __s); 876 static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); 877 static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); 878 static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); 879 static char_type* assign(char_type* __s, size_t __n, char_type __a); 880 881 _LIBCPP_INLINE_VISIBILITY 882 static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT 883 {return eq_int_type(__c, eof()) ? ~eof() : __c;} 884 _LIBCPP_INLINE_VISIBILITY 885 static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT 886 {return char_type(__c);} 887 _LIBCPP_INLINE_VISIBILITY 888 static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT 889 {return int_type(__c);} 890 _LIBCPP_INLINE_VISIBILITY 891 static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT 892 {return __c1 == __c2;} 893 _LIBCPP_INLINE_VISIBILITY 894 static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT 895 {return int_type(0xFFFFFFFF);} 896}; 897 898inline _LIBCPP_INLINE_VISIBILITY 899int 900char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) 901{ 902 for (; __n; --__n, ++__s1, ++__s2) 903 { 904 if (lt(*__s1, *__s2)) 905 return -1; 906 if (lt(*__s2, *__s1)) 907 return 1; 908 } 909 return 0; 910} 911 912inline _LIBCPP_INLINE_VISIBILITY 913size_t 914char_traits<char32_t>::length(const char_type* __s) 915{ 916 size_t __len = 0; 917 for (; !eq(*__s, char_type(0)); ++__s) 918 ++__len; 919 return __len; 920} 921 922inline _LIBCPP_INLINE_VISIBILITY 923const char32_t* 924char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) 925{ 926 for (; __n; --__n) 927 { 928 if (eq(*__s, __a)) 929 return __s; 930 ++__s; 931 } 932 return 0; 933} 934 935inline _LIBCPP_INLINE_VISIBILITY 936char32_t* 937char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) 938{ 939 char_type* __r = __s1; 940 if (__s1 < __s2) 941 { 942 for (; __n; --__n, ++__s1, ++__s2) 943 assign(*__s1, *__s2); 944 } 945 else if (__s2 < __s1) 946 { 947 __s1 += __n; 948 __s2 += __n; 949 for (; __n; --__n) 950 assign(*--__s1, *--__s2); 951 } 952 return __r; 953} 954 955inline _LIBCPP_INLINE_VISIBILITY 956char32_t* 957char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) 958{ 959 char_type* __r = __s1; 960 for (; __n; --__n, ++__s1, ++__s2) 961 assign(*__s1, *__s2); 962 return __r; 963} 964 965inline _LIBCPP_INLINE_VISIBILITY 966char32_t* 967char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) 968{ 969 char_type* __r = __s; 970 for (; __n; --__n, ++__s) 971 assign(*__s, __a); 972 return __r; 973} 974 975#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 976 977// basic_string 978 979template<class _CharT, class _Traits, class _Allocator> 980basic_string<_CharT, _Traits, _Allocator> 981operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, 982 const basic_string<_CharT, _Traits, _Allocator>& __y); 983 984template<class _CharT, class _Traits, class _Allocator> 985basic_string<_CharT, _Traits, _Allocator> 986operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); 987 988template<class _CharT, class _Traits, class _Allocator> 989basic_string<_CharT, _Traits, _Allocator> 990operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); 991 992template<class _CharT, class _Traits, class _Allocator> 993basic_string<_CharT, _Traits, _Allocator> 994operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); 995 996template<class _CharT, class _Traits, class _Allocator> 997basic_string<_CharT, _Traits, _Allocator> 998operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); 999 1000template <bool> 1001class __basic_string_common 1002{ 1003protected: 1004 void __throw_length_error() const; 1005 void __throw_out_of_range() const; 1006}; 1007 1008template <bool __b> 1009void 1010__basic_string_common<__b>::__throw_length_error() const 1011{ 1012#ifndef _LIBCPP_NO_EXCEPTIONS 1013 throw length_error("basic_string"); 1014#else 1015 assert(!"basic_string length_error"); 1016#endif 1017} 1018 1019template <bool __b> 1020void 1021__basic_string_common<__b>::__throw_out_of_range() const 1022{ 1023#ifndef _LIBCPP_NO_EXCEPTIONS 1024 throw out_of_range("basic_string"); 1025#else 1026 assert(!"basic_string out_of_range"); 1027#endif 1028} 1029 1030#ifdef _MSC_VER 1031#pragma warning( push ) 1032#pragma warning( disable: 4231 ) 1033#endif // _MSC_VER 1034_LIBCPP_EXTERN_TEMPLATE(class __basic_string_common<true>) 1035#ifdef _MSC_VER 1036#pragma warning( pop ) 1037#endif // _MSC_VER 1038 1039#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT 1040 1041template <class _CharT, size_t = sizeof(_CharT)> 1042struct __padding 1043{ 1044 unsigned char __xx[sizeof(_CharT)-1]; 1045}; 1046 1047template <class _CharT> 1048struct __padding<_CharT, 1> 1049{ 1050}; 1051 1052#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT 1053 1054template<class _CharT, class _Traits, class _Allocator> 1055class _LIBCPP_TYPE_VIS basic_string 1056 : private __basic_string_common<true> 1057{ 1058public: 1059 typedef basic_string __self; 1060 typedef _Traits traits_type; 1061 typedef typename traits_type::char_type value_type; 1062 typedef _Allocator allocator_type; 1063 typedef allocator_traits<allocator_type> __alloc_traits; 1064 typedef typename __alloc_traits::size_type size_type; 1065 typedef typename __alloc_traits::difference_type difference_type; 1066 typedef value_type& reference; 1067 typedef const value_type& const_reference; 1068 typedef typename __alloc_traits::pointer pointer; 1069 typedef typename __alloc_traits::const_pointer const_pointer; 1070#ifdef _LIBCPP_DEBUG 1071 typedef __debug_iter<basic_string, pointer> iterator; 1072 typedef __debug_iter<basic_string, const_pointer> const_iterator; 1073 1074 friend class __debug_iter<basic_string, pointer>; 1075 friend class __debug_iter<basic_string, const_pointer>; 1076#elif defined(_LIBCPP_RAW_ITERATORS) 1077 typedef pointer iterator; 1078 typedef const_pointer const_iterator; 1079#else // defined(_LIBCPP_RAW_ITERATORS) 1080 typedef __wrap_iter<pointer> iterator; 1081 typedef __wrap_iter<const_pointer> const_iterator; 1082#endif // defined(_LIBCPP_RAW_ITERATORS) 1083 typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 1084 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 1085 1086private: 1087 1088#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT 1089 1090 struct __long 1091 { 1092 pointer __data_; 1093 size_type __size_; 1094 size_type __cap_; 1095 }; 1096 1097#if _LIBCPP_BIG_ENDIAN 1098 enum {__short_mask = 0x01}; 1099 enum {__long_mask = 0x1ul}; 1100#else // _LIBCPP_BIG_ENDIAN 1101 enum {__short_mask = 0x80}; 1102 enum {__long_mask = ~(size_type(~0) >> 1)}; 1103#endif // _LIBCPP_BIG_ENDIAN 1104 1105 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? 1106 (sizeof(__long) - 1)/sizeof(value_type) : 2}; 1107 1108 struct __short 1109 { 1110 value_type __data_[__min_cap]; 1111 struct 1112 : __padding<value_type> 1113 { 1114 unsigned char __size_; 1115 }; 1116 }; 1117 1118#else 1119 1120 struct __long 1121 { 1122 size_type __cap_; 1123 size_type __size_; 1124 pointer __data_; 1125 }; 1126 1127#if _LIBCPP_BIG_ENDIAN 1128 enum {__short_mask = 0x80}; 1129 enum {__long_mask = ~(size_type(~0) >> 1)}; 1130#else // _LIBCPP_BIG_ENDIAN 1131 enum {__short_mask = 0x01}; 1132 enum {__long_mask = 0x1ul}; 1133#endif // _LIBCPP_BIG_ENDIAN 1134 1135 enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? 1136 (sizeof(__long) - 1)/sizeof(value_type) : 2}; 1137 1138 struct __short 1139 { 1140 union 1141 { 1142 unsigned char __size_; 1143 value_type __lx; 1144 }; 1145 value_type __data_[__min_cap]; 1146 }; 1147 1148#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT 1149 1150 union __lx{__long __lx; __short __lxx;}; 1151 1152 enum {__n_words = sizeof(__lx) / sizeof(size_type)}; 1153 1154 struct __raw 1155 { 1156 size_type __words[__n_words]; 1157 }; 1158 1159 struct __rep 1160 { 1161 union 1162 { 1163 __long __l; 1164 __short __s; 1165 __raw __r; 1166 }; 1167 }; 1168 1169 __compressed_pair<__rep, allocator_type> __r_; 1170 1171#ifdef _LIBCPP_DEBUG 1172 1173 pair<iterator*, const_iterator*> __iterator_list_; 1174 1175 _LIBCPP_INLINE_VISIBILITY iterator*& __get_iterator_list(iterator*) {return __iterator_list_.first;} 1176 _LIBCPP_INLINE_VISIBILITY const_iterator*& __get_iterator_list(const_iterator*) {return __iterator_list_.second;} 1177 1178#endif // _LIBCPP_DEBUG 1179 1180public: 1181 static const size_type npos = -1; 1182 1183 _LIBCPP_INLINE_VISIBILITY basic_string() 1184 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 1185 _LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a); 1186 basic_string(const basic_string& __str); 1187 basic_string(const basic_string& __str, const allocator_type& __a); 1188#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1189 _LIBCPP_INLINE_VISIBILITY 1190 basic_string(basic_string&& __str) 1191 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 1192 _LIBCPP_INLINE_VISIBILITY 1193 basic_string(basic_string&& __str, const allocator_type& __a); 1194#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1195 _LIBCPP_INLINE_VISIBILITY basic_string(const_pointer __s); 1196 _LIBCPP_INLINE_VISIBILITY 1197 basic_string(const_pointer __s, const allocator_type& __a); 1198 _LIBCPP_INLINE_VISIBILITY 1199 basic_string(const_pointer __s, size_type __n); 1200 _LIBCPP_INLINE_VISIBILITY 1201 basic_string(const_pointer __s, size_type __n, const allocator_type& __a); 1202 _LIBCPP_INLINE_VISIBILITY 1203 basic_string(size_type __n, value_type __c); 1204 _LIBCPP_INLINE_VISIBILITY 1205 basic_string(size_type __n, value_type __c, const allocator_type& __a); 1206 basic_string(const basic_string& __str, size_type __pos, size_type __n = npos, 1207 const allocator_type& __a = allocator_type()); 1208 template<class _InputIterator> 1209 _LIBCPP_INLINE_VISIBILITY 1210 basic_string(_InputIterator __first, _InputIterator __last); 1211 template<class _InputIterator> 1212 _LIBCPP_INLINE_VISIBILITY 1213 basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); 1214#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1215 _LIBCPP_INLINE_VISIBILITY 1216 basic_string(initializer_list<value_type> __il); 1217 _LIBCPP_INLINE_VISIBILITY 1218 basic_string(initializer_list<value_type> __il, const allocator_type& __a); 1219#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1220 1221 ~basic_string(); 1222 1223 basic_string& operator=(const basic_string& __str); 1224#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1225 _LIBCPP_INLINE_VISIBILITY 1226 basic_string& operator=(basic_string&& __str) 1227 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 1228 is_nothrow_move_assignable<allocator_type>::value); 1229#endif 1230 _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const_pointer __s) {return assign(__s);} 1231 basic_string& operator=(value_type __c); 1232#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1233 _LIBCPP_INLINE_VISIBILITY 1234 basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} 1235#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1236 1237#ifndef _LIBCPP_DEBUG 1238 _LIBCPP_INLINE_VISIBILITY 1239 iterator begin() _NOEXCEPT 1240 {return iterator(__get_pointer());} 1241 _LIBCPP_INLINE_VISIBILITY 1242 const_iterator begin() const _NOEXCEPT 1243 {return const_iterator(data());} 1244 _LIBCPP_INLINE_VISIBILITY 1245 iterator end() _NOEXCEPT 1246 {return iterator(__get_pointer() + size());} 1247 _LIBCPP_INLINE_VISIBILITY 1248 const_iterator end() const _NOEXCEPT 1249 {return const_iterator(data() + size());} 1250#else // _LIBCPP_DEBUG 1251 _LIBCPP_INLINE_VISIBILITY iterator begin() {return iterator(this, __get_pointer());} 1252 _LIBCPP_INLINE_VISIBILITY const_iterator begin() const {return const_iterator(this, data());} 1253 _LIBCPP_INLINE_VISIBILITY iterator end() {return iterator(this, __get_pointer() + size());} 1254 _LIBCPP_INLINE_VISIBILITY const_iterator end() const {return const_iterator(this, data() + size());} 1255#endif // _LIBCPP_DEBUG 1256 _LIBCPP_INLINE_VISIBILITY 1257 reverse_iterator rbegin() _NOEXCEPT 1258 {return reverse_iterator(end());} 1259 _LIBCPP_INLINE_VISIBILITY 1260 const_reverse_iterator rbegin() const _NOEXCEPT 1261 {return const_reverse_iterator(end());} 1262 _LIBCPP_INLINE_VISIBILITY 1263 reverse_iterator rend() _NOEXCEPT 1264 {return reverse_iterator(begin());} 1265 _LIBCPP_INLINE_VISIBILITY 1266 const_reverse_iterator rend() const _NOEXCEPT 1267 {return const_reverse_iterator(begin());} 1268 1269 _LIBCPP_INLINE_VISIBILITY 1270 const_iterator cbegin() const _NOEXCEPT 1271 {return begin();} 1272 _LIBCPP_INLINE_VISIBILITY 1273 const_iterator cend() const _NOEXCEPT 1274 {return end();} 1275 _LIBCPP_INLINE_VISIBILITY 1276 const_reverse_iterator crbegin() const _NOEXCEPT 1277 {return rbegin();} 1278 _LIBCPP_INLINE_VISIBILITY 1279 const_reverse_iterator crend() const _NOEXCEPT 1280 {return rend();} 1281 1282 _LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT 1283 {return __is_long() ? __get_long_size() : __get_short_size();} 1284 _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();} 1285 _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT; 1286 _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT 1287 {return (__is_long() ? __get_long_cap() : __min_cap) - 1;} 1288 1289 void resize(size_type __n, value_type __c); 1290 _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} 1291 1292 void reserve(size_type res_arg = 0); 1293 _LIBCPP_INLINE_VISIBILITY 1294 void shrink_to_fit() _NOEXCEPT {reserve();} 1295 _LIBCPP_INLINE_VISIBILITY 1296 void clear() _NOEXCEPT; 1297 _LIBCPP_INLINE_VISIBILITY bool empty() const _NOEXCEPT {return size() == 0;} 1298 1299 _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const; 1300 _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos); 1301 1302 const_reference at(size_type __n) const; 1303 reference at(size_type __n); 1304 1305 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);} 1306 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const_pointer __s) {return append(__s);} 1307 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;} 1308#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1309 _LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);} 1310#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1311 1312 _LIBCPP_INLINE_VISIBILITY 1313 basic_string& append(const basic_string& __str); 1314 basic_string& append(const basic_string& __str, size_type __pos, size_type __n); 1315 basic_string& append(const_pointer __s, size_type __n); 1316 basic_string& append(const_pointer __s); 1317 basic_string& append(size_type __n, value_type __c); 1318 template<class _InputIterator> 1319 typename enable_if 1320 < 1321 __is_input_iterator <_InputIterator>::value && 1322 !__is_forward_iterator<_InputIterator>::value, 1323 basic_string& 1324 >::type 1325 append(_InputIterator __first, _InputIterator __last); 1326 template<class _ForwardIterator> 1327 typename enable_if 1328 < 1329 __is_forward_iterator<_ForwardIterator>::value, 1330 basic_string& 1331 >::type 1332 append(_ForwardIterator __first, _ForwardIterator __last); 1333#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1334 _LIBCPP_INLINE_VISIBILITY 1335 basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} 1336#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1337 1338 void push_back(value_type __c); 1339 _LIBCPP_INLINE_VISIBILITY 1340 void pop_back(); 1341 _LIBCPP_INLINE_VISIBILITY reference front(); 1342 _LIBCPP_INLINE_VISIBILITY const_reference front() const; 1343 _LIBCPP_INLINE_VISIBILITY reference back(); 1344 _LIBCPP_INLINE_VISIBILITY const_reference back() const; 1345 1346 _LIBCPP_INLINE_VISIBILITY 1347 basic_string& assign(const basic_string& __str); 1348#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1349 _LIBCPP_INLINE_VISIBILITY 1350 basic_string& assign(basic_string&& str) 1351 {*this = _VSTD::move(str); return *this;} 1352#endif 1353 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n); 1354 basic_string& assign(const_pointer __s, size_type __n); 1355 basic_string& assign(const_pointer __s); 1356 basic_string& assign(size_type __n, value_type __c); 1357 template<class _InputIterator> 1358 typename enable_if 1359 < 1360 __is_input_iterator <_InputIterator>::value && 1361 !__is_forward_iterator<_InputIterator>::value, 1362 basic_string& 1363 >::type 1364 assign(_InputIterator __first, _InputIterator __last); 1365 template<class _ForwardIterator> 1366 typename enable_if 1367 < 1368 __is_forward_iterator<_ForwardIterator>::value, 1369 basic_string& 1370 >::type 1371 assign(_ForwardIterator __first, _ForwardIterator __last); 1372#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1373 _LIBCPP_INLINE_VISIBILITY 1374 basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} 1375#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1376 1377 _LIBCPP_INLINE_VISIBILITY 1378 basic_string& insert(size_type __pos1, const basic_string& __str); 1379 basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n); 1380 basic_string& insert(size_type __pos, const_pointer __s, size_type __n); 1381 basic_string& insert(size_type __pos, const_pointer __s); 1382 basic_string& insert(size_type __pos, size_type __n, value_type __c); 1383 iterator insert(const_iterator __pos, value_type __c); 1384 _LIBCPP_INLINE_VISIBILITY 1385 iterator insert(const_iterator __pos, size_type __n, value_type __c); 1386 template<class _InputIterator> 1387 typename enable_if 1388 < 1389 __is_input_iterator <_InputIterator>::value && 1390 !__is_forward_iterator<_InputIterator>::value, 1391 iterator 1392 >::type 1393 insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); 1394 template<class _ForwardIterator> 1395 typename enable_if 1396 < 1397 __is_forward_iterator<_ForwardIterator>::value, 1398 iterator 1399 >::type 1400 insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); 1401#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1402 _LIBCPP_INLINE_VISIBILITY 1403 iterator insert(const_iterator __pos, initializer_list<value_type> __il) 1404 {return insert(__pos, __il.begin(), __il.end());} 1405#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1406 1407 basic_string& erase(size_type __pos = 0, size_type __n = npos); 1408 _LIBCPP_INLINE_VISIBILITY 1409 iterator erase(const_iterator __pos); 1410 _LIBCPP_INLINE_VISIBILITY 1411 iterator erase(const_iterator __first, const_iterator __last); 1412 1413 _LIBCPP_INLINE_VISIBILITY 1414 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); 1415 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2); 1416 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2); 1417 basic_string& replace(size_type __pos, size_type __n1, const_pointer __s); 1418 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); 1419 _LIBCPP_INLINE_VISIBILITY 1420 basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str); 1421 _LIBCPP_INLINE_VISIBILITY 1422 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n); 1423 _LIBCPP_INLINE_VISIBILITY 1424 basic_string& replace(const_iterator __i1, const_iterator __i2, const_pointer __s); 1425 _LIBCPP_INLINE_VISIBILITY 1426 basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); 1427 template<class _InputIterator> 1428 typename enable_if 1429 < 1430 __is_input_iterator<_InputIterator>::value, 1431 basic_string& 1432 >::type 1433 replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); 1434#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1435 _LIBCPP_INLINE_VISIBILITY 1436 basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) 1437 {return replace(__i1, __i2, __il.begin(), __il.end());} 1438#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1439 1440 size_type copy(pointer __s, size_type __n, size_type __pos = 0) const; 1441 _LIBCPP_INLINE_VISIBILITY 1442 basic_string substr(size_type __pos = 0, size_type __n = npos) const; 1443 1444 _LIBCPP_INLINE_VISIBILITY 1445 void swap(basic_string& __str) 1446 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 1447 __is_nothrow_swappable<allocator_type>::value); 1448 1449 _LIBCPP_INLINE_VISIBILITY 1450 const_pointer c_str() const _NOEXCEPT {return data();} 1451 _LIBCPP_INLINE_VISIBILITY 1452 const_pointer data() const _NOEXCEPT {return __get_pointer();} 1453 1454 _LIBCPP_INLINE_VISIBILITY 1455 allocator_type get_allocator() const _NOEXCEPT {return __alloc();} 1456 1457 _LIBCPP_INLINE_VISIBILITY 1458 size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 1459 size_type find(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; 1460 _LIBCPP_INLINE_VISIBILITY 1461 size_type find(const_pointer __s, size_type __pos = 0) const _NOEXCEPT; 1462 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; 1463 1464 _LIBCPP_INLINE_VISIBILITY 1465 size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 1466 size_type rfind(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; 1467 _LIBCPP_INLINE_VISIBILITY 1468 size_type rfind(const_pointer __s, size_type __pos = npos) const _NOEXCEPT; 1469 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; 1470 1471 _LIBCPP_INLINE_VISIBILITY 1472 size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 1473 size_type find_first_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; 1474 _LIBCPP_INLINE_VISIBILITY 1475 size_type find_first_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT; 1476 _LIBCPP_INLINE_VISIBILITY 1477 size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; 1478 1479 _LIBCPP_INLINE_VISIBILITY 1480 size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 1481 size_type find_last_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; 1482 _LIBCPP_INLINE_VISIBILITY 1483 size_type find_last_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT; 1484 _LIBCPP_INLINE_VISIBILITY 1485 size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; 1486 1487 _LIBCPP_INLINE_VISIBILITY 1488 size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 1489 size_type find_first_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; 1490 _LIBCPP_INLINE_VISIBILITY 1491 size_type find_first_not_of(const_pointer __s, size_type __pos = 0) const _NOEXCEPT; 1492 _LIBCPP_INLINE_VISIBILITY 1493 size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; 1494 1495 _LIBCPP_INLINE_VISIBILITY 1496 size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 1497 size_type find_last_not_of(const_pointer __s, size_type __pos, size_type __n) const _NOEXCEPT; 1498 _LIBCPP_INLINE_VISIBILITY 1499 size_type find_last_not_of(const_pointer __s, size_type __pos = npos) const _NOEXCEPT; 1500 _LIBCPP_INLINE_VISIBILITY 1501 size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; 1502 1503 _LIBCPP_INLINE_VISIBILITY 1504 int compare(const basic_string& __str) const _NOEXCEPT; 1505 _LIBCPP_INLINE_VISIBILITY 1506 int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; 1507 int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2) const; 1508 int compare(const_pointer __s) const _NOEXCEPT; 1509 int compare(size_type __pos1, size_type __n1, const_pointer __s) const; 1510 int compare(size_type __pos1, size_type __n1, const_pointer __s, size_type __n2) const; 1511 1512 _LIBCPP_INLINE_VISIBILITY bool __invariants() const; 1513 1514 _LIBCPP_INLINE_VISIBILITY 1515 bool __is_long() const _NOEXCEPT 1516 {return bool(__r_.first().__s.__size_ & __short_mask);} 1517 1518private: 1519 _LIBCPP_INLINE_VISIBILITY 1520 allocator_type& __alloc() _NOEXCEPT 1521 {return __r_.second();} 1522 _LIBCPP_INLINE_VISIBILITY 1523 const allocator_type& __alloc() const _NOEXCEPT 1524 {return __r_.second();} 1525 1526#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT 1527 1528 _LIBCPP_INLINE_VISIBILITY 1529 void __set_short_size(size_type __s) _NOEXCEPT 1530# if _LIBCPP_BIG_ENDIAN 1531 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} 1532# else 1533 {__r_.first().__s.__size_ = (unsigned char)(__s);} 1534# endif 1535 1536 _LIBCPP_INLINE_VISIBILITY 1537 size_type __get_short_size() const _NOEXCEPT 1538# if _LIBCPP_BIG_ENDIAN 1539 {return __r_.first().__s.__size_ >> 1;} 1540# else 1541 {return __r_.first().__s.__size_;} 1542# endif 1543 1544#else // _LIBCPP_ALTERNATE_STRING_LAYOUT 1545 1546 _LIBCPP_INLINE_VISIBILITY 1547 void __set_short_size(size_type __s) _NOEXCEPT 1548# if _LIBCPP_BIG_ENDIAN 1549 {__r_.first().__s.__size_ = (unsigned char)(__s);} 1550# else 1551 {__r_.first().__s.__size_ = (unsigned char)(__s << 1);} 1552# endif 1553 1554 _LIBCPP_INLINE_VISIBILITY 1555 size_type __get_short_size() const _NOEXCEPT 1556# if _LIBCPP_BIG_ENDIAN 1557 {return __r_.first().__s.__size_;} 1558# else 1559 {return __r_.first().__s.__size_ >> 1;} 1560# endif 1561 1562#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT 1563 1564 _LIBCPP_INLINE_VISIBILITY 1565 void __set_long_size(size_type __s) _NOEXCEPT 1566 {__r_.first().__l.__size_ = __s;} 1567 _LIBCPP_INLINE_VISIBILITY 1568 size_type __get_long_size() const _NOEXCEPT 1569 {return __r_.first().__l.__size_;} 1570 _LIBCPP_INLINE_VISIBILITY 1571 void __set_size(size_type __s) _NOEXCEPT 1572 {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} 1573 1574 _LIBCPP_INLINE_VISIBILITY 1575 void __set_long_cap(size_type __s) _NOEXCEPT 1576 {__r_.first().__l.__cap_ = __long_mask | __s;} 1577 _LIBCPP_INLINE_VISIBILITY 1578 size_type __get_long_cap() const _NOEXCEPT 1579 {return __r_.first().__l.__cap_ & size_type(~__long_mask);} 1580 1581 _LIBCPP_INLINE_VISIBILITY 1582 void __set_long_pointer(pointer __p) _NOEXCEPT 1583 {__r_.first().__l.__data_ = __p;} 1584 _LIBCPP_INLINE_VISIBILITY 1585 pointer __get_long_pointer() _NOEXCEPT 1586 {return __r_.first().__l.__data_;} 1587 _LIBCPP_INLINE_VISIBILITY 1588 const_pointer __get_long_pointer() const _NOEXCEPT 1589 {return __r_.first().__l.__data_;} 1590 _LIBCPP_INLINE_VISIBILITY 1591 pointer __get_short_pointer() _NOEXCEPT 1592 {return __r_.first().__s.__data_;} 1593 _LIBCPP_INLINE_VISIBILITY 1594 const_pointer __get_short_pointer() const _NOEXCEPT 1595 {return __r_.first().__s.__data_;} 1596 _LIBCPP_INLINE_VISIBILITY 1597 pointer __get_pointer() _NOEXCEPT 1598 {return __is_long() ? __get_long_pointer() : __get_short_pointer();} 1599 _LIBCPP_INLINE_VISIBILITY 1600 const_pointer __get_pointer() const _NOEXCEPT 1601 {return __is_long() ? __get_long_pointer() : __get_short_pointer();} 1602 1603 _LIBCPP_INLINE_VISIBILITY 1604 void __zero() _NOEXCEPT 1605 { 1606 size_type (&__a)[__n_words] = __r_.first().__r.__words; 1607 for (unsigned __i = 0; __i < __n_words; ++__i) 1608 __a[__i] = 0; 1609 } 1610 1611 template <size_type __a> static 1612 _LIBCPP_INLINE_VISIBILITY 1613 size_type __align(size_type __s) _NOEXCEPT 1614 {return __s + (__a-1) & ~(__a-1);} 1615 enum {__alignment = 16}; 1616 static _LIBCPP_INLINE_VISIBILITY 1617 size_type __recommend(size_type __s) _NOEXCEPT 1618 {return (__s < __min_cap ? __min_cap : 1619 __align<sizeof(value_type) < __alignment ? 1620 __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;} 1621 1622 void __init(const_pointer __s, size_type __sz, size_type __reserve); 1623 void __init(const_pointer __s, size_type __sz); 1624 void __init(size_type __n, value_type __c); 1625 1626 template <class _InputIterator> 1627 typename enable_if 1628 < 1629 __is_input_iterator <_InputIterator>::value && 1630 !__is_forward_iterator<_InputIterator>::value, 1631 void 1632 >::type 1633 __init(_InputIterator __first, _InputIterator __last); 1634 1635 template <class _ForwardIterator> 1636 typename enable_if 1637 < 1638 __is_forward_iterator<_ForwardIterator>::value, 1639 void 1640 >::type 1641 __init(_ForwardIterator __first, _ForwardIterator __last); 1642 1643 void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 1644 size_type __n_copy, size_type __n_del, size_type __n_add = 0); 1645 void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 1646 size_type __n_copy, size_type __n_del, 1647 size_type __n_add, const_pointer __p_new_stuff); 1648 1649 _LIBCPP_INLINE_VISIBILITY 1650 void __erase_to_end(size_type __pos); 1651 1652 _LIBCPP_INLINE_VISIBILITY 1653 void __copy_assign_alloc(const basic_string& __str) 1654 {__copy_assign_alloc(__str, integral_constant<bool, 1655 __alloc_traits::propagate_on_container_copy_assignment::value>());} 1656 1657 _LIBCPP_INLINE_VISIBILITY 1658 void __copy_assign_alloc(const basic_string& __str, true_type) 1659 { 1660 if (__alloc() != __str.__alloc()) 1661 { 1662 clear(); 1663 shrink_to_fit(); 1664 } 1665 __alloc() = __str.__alloc(); 1666 } 1667 1668 _LIBCPP_INLINE_VISIBILITY 1669 void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT 1670 {} 1671 1672#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1673 _LIBCPP_INLINE_VISIBILITY 1674 void __move_assign(basic_string& __str, false_type); 1675 _LIBCPP_INLINE_VISIBILITY 1676 void __move_assign(basic_string& __str, true_type) 1677 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 1678#endif 1679 1680 _LIBCPP_INLINE_VISIBILITY 1681 void 1682 __move_assign_alloc(basic_string& __str) 1683 _NOEXCEPT_( 1684 !__alloc_traits::propagate_on_container_move_assignment::value || 1685 is_nothrow_move_assignable<allocator_type>::value) 1686 {__move_assign_alloc(__str, integral_constant<bool, 1687 __alloc_traits::propagate_on_container_move_assignment::value>());} 1688 1689 _LIBCPP_INLINE_VISIBILITY 1690 void __move_assign_alloc(basic_string& __c, true_type) 1691 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 1692 { 1693 __alloc() = _VSTD::move(__c.__alloc()); 1694 } 1695 1696 _LIBCPP_INLINE_VISIBILITY 1697 void __move_assign_alloc(basic_string&, false_type) 1698 _NOEXCEPT 1699 {} 1700 1701 _LIBCPP_INLINE_VISIBILITY 1702 static void __swap_alloc(allocator_type& __x, allocator_type& __y) 1703 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 1704 __is_nothrow_swappable<allocator_type>::value) 1705 {__swap_alloc(__x, __y, integral_constant<bool, 1706 __alloc_traits::propagate_on_container_swap::value>());} 1707 1708 _LIBCPP_INLINE_VISIBILITY 1709 static void __swap_alloc(allocator_type& __x, allocator_type& __y, true_type) 1710 _NOEXCEPT_(__is_nothrow_swappable<allocator_type>::value) 1711 { 1712 using _VSTD::swap; 1713 swap(__x, __y); 1714 } 1715 _LIBCPP_INLINE_VISIBILITY 1716 static void __swap_alloc(allocator_type&, allocator_type&, false_type) _NOEXCEPT 1717 {} 1718 1719 _LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators(); 1720 _LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type); 1721 1722 friend basic_string operator+<>(const basic_string&, const basic_string&); 1723 friend basic_string operator+<>(const value_type*, const basic_string&); 1724 friend basic_string operator+<>(value_type, const basic_string&); 1725 friend basic_string operator+<>(const basic_string&, const value_type*); 1726 friend basic_string operator+<>(const basic_string&, value_type); 1727}; 1728 1729template <class _CharT, class _Traits, class _Allocator> 1730#ifndef _LIBCPP_DEBUG 1731_LIBCPP_INLINE_VISIBILITY inline 1732#endif 1733void 1734basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() 1735{ 1736#ifdef _LIBCPP_DEBUG 1737 iterator::__remove_all(this); 1738 const_iterator::__remove_all(this); 1739#endif // _LIBCPP_DEBUG 1740} 1741 1742template <class _CharT, class _Traits, class _Allocator> 1743#ifndef _LIBCPP_DEBUG 1744_LIBCPP_INLINE_VISIBILITY inline 1745#endif 1746void 1747basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type 1748#ifdef _LIBCPP_DEBUG 1749 __pos 1750#endif 1751 ) 1752{ 1753#ifdef _LIBCPP_DEBUG 1754 const_iterator __beg = begin(); 1755 if (__iterator_list_.first) 1756 { 1757 for (iterator* __p = __iterator_list_.first; __p;) 1758 { 1759 if (*__p - __beg > static_cast<difference_type>(__pos)) 1760 { 1761 iterator* __n = __p; 1762 __p = __p->__next; 1763 __n->__remove_owner(); 1764 } 1765 else 1766 __p = __p->__next; 1767 } 1768 } 1769 if (__iterator_list_.second) 1770 { 1771 for (const_iterator* __p = __iterator_list_.second; __p;) 1772 { 1773 if (*__p - __beg > static_cast<difference_type>(__pos)) 1774 { 1775 const_iterator* __n = __p; 1776 __p = __p->__next; 1777 __n->__remove_owner(); 1778 } 1779 else 1780 __p = __p->__next; 1781 } 1782 } 1783#endif // _LIBCPP_DEBUG 1784} 1785 1786template <class _CharT, class _Traits, class _Allocator> 1787_LIBCPP_INLINE_VISIBILITY inline 1788basic_string<_CharT, _Traits, _Allocator>::basic_string() 1789 _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 1790{ 1791 __zero(); 1792} 1793 1794template <class _CharT, class _Traits, class _Allocator> 1795_LIBCPP_INLINE_VISIBILITY inline 1796basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) 1797 : __r_(__a) 1798{ 1799 __zero(); 1800} 1801 1802template <class _CharT, class _Traits, class _Allocator> 1803void 1804basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz, size_type __reserve) 1805{ 1806 if (__reserve > max_size()) 1807 this->__throw_length_error(); 1808 pointer __p; 1809 if (__reserve < __min_cap) 1810 { 1811 __set_short_size(__sz); 1812 __p = __get_short_pointer(); 1813 } 1814 else 1815 { 1816 size_type __cap = __recommend(__reserve); 1817 __p = __alloc_traits::allocate(__alloc(), __cap+1); 1818 __set_long_pointer(__p); 1819 __set_long_cap(__cap+1); 1820 __set_long_size(__sz); 1821 } 1822 traits_type::copy(__p, __s, __sz); 1823 traits_type::assign(__p[__sz], value_type()); 1824} 1825 1826template <class _CharT, class _Traits, class _Allocator> 1827void 1828basic_string<_CharT, _Traits, _Allocator>::__init(const_pointer __s, size_type __sz) 1829{ 1830 if (__sz > max_size()) 1831 this->__throw_length_error(); 1832 pointer __p; 1833 if (__sz < __min_cap) 1834 { 1835 __set_short_size(__sz); 1836 __p = __get_short_pointer(); 1837 } 1838 else 1839 { 1840 size_type __cap = __recommend(__sz); 1841 __p = __alloc_traits::allocate(__alloc(), __cap+1); 1842 __set_long_pointer(__p); 1843 __set_long_cap(__cap+1); 1844 __set_long_size(__sz); 1845 } 1846 traits_type::copy(__p, __s, __sz); 1847 traits_type::assign(__p[__sz], value_type()); 1848} 1849 1850template <class _CharT, class _Traits, class _Allocator> 1851_LIBCPP_INLINE_VISIBILITY inline 1852basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s) 1853{ 1854#ifdef _LIBCPP_DEBUG 1855 assert(__s != 0); 1856#endif 1857 __init(__s, traits_type::length(__s)); 1858} 1859 1860template <class _CharT, class _Traits, class _Allocator> 1861_LIBCPP_INLINE_VISIBILITY inline 1862basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, const allocator_type& __a) 1863 : __r_(__a) 1864{ 1865#ifdef _LIBCPP_DEBUG 1866 assert(__s != 0); 1867#endif 1868 __init(__s, traits_type::length(__s)); 1869} 1870 1871template <class _CharT, class _Traits, class _Allocator> 1872_LIBCPP_INLINE_VISIBILITY inline 1873basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n) 1874{ 1875#ifdef _LIBCPP_DEBUG 1876 assert(__s != 0); 1877#endif 1878 __init(__s, __n); 1879} 1880 1881template <class _CharT, class _Traits, class _Allocator> 1882_LIBCPP_INLINE_VISIBILITY inline 1883basic_string<_CharT, _Traits, _Allocator>::basic_string(const_pointer __s, size_type __n, const allocator_type& __a) 1884 : __r_(__a) 1885{ 1886#ifdef _LIBCPP_DEBUG 1887 assert(__s != 0); 1888#endif 1889 __init(__s, __n); 1890} 1891 1892template <class _CharT, class _Traits, class _Allocator> 1893basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) 1894 : __r_(__alloc_traits::select_on_container_copy_construction(__str.__alloc())) 1895{ 1896 if (!__str.__is_long()) 1897 __r_.first().__r = __str.__r_.first().__r; 1898 else 1899 __init(__str.__get_long_pointer(), __str.__get_long_size()); 1900} 1901 1902template <class _CharT, class _Traits, class _Allocator> 1903basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, const allocator_type& __a) 1904 : __r_(__a) 1905{ 1906 if (!__str.__is_long()) 1907 __r_.first().__r = __str.__r_.first().__r; 1908 else 1909 __init(__str.__get_long_pointer(), __str.__get_long_size()); 1910} 1911 1912#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1913 1914template <class _CharT, class _Traits, class _Allocator> 1915_LIBCPP_INLINE_VISIBILITY inline 1916basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) 1917 _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 1918 : __r_(_VSTD::move(__str.__r_)) 1919{ 1920 __str.__zero(); 1921#ifdef _LIBCPP_DEBUG 1922 __str.__invalidate_all_iterators(); 1923#endif 1924} 1925 1926template <class _CharT, class _Traits, class _Allocator> 1927_LIBCPP_INLINE_VISIBILITY inline 1928basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) 1929 : __r_(__a) 1930{ 1931 if (__a == __str.__alloc() || !__str.__is_long()) 1932 __r_.first().__r = __str.__r_.first().__r; 1933 else 1934 __init(__str.__get_long_pointer(), __str.__get_long_size()); 1935 __str.__zero(); 1936#ifdef _LIBCPP_DEBUG 1937 __str.__invalidate_all_iterators(); 1938#endif 1939} 1940 1941#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1942 1943template <class _CharT, class _Traits, class _Allocator> 1944void 1945basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) 1946{ 1947 if (__n > max_size()) 1948 this->__throw_length_error(); 1949 pointer __p; 1950 if (__n < __min_cap) 1951 { 1952 __set_short_size(__n); 1953 __p = __get_short_pointer(); 1954 } 1955 else 1956 { 1957 size_type __cap = __recommend(__n); 1958 __p = __alloc_traits::allocate(__alloc(), __cap+1); 1959 __set_long_pointer(__p); 1960 __set_long_cap(__cap+1); 1961 __set_long_size(__n); 1962 } 1963 traits_type::assign(__p, __n, __c); 1964 traits_type::assign(__p[__n], value_type()); 1965} 1966 1967template <class _CharT, class _Traits, class _Allocator> 1968_LIBCPP_INLINE_VISIBILITY inline 1969basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c) 1970{ 1971 __init(__n, __c); 1972} 1973 1974template <class _CharT, class _Traits, class _Allocator> 1975_LIBCPP_INLINE_VISIBILITY inline 1976basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, value_type __c, const allocator_type& __a) 1977 : __r_(__a) 1978{ 1979 __init(__n, __c); 1980} 1981 1982template <class _CharT, class _Traits, class _Allocator> 1983basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, size_type __n, 1984 const allocator_type& __a) 1985 : __r_(__a) 1986{ 1987 size_type __str_sz = __str.size(); 1988 if (__pos > __str_sz) 1989 this->__throw_out_of_range(); 1990 __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); 1991} 1992 1993template <class _CharT, class _Traits, class _Allocator> 1994template <class _InputIterator> 1995typename enable_if 1996< 1997 __is_input_iterator <_InputIterator>::value && 1998 !__is_forward_iterator<_InputIterator>::value, 1999 void 2000>::type 2001basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) 2002{ 2003 __zero(); 2004#ifndef _LIBCPP_NO_EXCEPTIONS 2005 try 2006 { 2007#endif // _LIBCPP_NO_EXCEPTIONS 2008 for (; __first != __last; ++__first) 2009 push_back(*__first); 2010#ifndef _LIBCPP_NO_EXCEPTIONS 2011 } 2012 catch (...) 2013 { 2014 if (__is_long()) 2015 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 2016 throw; 2017 } 2018#endif // _LIBCPP_NO_EXCEPTIONS 2019} 2020 2021template <class _CharT, class _Traits, class _Allocator> 2022template <class _ForwardIterator> 2023typename enable_if 2024< 2025 __is_forward_iterator<_ForwardIterator>::value, 2026 void 2027>::type 2028basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) 2029{ 2030 size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last)); 2031 if (__sz > max_size()) 2032 this->__throw_length_error(); 2033 pointer __p; 2034 if (__sz < __min_cap) 2035 { 2036 __set_short_size(__sz); 2037 __p = __get_short_pointer(); 2038 } 2039 else 2040 { 2041 size_type __cap = __recommend(__sz); 2042 __p = __alloc_traits::allocate(__alloc(), __cap+1); 2043 __set_long_pointer(__p); 2044 __set_long_cap(__cap+1); 2045 __set_long_size(__sz); 2046 } 2047 for (; __first != __last; ++__first, ++__p) 2048 traits_type::assign(*__p, *__first); 2049 traits_type::assign(*__p, value_type()); 2050} 2051 2052template <class _CharT, class _Traits, class _Allocator> 2053template<class _InputIterator> 2054_LIBCPP_INLINE_VISIBILITY inline 2055basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) 2056{ 2057 __init(__first, __last); 2058} 2059 2060template <class _CharT, class _Traits, class _Allocator> 2061template<class _InputIterator> 2062_LIBCPP_INLINE_VISIBILITY inline 2063basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, 2064 const allocator_type& __a) 2065 : __r_(__a) 2066{ 2067 __init(__first, __last); 2068} 2069 2070#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2071 2072template <class _CharT, class _Traits, class _Allocator> 2073_LIBCPP_INLINE_VISIBILITY inline 2074basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il) 2075{ 2076 __init(__il.begin(), __il.end()); 2077} 2078 2079template <class _CharT, class _Traits, class _Allocator> 2080_LIBCPP_INLINE_VISIBILITY inline 2081basic_string<_CharT, _Traits, _Allocator>::basic_string(initializer_list<value_type> __il, const allocator_type& __a) 2082 : __r_(__a) 2083{ 2084 __init(__il.begin(), __il.end()); 2085} 2086 2087#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 2088 2089template <class _CharT, class _Traits, class _Allocator> 2090basic_string<_CharT, _Traits, _Allocator>::~basic_string() 2091{ 2092 __invalidate_all_iterators(); 2093 if (__is_long()) 2094 __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 2095} 2096 2097template <class _CharT, class _Traits, class _Allocator> 2098void 2099basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace 2100 (size_type __old_cap, size_type __delta_cap, size_type __old_sz, 2101 size_type __n_copy, size_type __n_del, size_type __n_add, const_pointer __p_new_stuff) 2102{ 2103 size_type __ms = max_size(); 2104 if (__delta_cap > __ms - __old_cap - 1) 2105 this->__throw_length_error(); 2106 pointer __old_p = __get_pointer(); 2107 size_type __cap = __old_cap < __ms / 2 - __alignment ? 2108 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : 2109 __ms - 1; 2110 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); 2111 __invalidate_all_iterators(); 2112 if (__n_copy != 0) 2113 traits_type::copy(__p, __old_p, __n_copy); 2114 if (__n_add != 0) 2115 traits_type::copy(__p + __n_copy, __p_new_stuff, __n_add); 2116 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 2117 if (__sec_cp_sz != 0) 2118 traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz); 2119 if (__old_cap+1 != __min_cap) 2120 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); 2121 __set_long_pointer(__p); 2122 __set_long_cap(__cap+1); 2123 __old_sz = __n_copy + __n_add + __sec_cp_sz; 2124 __set_long_size(__old_sz); 2125 traits_type::assign(__p[__old_sz], value_type()); 2126} 2127 2128template <class _CharT, class _Traits, class _Allocator> 2129void 2130basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 2131 size_type __n_copy, size_type __n_del, size_type __n_add) 2132{ 2133 size_type __ms = max_size(); 2134 if (__delta_cap > __ms - __old_cap - 1) 2135 this->__throw_length_error(); 2136 pointer __old_p = __get_pointer(); 2137 size_type __cap = __old_cap < __ms / 2 - __alignment ? 2138 __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : 2139 __ms - 1; 2140 pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); 2141 __invalidate_all_iterators(); 2142 if (__n_copy != 0) 2143 traits_type::copy(__p, __old_p, __n_copy); 2144 size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 2145 if (__sec_cp_sz != 0) 2146 traits_type::copy(__p + __n_copy + __n_add, __old_p + __n_copy + __n_del, __sec_cp_sz); 2147 if (__old_cap+1 != __min_cap) 2148 __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); 2149 __set_long_pointer(__p); 2150 __set_long_cap(__cap+1); 2151} 2152 2153// assign 2154 2155template <class _CharT, class _Traits, class _Allocator> 2156basic_string<_CharT, _Traits, _Allocator>& 2157basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s, size_type __n) 2158{ 2159#ifdef _LIBCPP_DEBUG 2160 assert(__s != 0); 2161#endif 2162 size_type __cap = capacity(); 2163 if (__cap >= __n) 2164 { 2165 pointer __p = __get_pointer(); 2166 traits_type::move(__p, __s, __n); 2167 traits_type::assign(__p[__n], value_type()); 2168 __set_size(__n); 2169 __invalidate_iterators_past(__n); 2170 } 2171 else 2172 { 2173 size_type __sz = size(); 2174 __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); 2175 } 2176 return *this; 2177} 2178 2179template <class _CharT, class _Traits, class _Allocator> 2180basic_string<_CharT, _Traits, _Allocator>& 2181basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) 2182{ 2183 size_type __cap = capacity(); 2184 if (__cap < __n) 2185 { 2186 size_type __sz = size(); 2187 __grow_by(__cap, __n - __cap, __sz, 0, __sz); 2188 } 2189 else 2190 __invalidate_iterators_past(__n); 2191 pointer __p = __get_pointer(); 2192 traits_type::assign(__p, __n, __c); 2193 traits_type::assign(__p[__n], value_type()); 2194 __set_size(__n); 2195 return *this; 2196} 2197 2198template <class _CharT, class _Traits, class _Allocator> 2199basic_string<_CharT, _Traits, _Allocator>& 2200basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) 2201{ 2202 pointer __p; 2203 if (__is_long()) 2204 { 2205 __p = __get_long_pointer(); 2206 __set_long_size(1); 2207 } 2208 else 2209 { 2210 __p = __get_short_pointer(); 2211 __set_short_size(1); 2212 } 2213 traits_type::assign(*__p, __c); 2214 traits_type::assign(*++__p, value_type()); 2215 __invalidate_iterators_past(1); 2216 return *this; 2217} 2218 2219template <class _CharT, class _Traits, class _Allocator> 2220basic_string<_CharT, _Traits, _Allocator>& 2221basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) 2222{ 2223 if (this != &__str) 2224 { 2225 __copy_assign_alloc(__str); 2226 assign(__str); 2227 } 2228 return *this; 2229} 2230 2231#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 2232 2233template <class _CharT, class _Traits, class _Allocator> 2234_LIBCPP_INLINE_VISIBILITY inline 2235void 2236basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) 2237{ 2238 if (__alloc() != __str.__alloc()) 2239 assign(__str); 2240 else 2241 __move_assign(__str, true_type()); 2242} 2243 2244template <class _CharT, class _Traits, class _Allocator> 2245_LIBCPP_INLINE_VISIBILITY inline 2246void 2247basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) 2248 _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 2249{ 2250 clear(); 2251 shrink_to_fit(); 2252 __r_.first() = __str.__r_.first(); 2253 __move_assign_alloc(__str); 2254 __str.__zero(); 2255} 2256 2257template <class _CharT, class _Traits, class _Allocator> 2258_LIBCPP_INLINE_VISIBILITY inline 2259basic_string<_CharT, _Traits, _Allocator>& 2260basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) 2261 _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && 2262 is_nothrow_move_assignable<allocator_type>::value) 2263{ 2264 __move_assign(__str, integral_constant<bool, 2265 __alloc_traits::propagate_on_container_move_assignment::value>()); 2266 return *this; 2267} 2268 2269#endif 2270 2271template <class _CharT, class _Traits, class _Allocator> 2272template<class _InputIterator> 2273typename enable_if 2274< 2275 __is_input_iterator <_InputIterator>::value && 2276 !__is_forward_iterator<_InputIterator>::value, 2277 basic_string<_CharT, _Traits, _Allocator>& 2278>::type 2279basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 2280{ 2281 clear(); 2282 for (; __first != __last; ++__first) 2283 push_back(*__first); 2284 return *this; 2285} 2286 2287template <class _CharT, class _Traits, class _Allocator> 2288template<class _ForwardIterator> 2289typename enable_if 2290< 2291 __is_forward_iterator<_ForwardIterator>::value, 2292 basic_string<_CharT, _Traits, _Allocator>& 2293>::type 2294basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 2295{ 2296 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 2297 size_type __cap = capacity(); 2298 if (__cap < __n) 2299 { 2300 size_type __sz = size(); 2301 __grow_by(__cap, __n - __cap, __sz, 0, __sz); 2302 } 2303 else 2304 __invalidate_iterators_past(__n); 2305 pointer __p = __get_pointer(); 2306 for (; __first != __last; ++__first, ++__p) 2307 traits_type::assign(*__p, *__first); 2308 traits_type::assign(*__p, value_type()); 2309 __set_size(__n); 2310 return *this; 2311} 2312 2313template <class _CharT, class _Traits, class _Allocator> 2314_LIBCPP_INLINE_VISIBILITY inline 2315basic_string<_CharT, _Traits, _Allocator>& 2316basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str) 2317{ 2318 return assign(__str.data(), __str.size()); 2319} 2320 2321template <class _CharT, class _Traits, class _Allocator> 2322basic_string<_CharT, _Traits, _Allocator>& 2323basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) 2324{ 2325 size_type __sz = __str.size(); 2326 if (__pos > __sz) 2327 this->__throw_out_of_range(); 2328 return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); 2329} 2330 2331template <class _CharT, class _Traits, class _Allocator> 2332basic_string<_CharT, _Traits, _Allocator>& 2333basic_string<_CharT, _Traits, _Allocator>::assign(const_pointer __s) 2334{ 2335#ifdef _LIBCPP_DEBUG 2336 assert(__s != 0); 2337#endif 2338 return assign(__s, traits_type::length(__s)); 2339} 2340 2341// append 2342 2343template <class _CharT, class _Traits, class _Allocator> 2344basic_string<_CharT, _Traits, _Allocator>& 2345basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s, size_type __n) 2346{ 2347#ifdef _LIBCPP_DEBUG 2348 assert(__s != 0); 2349#endif 2350 size_type __cap = capacity(); 2351 size_type __sz = size(); 2352 if (__cap - __sz >= __n) 2353 { 2354 if (__n) 2355 { 2356 pointer __p = __get_pointer(); 2357 traits_type::copy(__p + __sz, __s, __n); 2358 __sz += __n; 2359 __set_size(__sz); 2360 traits_type::assign(__p[__sz], value_type()); 2361 } 2362 } 2363 else 2364 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); 2365 return *this; 2366} 2367 2368template <class _CharT, class _Traits, class _Allocator> 2369basic_string<_CharT, _Traits, _Allocator>& 2370basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) 2371{ 2372 if (__n) 2373 { 2374 size_type __cap = capacity(); 2375 size_type __sz = size(); 2376 if (__cap - __sz < __n) 2377 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); 2378 pointer __p = __get_pointer(); 2379 traits_type::assign(__p + __sz, __n, __c); 2380 __sz += __n; 2381 __set_size(__sz); 2382 traits_type::assign(__p[__sz], value_type()); 2383 } 2384 return *this; 2385} 2386 2387template <class _CharT, class _Traits, class _Allocator> 2388void 2389basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) 2390{ 2391 bool __is_short = !__is_long(); 2392 size_type __cap; 2393 size_type __sz; 2394 if (__is_short) 2395 { 2396 __cap = __min_cap - 1; 2397 __sz = __get_short_size(); 2398 } 2399 else 2400 { 2401 __cap = __get_long_cap() - 1; 2402 __sz = __get_long_size(); 2403 } 2404 if (__sz == __cap) 2405 { 2406 __grow_by(__cap, 1, __sz, __sz, 0); 2407 __is_short = !__is_long(); 2408 } 2409 pointer __p; 2410 if (__is_short) 2411 { 2412 __p = __get_short_pointer() + __sz; 2413 __set_short_size(__sz+1); 2414 } 2415 else 2416 { 2417 __p = __get_long_pointer() + __sz; 2418 __set_long_size(__sz+1); 2419 } 2420 traits_type::assign(*__p, __c); 2421 traits_type::assign(*++__p, value_type()); 2422} 2423 2424template <class _CharT, class _Traits, class _Allocator> 2425template<class _InputIterator> 2426typename enable_if 2427< 2428 __is_input_iterator <_InputIterator>::value && 2429 !__is_forward_iterator<_InputIterator>::value, 2430 basic_string<_CharT, _Traits, _Allocator>& 2431>::type 2432basic_string<_CharT, _Traits, _Allocator>::append(_InputIterator __first, _InputIterator __last) 2433{ 2434 for (; __first != __last; ++__first) 2435 push_back(*__first); 2436 return *this; 2437} 2438 2439template <class _CharT, class _Traits, class _Allocator> 2440template<class _ForwardIterator> 2441typename enable_if 2442< 2443 __is_forward_iterator<_ForwardIterator>::value, 2444 basic_string<_CharT, _Traits, _Allocator>& 2445>::type 2446basic_string<_CharT, _Traits, _Allocator>::append(_ForwardIterator __first, _ForwardIterator __last) 2447{ 2448 size_type __sz = size(); 2449 size_type __cap = capacity(); 2450 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 2451 if (__n) 2452 { 2453 if (__cap - __sz < __n) 2454 __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); 2455 pointer __p = __get_pointer() + __sz; 2456 for (; __first != __last; ++__p, ++__first) 2457 traits_type::assign(*__p, *__first); 2458 traits_type::assign(*__p, value_type()); 2459 __set_size(__sz + __n); 2460 } 2461 return *this; 2462} 2463 2464template <class _CharT, class _Traits, class _Allocator> 2465_LIBCPP_INLINE_VISIBILITY inline 2466basic_string<_CharT, _Traits, _Allocator>& 2467basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) 2468{ 2469 return append(__str.data(), __str.size()); 2470} 2471 2472template <class _CharT, class _Traits, class _Allocator> 2473basic_string<_CharT, _Traits, _Allocator>& 2474basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) 2475{ 2476 size_type __sz = __str.size(); 2477 if (__pos > __sz) 2478 this->__throw_out_of_range(); 2479 return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); 2480} 2481 2482template <class _CharT, class _Traits, class _Allocator> 2483basic_string<_CharT, _Traits, _Allocator>& 2484basic_string<_CharT, _Traits, _Allocator>::append(const_pointer __s) 2485{ 2486#ifdef _LIBCPP_DEBUG 2487 assert(__s != 0); 2488#endif 2489 return append(__s, traits_type::length(__s)); 2490} 2491 2492// insert 2493 2494template <class _CharT, class _Traits, class _Allocator> 2495basic_string<_CharT, _Traits, _Allocator>& 2496basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s, size_type __n) 2497{ 2498#ifdef _LIBCPP_DEBUG 2499 assert(__s != 0); 2500#endif 2501 size_type __sz = size(); 2502 if (__pos > __sz) 2503 this->__throw_out_of_range(); 2504 size_type __cap = capacity(); 2505 if (__cap - __sz >= __n) 2506 { 2507 if (__n) 2508 { 2509 pointer __p = __get_pointer(); 2510 size_type __n_move = __sz - __pos; 2511 if (__n_move != 0) 2512 { 2513 if (__p + __pos <= __s && __s < __p + __sz) 2514 __s += __n; 2515 traits_type::move(__p + __pos + __n, __p + __pos, __n_move); 2516 } 2517 traits_type::move(__p + __pos, __s, __n); 2518 __sz += __n; 2519 __set_size(__sz); 2520 traits_type::assign(__p[__sz], value_type()); 2521 } 2522 } 2523 else 2524 __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); 2525 return *this; 2526} 2527 2528template <class _CharT, class _Traits, class _Allocator> 2529basic_string<_CharT, _Traits, _Allocator>& 2530basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) 2531{ 2532 size_type __sz = size(); 2533 if (__pos > __sz) 2534 this->__throw_out_of_range(); 2535 if (__n) 2536 { 2537 size_type __cap = capacity(); 2538 pointer __p; 2539 if (__cap - __sz >= __n) 2540 { 2541 __p = __get_pointer(); 2542 size_type __n_move = __sz - __pos; 2543 if (__n_move != 0) 2544 traits_type::move(__p + __pos + __n, __p + __pos, __n_move); 2545 } 2546 else 2547 { 2548 __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); 2549 __p = __get_long_pointer(); 2550 } 2551 traits_type::assign(__p + __pos, __n, __c); 2552 __sz += __n; 2553 __set_size(__sz); 2554 traits_type::assign(__p[__sz], value_type()); 2555 } 2556 return *this; 2557} 2558 2559template <class _CharT, class _Traits, class _Allocator> 2560template<class _InputIterator> 2561typename enable_if 2562< 2563 __is_input_iterator <_InputIterator>::value && 2564 !__is_forward_iterator<_InputIterator>::value, 2565 typename basic_string<_CharT, _Traits, _Allocator>::iterator 2566>::type 2567basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) 2568{ 2569 size_type __old_sz = size(); 2570 difference_type __ip = __pos - begin(); 2571 for (; __first != __last; ++__first) 2572 push_back(*__first); 2573 pointer __p = __get_pointer(); 2574 _VSTD::rotate(__p + __ip, __p + __old_sz, __p + size()); 2575 return iterator(__p + __ip); 2576} 2577 2578template <class _CharT, class _Traits, class _Allocator> 2579template<class _ForwardIterator> 2580typename enable_if 2581< 2582 __is_forward_iterator<_ForwardIterator>::value, 2583 typename basic_string<_CharT, _Traits, _Allocator>::iterator 2584>::type 2585basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) 2586{ 2587 size_type __ip = static_cast<size_type>(__pos - begin()); 2588 size_type __sz = size(); 2589 size_type __cap = capacity(); 2590 size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); 2591 if (__n) 2592 { 2593 pointer __p; 2594 if (__cap - __sz >= __n) 2595 { 2596 __p = __get_pointer(); 2597 size_type __n_move = __sz - __ip; 2598 if (__n_move != 0) 2599 traits_type::move(__p + __ip + __n, __p + __ip, __n_move); 2600 } 2601 else 2602 { 2603 __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); 2604 __p = __get_long_pointer(); 2605 } 2606 __sz += __n; 2607 __set_size(__sz); 2608 traits_type::assign(__p[__sz], value_type()); 2609 for (__p += __ip; __first != __last; ++__p, ++__first) 2610 traits_type::assign(*__p, *__first); 2611 } 2612 return begin() + __ip; 2613} 2614 2615template <class _CharT, class _Traits, class _Allocator> 2616_LIBCPP_INLINE_VISIBILITY inline 2617basic_string<_CharT, _Traits, _Allocator>& 2618basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) 2619{ 2620 return insert(__pos1, __str.data(), __str.size()); 2621} 2622 2623template <class _CharT, class _Traits, class _Allocator> 2624basic_string<_CharT, _Traits, _Allocator>& 2625basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, 2626 size_type __pos2, size_type __n) 2627{ 2628 size_type __str_sz = __str.size(); 2629 if (__pos2 > __str_sz) 2630 this->__throw_out_of_range(); 2631 return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); 2632} 2633 2634template <class _CharT, class _Traits, class _Allocator> 2635basic_string<_CharT, _Traits, _Allocator>& 2636basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const_pointer __s) 2637{ 2638#ifdef _LIBCPP_DEBUG 2639 assert(__s != 0); 2640#endif 2641 return insert(__pos, __s, traits_type::length(__s)); 2642} 2643 2644template <class _CharT, class _Traits, class _Allocator> 2645typename basic_string<_CharT, _Traits, _Allocator>::iterator 2646basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) 2647{ 2648 size_type __ip = static_cast<size_type>(__pos - begin()); 2649 size_type __sz = size(); 2650 size_type __cap = capacity(); 2651 pointer __p; 2652 if (__cap == __sz) 2653 { 2654 __grow_by(__cap, 1, __sz, __ip, 0, 1); 2655 __p = __get_long_pointer(); 2656 } 2657 else 2658 { 2659 __p = __get_pointer(); 2660 size_type __n_move = __sz - __ip; 2661 if (__n_move != 0) 2662 traits_type::move(__p + __ip + 1, __p + __ip, __n_move); 2663 } 2664 traits_type::assign(__p[__ip], __c); 2665 traits_type::assign(__p[++__sz], value_type()); 2666 __set_size(__sz); 2667 return begin() + static_cast<difference_type>(__ip); 2668} 2669 2670template <class _CharT, class _Traits, class _Allocator> 2671_LIBCPP_INLINE_VISIBILITY inline 2672typename basic_string<_CharT, _Traits, _Allocator>::iterator 2673basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) 2674{ 2675 difference_type __p = __pos - begin(); 2676 insert(static_cast<size_type>(__p), __n, __c); 2677 return begin() + __p; 2678} 2679 2680// replace 2681 2682template <class _CharT, class _Traits, class _Allocator> 2683basic_string<_CharT, _Traits, _Allocator>& 2684basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s, size_type __n2) 2685{ 2686#ifdef _LIBCPP_DEBUG 2687 assert(__s != 0); 2688#endif 2689 size_type __sz = size(); 2690 if (__pos > __sz) 2691 this->__throw_out_of_range(); 2692 __n1 = _VSTD::min(__n1, __sz - __pos); 2693 size_type __cap = capacity(); 2694 if (__cap - __sz + __n1 >= __n2) 2695 { 2696 pointer __p = __get_pointer(); 2697 if (__n1 != __n2) 2698 { 2699 size_type __n_move = __sz - __pos - __n1; 2700 if (__n_move != 0) 2701 { 2702 if (__n1 > __n2) 2703 { 2704 traits_type::move(__p + __pos, __s, __n2); 2705 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 2706 goto __finish; 2707 } 2708 if (__p + __pos < __s && __s < __p + __sz) 2709 { 2710 if (__p + __pos + __n1 <= __s) 2711 __s += __n2 - __n1; 2712 else // __p + __pos < __s < __p + __pos + __n1 2713 { 2714 traits_type::move(__p + __pos, __s, __n1); 2715 __pos += __n1; 2716 __s += __n2; 2717 __n2 -= __n1; 2718 __n1 = 0; 2719 } 2720 } 2721 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 2722 } 2723 } 2724 traits_type::move(__p + __pos, __s, __n2); 2725__finish: 2726 __sz += __n2 - __n1; 2727 __set_size(__sz); 2728 __invalidate_iterators_past(__sz); 2729 traits_type::assign(__p[__sz], value_type()); 2730 } 2731 else 2732 __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); 2733 return *this; 2734} 2735 2736template <class _CharT, class _Traits, class _Allocator> 2737basic_string<_CharT, _Traits, _Allocator>& 2738basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) 2739{ 2740 size_type __sz = size(); 2741 if (__pos > __sz) 2742 this->__throw_out_of_range(); 2743 __n1 = _VSTD::min(__n1, __sz - __pos); 2744 size_type __cap = capacity(); 2745 pointer __p; 2746 if (__cap - __sz + __n1 >= __n2) 2747 { 2748 __p = __get_pointer(); 2749 if (__n1 != __n2) 2750 { 2751 size_type __n_move = __sz - __pos - __n1; 2752 if (__n_move != 0) 2753 traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 2754 } 2755 } 2756 else 2757 { 2758 __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); 2759 __p = __get_long_pointer(); 2760 } 2761 traits_type::assign(__p + __pos, __n2, __c); 2762 __sz += __n2 - __n1; 2763 __set_size(__sz); 2764 __invalidate_iterators_past(__sz); 2765 traits_type::assign(__p[__sz], value_type()); 2766 return *this; 2767} 2768 2769template <class _CharT, class _Traits, class _Allocator> 2770template<class _InputIterator> 2771typename enable_if 2772< 2773 __is_input_iterator<_InputIterator>::value, 2774 basic_string<_CharT, _Traits, _Allocator>& 2775>::type 2776basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, 2777 _InputIterator __j1, _InputIterator __j2) 2778{ 2779 for (; true; ++__i1, ++__j1) 2780 { 2781 if (__i1 == __i2) 2782 { 2783 if (__j1 != __j2) 2784 insert(__i1, __j1, __j2); 2785 break; 2786 } 2787 if (__j1 == __j2) 2788 { 2789 erase(__i1, __i2); 2790 break; 2791 } 2792 traits_type::assign(const_cast<value_type&>(*__i1), *__j1); 2793 } 2794 return *this; 2795} 2796 2797template <class _CharT, class _Traits, class _Allocator> 2798_LIBCPP_INLINE_VISIBILITY inline 2799basic_string<_CharT, _Traits, _Allocator>& 2800basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) 2801{ 2802 return replace(__pos1, __n1, __str.data(), __str.size()); 2803} 2804 2805template <class _CharT, class _Traits, class _Allocator> 2806basic_string<_CharT, _Traits, _Allocator>& 2807basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, 2808 size_type __pos2, size_type __n2) 2809{ 2810 size_type __str_sz = __str.size(); 2811 if (__pos2 > __str_sz) 2812 this->__throw_out_of_range(); 2813 return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); 2814} 2815 2816template <class _CharT, class _Traits, class _Allocator> 2817basic_string<_CharT, _Traits, _Allocator>& 2818basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const_pointer __s) 2819{ 2820#ifdef _LIBCPP_DEBUG 2821 assert(__s != 0); 2822#endif 2823 return replace(__pos, __n1, __s, traits_type::length(__s)); 2824} 2825 2826template <class _CharT, class _Traits, class _Allocator> 2827_LIBCPP_INLINE_VISIBILITY inline 2828basic_string<_CharT, _Traits, _Allocator>& 2829basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) 2830{ 2831 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), 2832 __str.data(), __str.size()); 2833} 2834 2835template <class _CharT, class _Traits, class _Allocator> 2836_LIBCPP_INLINE_VISIBILITY inline 2837basic_string<_CharT, _Traits, _Allocator>& 2838basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s, size_type __n) 2839{ 2840 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); 2841} 2842 2843template <class _CharT, class _Traits, class _Allocator> 2844_LIBCPP_INLINE_VISIBILITY inline 2845basic_string<_CharT, _Traits, _Allocator>& 2846basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const_pointer __s) 2847{ 2848 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); 2849} 2850 2851template <class _CharT, class _Traits, class _Allocator> 2852_LIBCPP_INLINE_VISIBILITY inline 2853basic_string<_CharT, _Traits, _Allocator>& 2854basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) 2855{ 2856 return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); 2857} 2858 2859// erase 2860 2861template <class _CharT, class _Traits, class _Allocator> 2862basic_string<_CharT, _Traits, _Allocator>& 2863basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n) 2864{ 2865 size_type __sz = size(); 2866 if (__pos > __sz) 2867 this->__throw_out_of_range(); 2868 if (__n) 2869 { 2870 pointer __p = __get_pointer(); 2871 __n = _VSTD::min(__n, __sz - __pos); 2872 size_type __n_move = __sz - __pos - __n; 2873 if (__n_move != 0) 2874 traits_type::move(__p + __pos, __p + __pos + __n, __n_move); 2875 __sz -= __n; 2876 __set_size(__sz); 2877 __invalidate_iterators_past(__sz); 2878 traits_type::assign(__p[__sz], value_type()); 2879 } 2880 return *this; 2881} 2882 2883template <class _CharT, class _Traits, class _Allocator> 2884_LIBCPP_INLINE_VISIBILITY inline 2885typename basic_string<_CharT, _Traits, _Allocator>::iterator 2886basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) 2887{ 2888 iterator __b = begin(); 2889 size_type __r = static_cast<size_type>(__pos - __b); 2890 erase(__r, 1); 2891 return __b + static_cast<difference_type>(__r); 2892} 2893 2894template <class _CharT, class _Traits, class _Allocator> 2895_LIBCPP_INLINE_VISIBILITY inline 2896typename basic_string<_CharT, _Traits, _Allocator>::iterator 2897basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) 2898{ 2899 iterator __b = begin(); 2900 size_type __r = static_cast<size_type>(__first - __b); 2901 erase(__r, static_cast<size_type>(__last - __first)); 2902 return __b + static_cast<difference_type>(__r); 2903} 2904 2905template <class _CharT, class _Traits, class _Allocator> 2906_LIBCPP_INLINE_VISIBILITY inline 2907void 2908basic_string<_CharT, _Traits, _Allocator>::pop_back() 2909{ 2910#ifdef _LIBCPP_DEBUG 2911 assert(!empty()); 2912#endif 2913 size_type __sz; 2914 if (__is_long()) 2915 { 2916 __sz = __get_long_size() - 1; 2917 __set_long_size(__sz); 2918 traits_type::assign(*(__get_long_pointer() + __sz), value_type()); 2919 } 2920 else 2921 { 2922 __sz = __get_short_size() - 1; 2923 __set_short_size(__sz); 2924 traits_type::assign(*(__get_short_pointer() + __sz), value_type()); 2925 } 2926 __invalidate_iterators_past(__sz); 2927} 2928 2929template <class _CharT, class _Traits, class _Allocator> 2930_LIBCPP_INLINE_VISIBILITY inline 2931void 2932basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT 2933{ 2934 __invalidate_all_iterators(); 2935 if (__is_long()) 2936 { 2937 traits_type::assign(*__get_long_pointer(), value_type()); 2938 __set_long_size(0); 2939 } 2940 else 2941 { 2942 traits_type::assign(*__get_short_pointer(), value_type()); 2943 __set_short_size(0); 2944 } 2945} 2946 2947template <class _CharT, class _Traits, class _Allocator> 2948_LIBCPP_INLINE_VISIBILITY inline 2949void 2950basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) 2951{ 2952 if (__is_long()) 2953 { 2954 traits_type::assign(*(__get_long_pointer() + __pos), value_type()); 2955 __set_long_size(__pos); 2956 } 2957 else 2958 { 2959 traits_type::assign(*(__get_short_pointer() + __pos), value_type()); 2960 __set_short_size(__pos); 2961 } 2962 __invalidate_iterators_past(__pos); 2963} 2964 2965template <class _CharT, class _Traits, class _Allocator> 2966void 2967basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) 2968{ 2969 size_type __sz = size(); 2970 if (__n > __sz) 2971 append(__n - __sz, __c); 2972 else 2973 __erase_to_end(__n); 2974} 2975 2976template <class _CharT, class _Traits, class _Allocator> 2977_LIBCPP_INLINE_VISIBILITY inline 2978typename basic_string<_CharT, _Traits, _Allocator>::size_type 2979basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT 2980{ 2981 size_type __m = __alloc_traits::max_size(__alloc()); 2982#if _LIBCPP_BIG_ENDIAN 2983 return (__m <= ~__long_mask ? __m : __m/2) - 1; 2984#else 2985 return __m - 1; 2986#endif 2987} 2988 2989template <class _CharT, class _Traits, class _Allocator> 2990void 2991basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg) 2992{ 2993 if (__res_arg > max_size()) 2994 this->__throw_length_error(); 2995 size_type __cap = capacity(); 2996 size_type __sz = size(); 2997 __res_arg = _VSTD::max(__res_arg, __sz); 2998 __res_arg = __recommend(__res_arg); 2999 if (__res_arg != __cap) 3000 { 3001 pointer __new_data, __p; 3002 bool __was_long, __now_long; 3003 if (__res_arg == __min_cap - 1) 3004 { 3005 __was_long = true; 3006 __now_long = false; 3007 __new_data = __get_short_pointer(); 3008 __p = __get_long_pointer(); 3009 } 3010 else 3011 { 3012 if (__res_arg > __cap) 3013 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); 3014 else 3015 { 3016 #ifndef _LIBCPP_NO_EXCEPTIONS 3017 try 3018 { 3019 #endif // _LIBCPP_NO_EXCEPTIONS 3020 __new_data = __alloc_traits::allocate(__alloc(), __res_arg+1); 3021 #ifndef _LIBCPP_NO_EXCEPTIONS 3022 } 3023 catch (...) 3024 { 3025 return; 3026 } 3027 #else // _LIBCPP_NO_EXCEPTIONS 3028 if (__new_data == 0) 3029 return; 3030 #endif // _LIBCPP_NO_EXCEPTIONS 3031 } 3032 __now_long = true; 3033 __was_long = __is_long(); 3034 __p = __get_pointer(); 3035 } 3036 traits_type::copy(__new_data, __p, size()+1); 3037 if (__was_long) 3038 __alloc_traits::deallocate(__alloc(), __p, __cap+1); 3039 if (__now_long) 3040 { 3041 __set_long_cap(__res_arg+1); 3042 __set_long_size(__sz); 3043 __set_long_pointer(__new_data); 3044 } 3045 else 3046 __set_short_size(__sz); 3047 __invalidate_all_iterators(); 3048 } 3049} 3050 3051template <class _CharT, class _Traits, class _Allocator> 3052_LIBCPP_INLINE_VISIBILITY inline 3053typename basic_string<_CharT, _Traits, _Allocator>::const_reference 3054basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const 3055{ 3056#ifdef __LIBCPP_DEBUG 3057 assert(__pos <= size()); 3058#endif 3059 return *(data() + __pos); 3060} 3061 3062template <class _CharT, class _Traits, class _Allocator> 3063_LIBCPP_INLINE_VISIBILITY inline 3064typename basic_string<_CharT, _Traits, _Allocator>::reference 3065basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) 3066{ 3067#ifdef __LIBCPP_DEBUG 3068 assert(__pos < size()); 3069#endif 3070 return *(__get_pointer() + __pos); 3071} 3072 3073template <class _CharT, class _Traits, class _Allocator> 3074typename basic_string<_CharT, _Traits, _Allocator>::const_reference 3075basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const 3076{ 3077 if (__n >= size()) 3078 this->__throw_out_of_range(); 3079 return (*this)[__n]; 3080} 3081 3082template <class _CharT, class _Traits, class _Allocator> 3083typename basic_string<_CharT, _Traits, _Allocator>::reference 3084basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) 3085{ 3086 if (__n >= size()) 3087 this->__throw_out_of_range(); 3088 return (*this)[__n]; 3089} 3090 3091template <class _CharT, class _Traits, class _Allocator> 3092_LIBCPP_INLINE_VISIBILITY inline 3093typename basic_string<_CharT, _Traits, _Allocator>::reference 3094basic_string<_CharT, _Traits, _Allocator>::front() 3095{ 3096#ifdef _LIBCPP_DEBUG 3097 assert(!empty()); 3098#endif 3099 return *__get_pointer(); 3100} 3101 3102template <class _CharT, class _Traits, class _Allocator> 3103_LIBCPP_INLINE_VISIBILITY inline 3104typename basic_string<_CharT, _Traits, _Allocator>::const_reference 3105basic_string<_CharT, _Traits, _Allocator>::front() const 3106{ 3107#ifdef _LIBCPP_DEBUG 3108 assert(!empty()); 3109#endif 3110 return *data(); 3111} 3112 3113template <class _CharT, class _Traits, class _Allocator> 3114_LIBCPP_INLINE_VISIBILITY inline 3115typename basic_string<_CharT, _Traits, _Allocator>::reference 3116basic_string<_CharT, _Traits, _Allocator>::back() 3117{ 3118#ifdef _LIBCPP_DEBUG 3119 assert(!empty()); 3120#endif 3121 return *(__get_pointer() + size() - 1); 3122} 3123 3124template <class _CharT, class _Traits, class _Allocator> 3125_LIBCPP_INLINE_VISIBILITY inline 3126typename basic_string<_CharT, _Traits, _Allocator>::const_reference 3127basic_string<_CharT, _Traits, _Allocator>::back() const 3128{ 3129#ifdef _LIBCPP_DEBUG 3130 assert(!empty()); 3131#endif 3132 return *(data() + size() - 1); 3133} 3134 3135template <class _CharT, class _Traits, class _Allocator> 3136typename basic_string<_CharT, _Traits, _Allocator>::size_type 3137basic_string<_CharT, _Traits, _Allocator>::copy(pointer __s, size_type __n, size_type __pos) const 3138{ 3139 size_type __sz = size(); 3140 if (__pos > __sz) 3141 this->__throw_out_of_range(); 3142 size_type __rlen = _VSTD::min(__n, __sz - __pos); 3143 traits_type::copy(__s, data() + __pos, __rlen); 3144 return __rlen; 3145} 3146 3147template <class _CharT, class _Traits, class _Allocator> 3148_LIBCPP_INLINE_VISIBILITY inline 3149basic_string<_CharT, _Traits, _Allocator> 3150basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const 3151{ 3152 return basic_string(*this, __pos, __n, __alloc()); 3153} 3154 3155template <class _CharT, class _Traits, class _Allocator> 3156_LIBCPP_INLINE_VISIBILITY inline 3157void 3158basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) 3159 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 3160 __is_nothrow_swappable<allocator_type>::value) 3161{ 3162 _VSTD::swap(__r_.first(), __str.__r_.first()); 3163 __swap_alloc(__alloc(), __str.__alloc()); 3164#ifdef _LIBCPP_DEBUG 3165 __invalidate_all_iterators(); 3166 __str.__invalidate_all_iterators(); 3167#endif // _LIBCPP_DEBUG 3168} 3169 3170// find 3171 3172template <class _Traits> 3173struct _LIBCPP_HIDDEN __traits_eq 3174{ 3175 typedef typename _Traits::char_type char_type; 3176 _LIBCPP_INLINE_VISIBILITY 3177 bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT 3178 {return _Traits::eq(__x, __y);} 3179}; 3180 3181template<class _CharT, class _Traits, class _Allocator> 3182typename basic_string<_CharT, _Traits, _Allocator>::size_type 3183basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s, 3184 size_type __pos, 3185 size_type __n) const _NOEXCEPT 3186{ 3187#ifdef _LIBCPP_DEBUG 3188 assert(__s != 0); 3189#endif 3190 size_type __sz = size(); 3191 if (__pos > __sz || __sz - __pos < __n) 3192 return npos; 3193 if (__n == 0) 3194 return __pos; 3195 const_pointer __p = data(); 3196 const_pointer __r = _VSTD::search(__p + __pos, __p + __sz, __s, __s + __n, 3197 __traits_eq<traits_type>()); 3198 if (__r == __p + __sz) 3199 return npos; 3200 return static_cast<size_type>(__r - __p); 3201} 3202 3203template<class _CharT, class _Traits, class _Allocator> 3204_LIBCPP_INLINE_VISIBILITY inline 3205typename basic_string<_CharT, _Traits, _Allocator>::size_type 3206basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, 3207 size_type __pos) const _NOEXCEPT 3208{ 3209 return find(__str.data(), __pos, __str.size()); 3210} 3211 3212template<class _CharT, class _Traits, class _Allocator> 3213_LIBCPP_INLINE_VISIBILITY inline 3214typename basic_string<_CharT, _Traits, _Allocator>::size_type 3215basic_string<_CharT, _Traits, _Allocator>::find(const_pointer __s, 3216 size_type __pos) const _NOEXCEPT 3217{ 3218#ifdef _LIBCPP_DEBUG 3219 assert(__s != 0); 3220#endif 3221 return find(__s, __pos, traits_type::length(__s)); 3222} 3223 3224template<class _CharT, class _Traits, class _Allocator> 3225typename basic_string<_CharT, _Traits, _Allocator>::size_type 3226basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, 3227 size_type __pos) const _NOEXCEPT 3228{ 3229 size_type __sz = size(); 3230 if (__pos >= __sz) 3231 return npos; 3232 const_pointer __p = data(); 3233 const_pointer __r = traits_type::find(__p + __pos, __sz - __pos, __c); 3234 if (__r == 0) 3235 return npos; 3236 return static_cast<size_type>(__r - __p); 3237} 3238 3239// rfind 3240 3241template<class _CharT, class _Traits, class _Allocator> 3242typename basic_string<_CharT, _Traits, _Allocator>::size_type 3243basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s, 3244 size_type __pos, 3245 size_type __n) const _NOEXCEPT 3246{ 3247#ifdef _LIBCPP_DEBUG 3248 assert(__s != 0); 3249#endif 3250 size_type __sz = size(); 3251 __pos = _VSTD::min(__pos, __sz); 3252 if (__n < __sz - __pos) 3253 __pos += __n; 3254 else 3255 __pos = __sz; 3256 const_pointer __p = data(); 3257 const_pointer __r = _VSTD::find_end(__p, __p + __pos, __s, __s + __n, 3258 __traits_eq<traits_type>()); 3259 if (__n > 0 && __r == __p + __pos) 3260 return npos; 3261 return static_cast<size_type>(__r - __p); 3262} 3263 3264template<class _CharT, class _Traits, class _Allocator> 3265_LIBCPP_INLINE_VISIBILITY inline 3266typename basic_string<_CharT, _Traits, _Allocator>::size_type 3267basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, 3268 size_type __pos) const _NOEXCEPT 3269{ 3270 return rfind(__str.data(), __pos, __str.size()); 3271} 3272 3273template<class _CharT, class _Traits, class _Allocator> 3274_LIBCPP_INLINE_VISIBILITY inline 3275typename basic_string<_CharT, _Traits, _Allocator>::size_type 3276basic_string<_CharT, _Traits, _Allocator>::rfind(const_pointer __s, 3277 size_type __pos) const _NOEXCEPT 3278{ 3279#ifdef _LIBCPP_DEBUG 3280 assert(__s != 0); 3281#endif 3282 return rfind(__s, __pos, traits_type::length(__s)); 3283} 3284 3285template<class _CharT, class _Traits, class _Allocator> 3286typename basic_string<_CharT, _Traits, _Allocator>::size_type 3287basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, 3288 size_type __pos) const _NOEXCEPT 3289{ 3290 size_type __sz = size(); 3291 if (__sz) 3292 { 3293 if (__pos < __sz) 3294 ++__pos; 3295 else 3296 __pos = __sz; 3297 const_pointer __p = data(); 3298 for (const_pointer __ps = __p + __pos; __ps != __p;) 3299 { 3300 if (traits_type::eq(*--__ps, __c)) 3301 return static_cast<size_type>(__ps - __p); 3302 } 3303 } 3304 return npos; 3305} 3306 3307// find_first_of 3308 3309template<class _CharT, class _Traits, class _Allocator> 3310typename basic_string<_CharT, _Traits, _Allocator>::size_type 3311basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s, 3312 size_type __pos, 3313 size_type __n) const _NOEXCEPT 3314{ 3315#ifdef _LIBCPP_DEBUG 3316 assert(__s != 0); 3317#endif 3318 size_type __sz = size(); 3319 if (__pos >= __sz || __n == 0) 3320 return npos; 3321 const_pointer __p = data(); 3322 const_pointer __r = _VSTD::find_first_of(__p + __pos, __p + __sz, __s, 3323 __s + __n, __traits_eq<traits_type>()); 3324 if (__r == __p + __sz) 3325 return npos; 3326 return static_cast<size_type>(__r - __p); 3327} 3328 3329template<class _CharT, class _Traits, class _Allocator> 3330_LIBCPP_INLINE_VISIBILITY inline 3331typename basic_string<_CharT, _Traits, _Allocator>::size_type 3332basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, 3333 size_type __pos) const _NOEXCEPT 3334{ 3335 return find_first_of(__str.data(), __pos, __str.size()); 3336} 3337 3338template<class _CharT, class _Traits, class _Allocator> 3339_LIBCPP_INLINE_VISIBILITY inline 3340typename basic_string<_CharT, _Traits, _Allocator>::size_type 3341basic_string<_CharT, _Traits, _Allocator>::find_first_of(const_pointer __s, 3342 size_type __pos) const _NOEXCEPT 3343{ 3344#ifdef _LIBCPP_DEBUG 3345 assert(__s != 0); 3346#endif 3347 return find_first_of(__s, __pos, traits_type::length(__s)); 3348} 3349 3350template<class _CharT, class _Traits, class _Allocator> 3351_LIBCPP_INLINE_VISIBILITY inline 3352typename basic_string<_CharT, _Traits, _Allocator>::size_type 3353basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, 3354 size_type __pos) const _NOEXCEPT 3355{ 3356 return find(__c, __pos); 3357} 3358 3359// find_last_of 3360 3361template<class _CharT, class _Traits, class _Allocator> 3362typename basic_string<_CharT, _Traits, _Allocator>::size_type 3363basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s, 3364 size_type __pos, 3365 size_type __n) const _NOEXCEPT 3366{ 3367#ifdef _LIBCPP_DEBUG 3368 assert(__s != 0); 3369#endif 3370 if (__n != 0) 3371 { 3372 size_type __sz = size(); 3373 if (__pos < __sz) 3374 ++__pos; 3375 else 3376 __pos = __sz; 3377 const_pointer __p = data(); 3378 for (const_pointer __ps = __p + __pos; __ps != __p;) 3379 { 3380 const_pointer __r = traits_type::find(__s, __n, *--__ps); 3381 if (__r) 3382 return static_cast<size_type>(__ps - __p); 3383 } 3384 } 3385 return npos; 3386} 3387 3388template<class _CharT, class _Traits, class _Allocator> 3389_LIBCPP_INLINE_VISIBILITY inline 3390typename basic_string<_CharT, _Traits, _Allocator>::size_type 3391basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, 3392 size_type __pos) const _NOEXCEPT 3393{ 3394 return find_last_of(__str.data(), __pos, __str.size()); 3395} 3396 3397template<class _CharT, class _Traits, class _Allocator> 3398_LIBCPP_INLINE_VISIBILITY inline 3399typename basic_string<_CharT, _Traits, _Allocator>::size_type 3400basic_string<_CharT, _Traits, _Allocator>::find_last_of(const_pointer __s, 3401 size_type __pos) const _NOEXCEPT 3402{ 3403#ifdef _LIBCPP_DEBUG 3404 assert(__s != 0); 3405#endif 3406 return find_last_of(__s, __pos, traits_type::length(__s)); 3407} 3408 3409template<class _CharT, class _Traits, class _Allocator> 3410_LIBCPP_INLINE_VISIBILITY inline 3411typename basic_string<_CharT, _Traits, _Allocator>::size_type 3412basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, 3413 size_type __pos) const _NOEXCEPT 3414{ 3415 return rfind(__c, __pos); 3416} 3417 3418// find_first_not_of 3419 3420template<class _CharT, class _Traits, class _Allocator> 3421typename basic_string<_CharT, _Traits, _Allocator>::size_type 3422basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s, 3423 size_type __pos, 3424 size_type __n) const _NOEXCEPT 3425{ 3426#ifdef _LIBCPP_DEBUG 3427 assert(__s != 0); 3428#endif 3429 size_type __sz = size(); 3430 if (__pos < __sz) 3431 { 3432 const_pointer __p = data(); 3433 const_pointer __pe = __p + __sz; 3434 for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps) 3435 if (traits_type::find(__s, __n, *__ps) == 0) 3436 return static_cast<size_type>(__ps - __p); 3437 } 3438 return npos; 3439} 3440 3441template<class _CharT, class _Traits, class _Allocator> 3442_LIBCPP_INLINE_VISIBILITY inline 3443typename basic_string<_CharT, _Traits, _Allocator>::size_type 3444basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, 3445 size_type __pos) const _NOEXCEPT 3446{ 3447 return find_first_not_of(__str.data(), __pos, __str.size()); 3448} 3449 3450template<class _CharT, class _Traits, class _Allocator> 3451_LIBCPP_INLINE_VISIBILITY inline 3452typename basic_string<_CharT, _Traits, _Allocator>::size_type 3453basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const_pointer __s, 3454 size_type __pos) const _NOEXCEPT 3455{ 3456#ifdef _LIBCPP_DEBUG 3457 assert(__s != 0); 3458#endif 3459 return find_first_not_of(__s, __pos, traits_type::length(__s)); 3460} 3461 3462template<class _CharT, class _Traits, class _Allocator> 3463_LIBCPP_INLINE_VISIBILITY inline 3464typename basic_string<_CharT, _Traits, _Allocator>::size_type 3465basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, 3466 size_type __pos) const _NOEXCEPT 3467{ 3468 size_type __sz = size(); 3469 if (__pos < __sz) 3470 { 3471 const_pointer __p = data(); 3472 const_pointer __pe = __p + __sz; 3473 for (const_pointer __ps = __p + __pos; __ps != __pe; ++__ps) 3474 if (!traits_type::eq(*__ps, __c)) 3475 return static_cast<size_type>(__ps - __p); 3476 } 3477 return npos; 3478} 3479 3480// find_last_not_of 3481 3482template<class _CharT, class _Traits, class _Allocator> 3483typename basic_string<_CharT, _Traits, _Allocator>::size_type 3484basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s, 3485 size_type __pos, 3486 size_type __n) const _NOEXCEPT 3487{ 3488#ifdef _LIBCPP_DEBUG 3489 assert(__s != 0); 3490#endif 3491 size_type __sz = size(); 3492 if (__pos < __sz) 3493 ++__pos; 3494 else 3495 __pos = __sz; 3496 const_pointer __p = data(); 3497 for (const_pointer __ps = __p + __pos; __ps != __p;) 3498 if (traits_type::find(__s, __n, *--__ps) == 0) 3499 return static_cast<size_type>(__ps - __p); 3500 return npos; 3501} 3502 3503template<class _CharT, class _Traits, class _Allocator> 3504_LIBCPP_INLINE_VISIBILITY inline 3505typename basic_string<_CharT, _Traits, _Allocator>::size_type 3506basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, 3507 size_type __pos) const _NOEXCEPT 3508{ 3509 return find_last_not_of(__str.data(), __pos, __str.size()); 3510} 3511 3512template<class _CharT, class _Traits, class _Allocator> 3513_LIBCPP_INLINE_VISIBILITY inline 3514typename basic_string<_CharT, _Traits, _Allocator>::size_type 3515basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const_pointer __s, 3516 size_type __pos) const _NOEXCEPT 3517{ 3518#ifdef _LIBCPP_DEBUG 3519 assert(__s != 0); 3520#endif 3521 return find_last_not_of(__s, __pos, traits_type::length(__s)); 3522} 3523 3524template<class _CharT, class _Traits, class _Allocator> 3525_LIBCPP_INLINE_VISIBILITY inline 3526typename basic_string<_CharT, _Traits, _Allocator>::size_type 3527basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, 3528 size_type __pos) const _NOEXCEPT 3529{ 3530 size_type __sz = size(); 3531 if (__pos < __sz) 3532 ++__pos; 3533 else 3534 __pos = __sz; 3535 const_pointer __p = data(); 3536 for (const_pointer __ps = __p + __pos; __ps != __p;) 3537 if (!traits_type::eq(*--__ps, __c)) 3538 return static_cast<size_type>(__ps - __p); 3539 return npos; 3540} 3541 3542// compare 3543 3544template <class _CharT, class _Traits, class _Allocator> 3545_LIBCPP_INLINE_VISIBILITY inline 3546int 3547basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT 3548{ 3549 size_t __lhs_sz = size(); 3550 size_t __rhs_sz = __str.size(); 3551 int __result = traits_type::compare(data(), __str.data(), 3552 _VSTD::min(__lhs_sz, __rhs_sz)); 3553 if (__result != 0) 3554 return __result; 3555 if (__lhs_sz < __rhs_sz) 3556 return -1; 3557 if (__lhs_sz > __rhs_sz) 3558 return 1; 3559 return 0; 3560} 3561 3562template <class _CharT, class _Traits, class _Allocator> 3563_LIBCPP_INLINE_VISIBILITY inline 3564int 3565basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 3566 size_type __n1, 3567 const basic_string& __str) const 3568{ 3569 return compare(__pos1, __n1, __str.data(), __str.size()); 3570} 3571 3572template <class _CharT, class _Traits, class _Allocator> 3573int 3574basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 3575 size_type __n1, 3576 const basic_string& __str, 3577 size_type __pos2, 3578 size_type __n2) const 3579{ 3580 size_type __sz = __str.size(); 3581 if (__pos2 > __sz) 3582 this->__throw_out_of_range(); 3583 return compare(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, 3584 __sz - __pos2)); 3585} 3586 3587template <class _CharT, class _Traits, class _Allocator> 3588int 3589basic_string<_CharT, _Traits, _Allocator>::compare(const_pointer __s) const _NOEXCEPT 3590{ 3591#ifdef _LIBCPP_DEBUG 3592 assert(__s != 0); 3593#endif 3594 return compare(0, npos, __s, traits_type::length(__s)); 3595} 3596 3597template <class _CharT, class _Traits, class _Allocator> 3598int 3599basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 3600 size_type __n1, 3601 const_pointer __s) const 3602{ 3603#ifdef _LIBCPP_DEBUG 3604 assert(__s != 0); 3605#endif 3606 return compare(__pos1, __n1, __s, traits_type::length(__s)); 3607} 3608 3609template <class _CharT, class _Traits, class _Allocator> 3610int 3611basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 3612 size_type __n1, 3613 const_pointer __s, 3614 size_type __n2) const 3615{ 3616#ifdef _LIBCPP_DEBUG 3617 assert(__s != 0); 3618#endif 3619 size_type __sz = size(); 3620 if (__pos1 > __sz || __n2 == npos) 3621 this->__throw_out_of_range(); 3622 size_type __rlen = _VSTD::min(__n1, __sz - __pos1); 3623 int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2)); 3624 if (__r == 0) 3625 { 3626 if (__rlen < __n2) 3627 __r = -1; 3628 else if (__rlen > __n2) 3629 __r = 1; 3630 } 3631 return __r; 3632} 3633 3634// __invariants 3635 3636template<class _CharT, class _Traits, class _Allocator> 3637_LIBCPP_INLINE_VISIBILITY inline 3638bool 3639basic_string<_CharT, _Traits, _Allocator>::__invariants() const 3640{ 3641 if (size() > capacity()) 3642 return false; 3643 if (capacity() < __min_cap - 1) 3644 return false; 3645 if (data() == 0) 3646 return false; 3647 if (data()[size()] != value_type(0)) 3648 return false; 3649 return true; 3650} 3651 3652// operator== 3653 3654template<class _CharT, class _Traits, class _Allocator> 3655_LIBCPP_INLINE_VISIBILITY inline 3656bool 3657operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3658 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3659{ 3660 size_t __lhs_sz = __lhs.size(); 3661 return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), 3662 __rhs.data(), 3663 __lhs_sz) == 0; 3664} 3665 3666template<class _Allocator> 3667_LIBCPP_INLINE_VISIBILITY inline 3668bool 3669operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, 3670 const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT 3671{ 3672 size_t __lhs_sz = __lhs.size(); 3673 if (__lhs_sz != __rhs.size()) 3674 return false; 3675 const char* __lp = __lhs.data(); 3676 const char* __rp = __rhs.data(); 3677 if (__lhs.__is_long()) 3678 return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; 3679 for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) 3680 if (*__lp != *__rp) 3681 return false; 3682 return true; 3683} 3684 3685template<class _CharT, class _Traits, class _Allocator> 3686_LIBCPP_INLINE_VISIBILITY inline 3687bool 3688operator==(const _CharT* __lhs, 3689 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3690{ 3691 return __rhs.compare(__lhs) == 0; 3692} 3693 3694template<class _CharT, class _Traits, class _Allocator> 3695_LIBCPP_INLINE_VISIBILITY inline 3696bool 3697operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 3698 const _CharT* __rhs) _NOEXCEPT 3699{ 3700 return __lhs.compare(__rhs) == 0; 3701} 3702 3703// operator!= 3704 3705template<class _CharT, class _Traits, class _Allocator> 3706_LIBCPP_INLINE_VISIBILITY inline 3707bool 3708operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 3709 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3710{ 3711 return !(__lhs == __rhs); 3712} 3713 3714template<class _CharT, class _Traits, class _Allocator> 3715_LIBCPP_INLINE_VISIBILITY inline 3716bool 3717operator!=(const _CharT* __lhs, 3718 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3719{ 3720 return !(__lhs == __rhs); 3721} 3722 3723template<class _CharT, class _Traits, class _Allocator> 3724_LIBCPP_INLINE_VISIBILITY inline 3725bool 3726operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3727 const _CharT* __rhs) _NOEXCEPT 3728{ 3729 return !(__lhs == __rhs); 3730} 3731 3732// operator< 3733 3734template<class _CharT, class _Traits, class _Allocator> 3735_LIBCPP_INLINE_VISIBILITY inline 3736bool 3737operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3738 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3739{ 3740 return __lhs.compare(__rhs) < 0; 3741} 3742 3743template<class _CharT, class _Traits, class _Allocator> 3744_LIBCPP_INLINE_VISIBILITY inline 3745bool 3746operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3747 const _CharT* __rhs) _NOEXCEPT 3748{ 3749 return __lhs.compare(__rhs) < 0; 3750} 3751 3752template<class _CharT, class _Traits, class _Allocator> 3753_LIBCPP_INLINE_VISIBILITY inline 3754bool 3755operator< (const _CharT* __lhs, 3756 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3757{ 3758 return __rhs.compare(__lhs) > 0; 3759} 3760 3761// operator> 3762 3763template<class _CharT, class _Traits, class _Allocator> 3764_LIBCPP_INLINE_VISIBILITY inline 3765bool 3766operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3767 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3768{ 3769 return __rhs < __lhs; 3770} 3771 3772template<class _CharT, class _Traits, class _Allocator> 3773_LIBCPP_INLINE_VISIBILITY inline 3774bool 3775operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3776 const _CharT* __rhs) _NOEXCEPT 3777{ 3778 return __rhs < __lhs; 3779} 3780 3781template<class _CharT, class _Traits, class _Allocator> 3782_LIBCPP_INLINE_VISIBILITY inline 3783bool 3784operator> (const _CharT* __lhs, 3785 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3786{ 3787 return __rhs < __lhs; 3788} 3789 3790// operator<= 3791 3792template<class _CharT, class _Traits, class _Allocator> 3793_LIBCPP_INLINE_VISIBILITY inline 3794bool 3795operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3796 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3797{ 3798 return !(__rhs < __lhs); 3799} 3800 3801template<class _CharT, class _Traits, class _Allocator> 3802_LIBCPP_INLINE_VISIBILITY inline 3803bool 3804operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3805 const _CharT* __rhs) _NOEXCEPT 3806{ 3807 return !(__rhs < __lhs); 3808} 3809 3810template<class _CharT, class _Traits, class _Allocator> 3811_LIBCPP_INLINE_VISIBILITY inline 3812bool 3813operator<=(const _CharT* __lhs, 3814 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3815{ 3816 return !(__rhs < __lhs); 3817} 3818 3819// operator>= 3820 3821template<class _CharT, class _Traits, class _Allocator> 3822_LIBCPP_INLINE_VISIBILITY inline 3823bool 3824operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3825 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3826{ 3827 return !(__lhs < __rhs); 3828} 3829 3830template<class _CharT, class _Traits, class _Allocator> 3831_LIBCPP_INLINE_VISIBILITY inline 3832bool 3833operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3834 const _CharT* __rhs) _NOEXCEPT 3835{ 3836 return !(__lhs < __rhs); 3837} 3838 3839template<class _CharT, class _Traits, class _Allocator> 3840_LIBCPP_INLINE_VISIBILITY inline 3841bool 3842operator>=(const _CharT* __lhs, 3843 const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 3844{ 3845 return !(__lhs < __rhs); 3846} 3847 3848// operator + 3849 3850template<class _CharT, class _Traits, class _Allocator> 3851basic_string<_CharT, _Traits, _Allocator> 3852operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3853 const basic_string<_CharT, _Traits, _Allocator>& __rhs) 3854{ 3855 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); 3856 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); 3857 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); 3858 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); 3859 __r.append(__rhs.data(), __rhs_sz); 3860 return __r; 3861} 3862 3863template<class _CharT, class _Traits, class _Allocator> 3864basic_string<_CharT, _Traits, _Allocator> 3865operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) 3866{ 3867 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); 3868 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs); 3869 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); 3870 __r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz); 3871 __r.append(__rhs.data(), __rhs_sz); 3872 return __r; 3873} 3874 3875template<class _CharT, class _Traits, class _Allocator> 3876basic_string<_CharT, _Traits, _Allocator> 3877operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) 3878{ 3879 basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator()); 3880 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size(); 3881 __r.__init(&__lhs, 1, 1 + __rhs_sz); 3882 __r.append(__rhs.data(), __rhs_sz); 3883 return __r; 3884} 3885 3886template<class _CharT, class _Traits, class _Allocator> 3887basic_string<_CharT, _Traits, _Allocator> 3888operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) 3889{ 3890 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); 3891 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); 3892 typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs); 3893 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz); 3894 __r.append(__rhs, __rhs_sz); 3895 return __r; 3896} 3897 3898template<class _CharT, class _Traits, class _Allocator> 3899basic_string<_CharT, _Traits, _Allocator> 3900operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) 3901{ 3902 basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator()); 3903 typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size(); 3904 __r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1); 3905 __r.push_back(__rhs); 3906 return __r; 3907} 3908 3909#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 3910 3911template<class _CharT, class _Traits, class _Allocator> 3912_LIBCPP_INLINE_VISIBILITY inline 3913basic_string<_CharT, _Traits, _Allocator> 3914operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) 3915{ 3916 return _VSTD::move(__lhs.append(__rhs)); 3917} 3918 3919template<class _CharT, class _Traits, class _Allocator> 3920_LIBCPP_INLINE_VISIBILITY inline 3921basic_string<_CharT, _Traits, _Allocator> 3922operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) 3923{ 3924 return _VSTD::move(__rhs.insert(0, __lhs)); 3925} 3926 3927template<class _CharT, class _Traits, class _Allocator> 3928_LIBCPP_INLINE_VISIBILITY inline 3929basic_string<_CharT, _Traits, _Allocator> 3930operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) 3931{ 3932 return _VSTD::move(__lhs.append(__rhs)); 3933} 3934 3935template<class _CharT, class _Traits, class _Allocator> 3936_LIBCPP_INLINE_VISIBILITY inline 3937basic_string<_CharT, _Traits, _Allocator> 3938operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) 3939{ 3940 return _VSTD::move(__rhs.insert(0, __lhs)); 3941} 3942 3943template<class _CharT, class _Traits, class _Allocator> 3944_LIBCPP_INLINE_VISIBILITY inline 3945basic_string<_CharT, _Traits, _Allocator> 3946operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) 3947{ 3948 __rhs.insert(__rhs.begin(), __lhs); 3949 return _VSTD::move(__rhs); 3950} 3951 3952template<class _CharT, class _Traits, class _Allocator> 3953_LIBCPP_INLINE_VISIBILITY inline 3954basic_string<_CharT, _Traits, _Allocator> 3955operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) 3956{ 3957 return _VSTD::move(__lhs.append(__rhs)); 3958} 3959 3960template<class _CharT, class _Traits, class _Allocator> 3961_LIBCPP_INLINE_VISIBILITY inline 3962basic_string<_CharT, _Traits, _Allocator> 3963operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) 3964{ 3965 __lhs.push_back(__rhs); 3966 return _VSTD::move(__lhs); 3967} 3968 3969#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 3970 3971// swap 3972 3973template<class _CharT, class _Traits, class _Allocator> 3974_LIBCPP_INLINE_VISIBILITY inline 3975void 3976swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, 3977 basic_string<_CharT, _Traits, _Allocator>& __rhs) 3978 _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) 3979{ 3980 __lhs.swap(__rhs); 3981} 3982 3983#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 3984 3985typedef basic_string<char16_t> u16string; 3986typedef basic_string<char32_t> u32string; 3987 3988#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 3989 3990int stoi (const string& __str, size_t* __idx = 0, int __base = 10); 3991long stol (const string& __str, size_t* __idx = 0, int __base = 10); 3992unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10); 3993long long stoll (const string& __str, size_t* __idx = 0, int __base = 10); 3994unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10); 3995 3996float stof (const string& __str, size_t* __idx = 0); 3997double stod (const string& __str, size_t* __idx = 0); 3998long double stold(const string& __str, size_t* __idx = 0); 3999 4000string to_string(int __val); 4001string to_string(unsigned __val); 4002string to_string(long __val); 4003string to_string(unsigned long __val); 4004string to_string(long long __val); 4005string to_string(unsigned long long __val); 4006string to_string(float __val); 4007string to_string(double __val); 4008string to_string(long double __val); 4009 4010int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10); 4011long stol (const wstring& __str, size_t* __idx = 0, int __base = 10); 4012unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10); 4013long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10); 4014unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10); 4015 4016float stof (const wstring& __str, size_t* __idx = 0); 4017double stod (const wstring& __str, size_t* __idx = 0); 4018long double stold(const wstring& __str, size_t* __idx = 0); 4019 4020wstring to_wstring(int __val); 4021wstring to_wstring(unsigned __val); 4022wstring to_wstring(long __val); 4023wstring to_wstring(unsigned long __val); 4024wstring to_wstring(long long __val); 4025wstring to_wstring(unsigned long long __val); 4026wstring to_wstring(float __val); 4027wstring to_wstring(double __val); 4028wstring to_wstring(long double __val); 4029 4030template<class _CharT, class _Traits, class _Allocator> 4031 const typename basic_string<_CharT, _Traits, _Allocator>::size_type 4032 basic_string<_CharT, _Traits, _Allocator>::npos; 4033 4034template<class _Ptr> 4035size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e) 4036{ 4037 typedef typename iterator_traits<_Ptr>::value_type value_type; 4038 return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type)); 4039} 4040 4041template<class _CharT, class _Traits, class _Allocator> 4042struct _LIBCPP_TYPE_VIS hash<basic_string<_CharT, _Traits, _Allocator> > 4043 : public unary_function<basic_string<_CharT, _Traits, _Allocator>, size_t> 4044{ 4045 size_t 4046 operator()(const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT; 4047}; 4048 4049template<class _CharT, class _Traits, class _Allocator> 4050size_t 4051hash<basic_string<_CharT, _Traits, _Allocator> >::operator()( 4052 const basic_string<_CharT, _Traits, _Allocator>& __val) const _NOEXCEPT 4053{ 4054 return __do_string_hash(__val.data(), __val.data() + __val.size()); 4055} 4056 4057template<class _CharT, class _Traits, class _Allocator> 4058basic_ostream<_CharT, _Traits>& 4059operator<<(basic_ostream<_CharT, _Traits>& __os, 4060 const basic_string<_CharT, _Traits, _Allocator>& __str); 4061 4062template<class _CharT, class _Traits, class _Allocator> 4063basic_istream<_CharT, _Traits>& 4064operator>>(basic_istream<_CharT, _Traits>& __is, 4065 basic_string<_CharT, _Traits, _Allocator>& __str); 4066 4067template<class _CharT, class _Traits, class _Allocator> 4068basic_istream<_CharT, _Traits>& 4069getline(basic_istream<_CharT, _Traits>& __is, 4070 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); 4071 4072template<class _CharT, class _Traits, class _Allocator> 4073inline _LIBCPP_INLINE_VISIBILITY 4074basic_istream<_CharT, _Traits>& 4075getline(basic_istream<_CharT, _Traits>& __is, 4076 basic_string<_CharT, _Traits, _Allocator>& __str); 4077 4078#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 4079 4080template<class _CharT, class _Traits, class _Allocator> 4081inline _LIBCPP_INLINE_VISIBILITY 4082basic_istream<_CharT, _Traits>& 4083getline(basic_istream<_CharT, _Traits>&& __is, 4084 basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); 4085 4086template<class _CharT, class _Traits, class _Allocator> 4087inline _LIBCPP_INLINE_VISIBILITY 4088basic_istream<_CharT, _Traits>& 4089getline(basic_istream<_CharT, _Traits>&& __is, 4090 basic_string<_CharT, _Traits, _Allocator>& __str); 4091 4092#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 4093 4094_LIBCPP_EXTERN_TEMPLATE(class basic_string<char>) 4095_LIBCPP_EXTERN_TEMPLATE(class basic_string<wchar_t>) 4096 4097extern template 4098 string 4099 operator+<char, char_traits<char>, allocator<char> >(char const*, string const&); 4100 4101_LIBCPP_END_NAMESPACE_STD 4102 4103#endif // _LIBCPP_STRING 4104