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