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