10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_STRING 110b57cec5SDimitry Andric#define _LIBCPP_STRING 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric string synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andrictemplate <class stateT> 200b57cec5SDimitry Andricclass fpos 210b57cec5SDimitry Andric{ 220b57cec5SDimitry Andricprivate: 230b57cec5SDimitry Andric stateT st; 240b57cec5SDimitry Andricpublic: 250b57cec5SDimitry Andric fpos(streamoff = streamoff()); 260b57cec5SDimitry Andric 270b57cec5SDimitry Andric operator streamoff() const; 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric stateT state() const; 300b57cec5SDimitry Andric void state(stateT); 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric fpos& operator+=(streamoff); 330b57cec5SDimitry Andric fpos operator+ (streamoff) const; 340b57cec5SDimitry Andric fpos& operator-=(streamoff); 350b57cec5SDimitry Andric fpos operator- (streamoff) const; 360b57cec5SDimitry Andric}; 370b57cec5SDimitry Andric 380b57cec5SDimitry Andrictemplate <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); 390b57cec5SDimitry Andric 400b57cec5SDimitry Andrictemplate <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); 410b57cec5SDimitry Andrictemplate <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); 420b57cec5SDimitry Andric 430b57cec5SDimitry Andrictemplate <class charT> 440b57cec5SDimitry Andricstruct char_traits 450b57cec5SDimitry Andric{ 460b57cec5SDimitry Andric typedef charT char_type; 470b57cec5SDimitry Andric typedef ... int_type; 480b57cec5SDimitry Andric typedef streamoff off_type; 490b57cec5SDimitry Andric typedef streampos pos_type; 500b57cec5SDimitry Andric typedef mbstate_t state_type; 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric static void assign(char_type& c1, const char_type& c2) noexcept; 530b57cec5SDimitry Andric static constexpr bool eq(char_type c1, char_type c2) noexcept; 540b57cec5SDimitry Andric static constexpr bool lt(char_type c1, char_type c2) noexcept; 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric static int compare(const char_type* s1, const char_type* s2, size_t n); 570b57cec5SDimitry Andric static size_t length(const char_type* s); 580b57cec5SDimitry Andric static const char_type* find(const char_type* s, size_t n, const char_type& a); 590b57cec5SDimitry Andric static char_type* move(char_type* s1, const char_type* s2, size_t n); 600b57cec5SDimitry Andric static char_type* copy(char_type* s1, const char_type* s2, size_t n); 610b57cec5SDimitry Andric static char_type* assign(char_type* s, size_t n, char_type a); 620b57cec5SDimitry Andric 630b57cec5SDimitry Andric static constexpr int_type not_eof(int_type c) noexcept; 640b57cec5SDimitry Andric static constexpr char_type to_char_type(int_type c) noexcept; 650b57cec5SDimitry Andric static constexpr int_type to_int_type(char_type c) noexcept; 660b57cec5SDimitry Andric static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; 670b57cec5SDimitry Andric static constexpr int_type eof() noexcept; 680b57cec5SDimitry Andric}; 690b57cec5SDimitry Andric 700b57cec5SDimitry Andrictemplate <> struct char_traits<char>; 710b57cec5SDimitry Andrictemplate <> struct char_traits<wchar_t>; 72fe6060f1SDimitry Andrictemplate <> struct char_traits<char8_t>; // C++20 73fe6060f1SDimitry Andrictemplate <> struct char_traits<char16_t>; 74fe6060f1SDimitry Andrictemplate <> struct char_traits<char32_t>; 750b57cec5SDimitry Andric 760b57cec5SDimitry Andrictemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 770b57cec5SDimitry Andricclass basic_string 780b57cec5SDimitry Andric{ 790b57cec5SDimitry Andricpublic: 800b57cec5SDimitry Andric// types: 810b57cec5SDimitry Andric typedef traits traits_type; 820b57cec5SDimitry Andric typedef typename traits_type::char_type value_type; 830b57cec5SDimitry Andric typedef Allocator allocator_type; 840b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 850b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 860b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 870b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 880b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 890b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 900b57cec5SDimitry Andric typedef implementation-defined iterator; 910b57cec5SDimitry Andric typedef implementation-defined const_iterator; 920b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 930b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 940b57cec5SDimitry Andric 950b57cec5SDimitry Andric static const size_type npos = -1; 960b57cec5SDimitry Andric 970b57cec5SDimitry Andric basic_string() 9881ad6265SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20 9981ad6265SDimitry Andric explicit basic_string(const allocator_type& a); // constexpr since C++20 10081ad6265SDimitry Andric basic_string(const basic_string& str); // constexpr since C++20 1010b57cec5SDimitry Andric basic_string(basic_string&& str) 10281ad6265SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20 1030b57cec5SDimitry Andric basic_string(const basic_string& str, size_type pos, 10481ad6265SDimitry Andric const allocator_type& a = allocator_type()); // constexpr since C++20 1050b57cec5SDimitry Andric basic_string(const basic_string& str, size_type pos, size_type n, 10681ad6265SDimitry Andric const Allocator& a = Allocator()); // constexpr since C++20 1070b57cec5SDimitry Andric template<class T> 10881ad6265SDimitry Andric basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17, constexpr since C++20 1090b57cec5SDimitry Andric template <class T> 11081ad6265SDimitry Andric explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20 11181ad6265SDimitry Andric basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20 11281ad6265SDimitry Andric basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); // constexpr since C++20 113fe6060f1SDimitry Andric basic_string(nullptr_t) = delete; // C++2b 11481ad6265SDimitry Andric basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); // constexpr since C++20 1150b57cec5SDimitry Andric template<class InputIterator> 1160b57cec5SDimitry Andric basic_string(InputIterator begin, InputIterator end, 11781ad6265SDimitry Andric const allocator_type& a = allocator_type()); // constexpr since C++20 11881ad6265SDimitry Andric basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20 11981ad6265SDimitry Andric basic_string(const basic_string&, const Allocator&); // constexpr since C++20 12081ad6265SDimitry Andric basic_string(basic_string&&, const Allocator&); // constexpr since C++20 1210b57cec5SDimitry Andric 12281ad6265SDimitry Andric ~basic_string(); // constexpr since C++20 1230b57cec5SDimitry Andric 12481ad6265SDimitry Andric operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20 1250b57cec5SDimitry Andric 12681ad6265SDimitry Andric basic_string& operator=(const basic_string& str); // constexpr since C++20 1270b57cec5SDimitry Andric template <class T> 12881ad6265SDimitry Andric basic_string& operator=(const T& t); // C++17, constexpr since C++20 1290b57cec5SDimitry Andric basic_string& operator=(basic_string&& str) 1300b57cec5SDimitry Andric noexcept( 1310b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 13281ad6265SDimitry Andric allocator_type::is_always_equal::value ); // C++17, constexpr since C++20 13381ad6265SDimitry Andric basic_string& operator=(const value_type* s); // constexpr since C++20 134fe6060f1SDimitry Andric basic_string& operator=(nullptr_t) = delete; // C++2b 13581ad6265SDimitry Andric basic_string& operator=(value_type c); // constexpr since C++20 13681ad6265SDimitry Andric basic_string& operator=(initializer_list<value_type>); // constexpr since C++20 1370b57cec5SDimitry Andric 13881ad6265SDimitry Andric iterator begin() noexcept; // constexpr since C++20 13981ad6265SDimitry Andric const_iterator begin() const noexcept; // constexpr since C++20 14081ad6265SDimitry Andric iterator end() noexcept; // constexpr since C++20 14181ad6265SDimitry Andric const_iterator end() const noexcept; // constexpr since C++20 1420b57cec5SDimitry Andric 14381ad6265SDimitry Andric reverse_iterator rbegin() noexcept; // constexpr since C++20 14481ad6265SDimitry Andric const_reverse_iterator rbegin() const noexcept; // constexpr since C++20 14581ad6265SDimitry Andric reverse_iterator rend() noexcept; // constexpr since C++20 14681ad6265SDimitry Andric const_reverse_iterator rend() const noexcept; // constexpr since C++20 1470b57cec5SDimitry Andric 14881ad6265SDimitry Andric const_iterator cbegin() const noexcept; // constexpr since C++20 14981ad6265SDimitry Andric const_iterator cend() const noexcept; // constexpr since C++20 15081ad6265SDimitry Andric const_reverse_iterator crbegin() const noexcept; // constexpr since C++20 15181ad6265SDimitry Andric const_reverse_iterator crend() const noexcept; // constexpr since C++20 1520b57cec5SDimitry Andric 15381ad6265SDimitry Andric size_type size() const noexcept; // constexpr since C++20 15481ad6265SDimitry Andric size_type length() const noexcept; // constexpr since C++20 15581ad6265SDimitry Andric size_type max_size() const noexcept; // constexpr since C++20 15681ad6265SDimitry Andric size_type capacity() const noexcept; // constexpr since C++20 1570b57cec5SDimitry Andric 15881ad6265SDimitry Andric void resize(size_type n, value_type c); // constexpr since C++20 15981ad6265SDimitry Andric void resize(size_type n); // constexpr since C++20 1600b57cec5SDimitry Andric 16104eeddc0SDimitry Andric template<class Operation> 16204eeddc0SDimitry Andric constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23 16304eeddc0SDimitry Andric 16481ad6265SDimitry Andric void reserve(size_type res_arg); // constexpr since C++20 165e8d8bef9SDimitry Andric void reserve(); // deprecated in C++20 16681ad6265SDimitry Andric void shrink_to_fit(); // constexpr since C++20 16781ad6265SDimitry Andric void clear() noexcept; // constexpr since C++20 16881ad6265SDimitry Andric bool empty() const noexcept; // constexpr since C++20 1690b57cec5SDimitry Andric 17081ad6265SDimitry Andric const_reference operator[](size_type pos) const; // constexpr since C++20 17181ad6265SDimitry Andric reference operator[](size_type pos); // constexpr since C++20 1720b57cec5SDimitry Andric 17381ad6265SDimitry Andric const_reference at(size_type n) const; // constexpr since C++20 17481ad6265SDimitry Andric reference at(size_type n); // constexpr since C++20 1750b57cec5SDimitry Andric 17681ad6265SDimitry Andric basic_string& operator+=(const basic_string& str); // constexpr since C++20 1770b57cec5SDimitry Andric template <class T> 17881ad6265SDimitry Andric basic_string& operator+=(const T& t); // C++17, constexpr since C++20 17981ad6265SDimitry Andric basic_string& operator+=(const value_type* s); // constexpr since C++20 18081ad6265SDimitry Andric basic_string& operator+=(value_type c); // constexpr since C++20 18181ad6265SDimitry Andric basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20 1820b57cec5SDimitry Andric 18381ad6265SDimitry Andric basic_string& append(const basic_string& str); // constexpr since C++20 1840b57cec5SDimitry Andric template <class T> 18581ad6265SDimitry Andric basic_string& append(const T& t); // C++17, constexpr since C++20 18681ad6265SDimitry Andric basic_string& append(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 1870b57cec5SDimitry Andric template <class T> 18881ad6265SDimitry Andric basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 18981ad6265SDimitry Andric basic_string& append(const value_type* s, size_type n); // constexpr since C++20 19081ad6265SDimitry Andric basic_string& append(const value_type* s); // constexpr since C++20 19181ad6265SDimitry Andric basic_string& append(size_type n, value_type c); // constexpr since C++20 1920b57cec5SDimitry Andric template<class InputIterator> 19381ad6265SDimitry Andric basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20 19481ad6265SDimitry Andric basic_string& append(initializer_list<value_type>); // constexpr since C++20 1950b57cec5SDimitry Andric 19681ad6265SDimitry Andric void push_back(value_type c); // constexpr since C++20 19781ad6265SDimitry Andric void pop_back(); // constexpr since C++20 19881ad6265SDimitry Andric reference front(); // constexpr since C++20 19981ad6265SDimitry Andric const_reference front() const; // constexpr since C++20 20081ad6265SDimitry Andric reference back(); // constexpr since C++20 20181ad6265SDimitry Andric const_reference back() const; // constexpr since C++20 2020b57cec5SDimitry Andric 20381ad6265SDimitry Andric basic_string& assign(const basic_string& str); // constexpr since C++20 2040b57cec5SDimitry Andric template <class T> 20581ad6265SDimitry Andric basic_string& assign(const T& t); // C++17, constexpr since C++20 20681ad6265SDimitry Andric basic_string& assign(basic_string&& str); // constexpr since C++20 20781ad6265SDimitry Andric basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 2080b57cec5SDimitry Andric template <class T> 20981ad6265SDimitry Andric basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 21081ad6265SDimitry Andric basic_string& assign(const value_type* s, size_type n); // constexpr since C++20 21181ad6265SDimitry Andric basic_string& assign(const value_type* s); // constexpr since C++20 21281ad6265SDimitry Andric basic_string& assign(size_type n, value_type c); // constexpr since C++20 2130b57cec5SDimitry Andric template<class InputIterator> 21481ad6265SDimitry Andric basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20 21581ad6265SDimitry Andric basic_string& assign(initializer_list<value_type>); // constexpr since C++20 2160b57cec5SDimitry Andric 21781ad6265SDimitry Andric basic_string& insert(size_type pos1, const basic_string& str); // constexpr since C++20 2180b57cec5SDimitry Andric template <class T> 21981ad6265SDimitry Andric basic_string& insert(size_type pos1, const T& t); // constexpr since C++20 2200b57cec5SDimitry Andric basic_string& insert(size_type pos1, const basic_string& str, 22181ad6265SDimitry Andric size_type pos2, size_type n); // constexpr since C++20 2220b57cec5SDimitry Andric template <class T> 22381ad6265SDimitry Andric basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20 22481ad6265SDimitry Andric basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20 22581ad6265SDimitry Andric basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20 22681ad6265SDimitry Andric basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20 22781ad6265SDimitry Andric iterator insert(const_iterator p, value_type c); // constexpr since C++20 22881ad6265SDimitry Andric iterator insert(const_iterator p, size_type n, value_type c); // constexpr since C++20 2290b57cec5SDimitry Andric template<class InputIterator> 23081ad6265SDimitry Andric iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20 23181ad6265SDimitry Andric iterator insert(const_iterator p, initializer_list<value_type>); // constexpr since C++20 2320b57cec5SDimitry Andric 23381ad6265SDimitry Andric basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20 23481ad6265SDimitry Andric iterator erase(const_iterator position); // constexpr since C++20 23581ad6265SDimitry Andric iterator erase(const_iterator first, const_iterator last); // constexpr since C++20 2360b57cec5SDimitry Andric 23781ad6265SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const basic_string& str); // constexpr since C++20 2380b57cec5SDimitry Andric template <class T> 23981ad6265SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17, constexpr since C++20 2400b57cec5SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const basic_string& str, 24181ad6265SDimitry Andric size_type pos2, size_type n2=npos); // C++14, constexpr since C++20 2420b57cec5SDimitry Andric template <class T> 2430b57cec5SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const T& t, 24481ad6265SDimitry Andric size_type pos2, size_type n); // C++17, constexpr since C++20 24581ad6265SDimitry Andric basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20 24681ad6265SDimitry Andric basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20 24781ad6265SDimitry Andric basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20 24881ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); // constexpr since C++20 2490b57cec5SDimitry Andric template <class T> 25081ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20 25181ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20 25281ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20 25381ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); // constexpr since C++20 2540b57cec5SDimitry Andric template<class InputIterator> 25581ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20 25681ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20 2570b57cec5SDimitry Andric 25881ad6265SDimitry Andric size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20 25981ad6265SDimitry Andric basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr since C++20 2600b57cec5SDimitry Andric 2610b57cec5SDimitry Andric void swap(basic_string& str) 2620b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 26381ad6265SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20 2640b57cec5SDimitry Andric 26581ad6265SDimitry Andric const value_type* c_str() const noexcept; // constexpr since C++20 26681ad6265SDimitry Andric const value_type* data() const noexcept; // constexpr since C++20 26781ad6265SDimitry Andric value_type* data() noexcept; // C++17, constexpr since C++20 2680b57cec5SDimitry Andric 26981ad6265SDimitry Andric allocator_type get_allocator() const noexcept; // constexpr since C++20 2700b57cec5SDimitry Andric 27181ad6265SDimitry Andric size_type find(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 2720b57cec5SDimitry Andric template <class T> 27381ad6265SDimitry Andric size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 27481ad6265SDimitry Andric size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 27581ad6265SDimitry Andric size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 27681ad6265SDimitry Andric size_type find(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 2770b57cec5SDimitry Andric 27881ad6265SDimitry Andric size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 2790b57cec5SDimitry Andric template <class T> 28081ad6265SDimitry Andric size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 28181ad6265SDimitry Andric size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 28281ad6265SDimitry Andric size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 28381ad6265SDimitry Andric size_type rfind(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 2840b57cec5SDimitry Andric 28581ad6265SDimitry Andric size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 2860b57cec5SDimitry Andric template <class T> 28781ad6265SDimitry Andric size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 28881ad6265SDimitry Andric size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 28981ad6265SDimitry Andric size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 29081ad6265SDimitry Andric size_type find_first_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 2910b57cec5SDimitry Andric 29281ad6265SDimitry Andric size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 2930b57cec5SDimitry Andric template <class T> 29481ad6265SDimitry Andric size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension, constexpr since C++20 29581ad6265SDimitry Andric size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 29681ad6265SDimitry Andric size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 29781ad6265SDimitry Andric size_type find_last_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 2980b57cec5SDimitry Andric 29981ad6265SDimitry Andric size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 3000b57cec5SDimitry Andric template <class T> 30181ad6265SDimitry Andric size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 30281ad6265SDimitry Andric size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 30381ad6265SDimitry Andric size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 30481ad6265SDimitry Andric size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 3050b57cec5SDimitry Andric 30681ad6265SDimitry Andric size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 3070b57cec5SDimitry Andric template <class T> 30881ad6265SDimitry Andric size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 30981ad6265SDimitry Andric size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 31081ad6265SDimitry Andric size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 31181ad6265SDimitry Andric size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 3120b57cec5SDimitry Andric 31381ad6265SDimitry Andric int compare(const basic_string& str) const noexcept; // constexpr since C++20 3140b57cec5SDimitry Andric template <class T> 31581ad6265SDimitry Andric int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 31681ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const basic_string& str) const; // constexpr since C++20 3170b57cec5SDimitry Andric template <class T> 31881ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const T& t) const; // C++17, constexpr since C++20 3190b57cec5SDimitry Andric int compare(size_type pos1, size_type n1, const basic_string& str, 32081ad6265SDimitry Andric size_type pos2, size_type n2=npos) const; // C++14, constexpr since C++20 3210b57cec5SDimitry Andric template <class T> 3220b57cec5SDimitry Andric int compare(size_type pos1, size_type n1, const T& t, 32381ad6265SDimitry Andric size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20 32481ad6265SDimitry Andric int compare(const value_type* s) const noexcept; // constexpr since C++20 32581ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20 32681ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; // constexpr since C++20 3270b57cec5SDimitry Andric 32881ad6265SDimitry Andric constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 32981ad6265SDimitry Andric constexpr bool starts_with(charT c) const noexcept; // C++20 33081ad6265SDimitry Andric constexpr bool starts_with(const charT* s) const; // C++20 33181ad6265SDimitry Andric constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 33281ad6265SDimitry Andric constexpr bool ends_with(charT c) const noexcept; // C++20 33381ad6265SDimitry Andric constexpr bool ends_with(const charT* s) const; // C++20 334e8d8bef9SDimitry Andric 335e8d8bef9SDimitry Andric constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b 336e8d8bef9SDimitry Andric constexpr bool contains(charT c) const noexcept; // C++2b 337e8d8bef9SDimitry Andric constexpr bool contains(const charT* s) const; // C++2b 3380b57cec5SDimitry Andric}; 3390b57cec5SDimitry Andric 3400b57cec5SDimitry Andrictemplate<class InputIterator, 3410b57cec5SDimitry Andric class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 3420b57cec5SDimitry Andricbasic_string(InputIterator, InputIterator, Allocator = Allocator()) 3430b57cec5SDimitry Andric -> basic_string<typename iterator_traits<InputIterator>::value_type, 3440b57cec5SDimitry Andric char_traits<typename iterator_traits<InputIterator>::value_type>, 3450b57cec5SDimitry Andric Allocator>; // C++17 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3480b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 3490b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, 35081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20 3510b57cec5SDimitry Andric 3520b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3530b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 35481ad6265SDimitry Andricoperator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); // constexpr since C++20 3550b57cec5SDimitry Andric 3560b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3570b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 35881ad6265SDimitry Andricoperator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3610b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 36281ad6265SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // constexpr since C++20 3630b57cec5SDimitry Andric 3640b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3650b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 36681ad6265SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); // constexpr since C++20 3670b57cec5SDimitry Andric 3680b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3690b57cec5SDimitry Andricbool operator==(const basic_string<charT, traits, Allocator>& lhs, 37081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 3710b57cec5SDimitry Andric 3720b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 37381ad6265SDimitry Andricbool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 3740b57cec5SDimitry Andric 3750b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 37681ad6265SDimitry Andricbool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 3770b57cec5SDimitry Andric 3780b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3790b57cec5SDimitry Andricbool operator!=(const basic_string<charT,traits,Allocator>& lhs, 38081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 3810b57cec5SDimitry Andric 3820b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 38381ad6265SDimitry Andricbool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 3840b57cec5SDimitry Andric 3850b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 38681ad6265SDimitry Andricbool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3890b57cec5SDimitry Andricbool operator< (const basic_string<charT, traits, Allocator>& lhs, 39081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 3910b57cec5SDimitry Andric 3920b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 39381ad6265SDimitry Andricbool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 3940b57cec5SDimitry Andric 3950b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 39681ad6265SDimitry Andricbool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 3970b57cec5SDimitry Andric 3980b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3990b57cec5SDimitry Andricbool operator> (const basic_string<charT, traits, Allocator>& lhs, 40081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 4010b57cec5SDimitry Andric 4020b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 40381ad6265SDimitry Andricbool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 4040b57cec5SDimitry Andric 4050b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 40681ad6265SDimitry Andricbool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 4070b57cec5SDimitry Andric 4080b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4090b57cec5SDimitry Andricbool operator<=(const basic_string<charT, traits, Allocator>& lhs, 41081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 4110b57cec5SDimitry Andric 4120b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 41381ad6265SDimitry Andricbool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 4140b57cec5SDimitry Andric 4150b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 41681ad6265SDimitry Andricbool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 4170b57cec5SDimitry Andric 4180b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4190b57cec5SDimitry Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs, 42081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 4210b57cec5SDimitry Andric 4220b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 42381ad6265SDimitry Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 4240b57cec5SDimitry Andric 4250b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 42681ad6265SDimitry Andricbool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4290b57cec5SDimitry Andricvoid swap(basic_string<charT, traits, Allocator>& lhs, 4300b57cec5SDimitry Andric basic_string<charT, traits, Allocator>& rhs) 43181ad6265SDimitry Andric noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20 4320b57cec5SDimitry Andric 4330b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4340b57cec5SDimitry Andricbasic_istream<charT, traits>& 4350b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4380b57cec5SDimitry Andricbasic_ostream<charT, traits>& 4390b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); 4400b57cec5SDimitry Andric 4410b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4420b57cec5SDimitry Andricbasic_istream<charT, traits>& 4430b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, 4440b57cec5SDimitry Andric charT delim); 4450b57cec5SDimitry Andric 4460b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4470b57cec5SDimitry Andricbasic_istream<charT, traits>& 4480b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); 4490b57cec5SDimitry Andric 4500b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class U> 4515ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type 4525ffd83dbSDimitry Andricerase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20 4530b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class Predicate> 4545ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type 4555ffd83dbSDimitry Andricerase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20 4560b57cec5SDimitry Andric 4570b57cec5SDimitry Andrictypedef basic_string<char> string; 4580b57cec5SDimitry Andrictypedef basic_string<wchar_t> wstring; 459fe6060f1SDimitry Andrictypedef basic_string<char8_t> u8string; // C++20 4600b57cec5SDimitry Andrictypedef basic_string<char16_t> u16string; 4610b57cec5SDimitry Andrictypedef basic_string<char32_t> u32string; 4620b57cec5SDimitry Andric 463e8d8bef9SDimitry Andricint stoi (const string& str, size_t* idx = nullptr, int base = 10); 464e8d8bef9SDimitry Andriclong stol (const string& str, size_t* idx = nullptr, int base = 10); 465e8d8bef9SDimitry Andricunsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10); 466e8d8bef9SDimitry Andriclong long stoll (const string& str, size_t* idx = nullptr, int base = 10); 467e8d8bef9SDimitry Andricunsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10); 4680b57cec5SDimitry Andric 469e8d8bef9SDimitry Andricfloat stof (const string& str, size_t* idx = nullptr); 470e8d8bef9SDimitry Andricdouble stod (const string& str, size_t* idx = nullptr); 471e8d8bef9SDimitry Andriclong double stold(const string& str, size_t* idx = nullptr); 4720b57cec5SDimitry Andric 4730b57cec5SDimitry Andricstring to_string(int val); 4740b57cec5SDimitry Andricstring to_string(unsigned val); 4750b57cec5SDimitry Andricstring to_string(long val); 4760b57cec5SDimitry Andricstring to_string(unsigned long val); 4770b57cec5SDimitry Andricstring to_string(long long val); 4780b57cec5SDimitry Andricstring to_string(unsigned long long val); 4790b57cec5SDimitry Andricstring to_string(float val); 4800b57cec5SDimitry Andricstring to_string(double val); 4810b57cec5SDimitry Andricstring to_string(long double val); 4820b57cec5SDimitry Andric 483e8d8bef9SDimitry Andricint stoi (const wstring& str, size_t* idx = nullptr, int base = 10); 484e8d8bef9SDimitry Andriclong stol (const wstring& str, size_t* idx = nullptr, int base = 10); 485e8d8bef9SDimitry Andricunsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10); 486e8d8bef9SDimitry Andriclong long stoll (const wstring& str, size_t* idx = nullptr, int base = 10); 487e8d8bef9SDimitry Andricunsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10); 4880b57cec5SDimitry Andric 489e8d8bef9SDimitry Andricfloat stof (const wstring& str, size_t* idx = nullptr); 490e8d8bef9SDimitry Andricdouble stod (const wstring& str, size_t* idx = nullptr); 491e8d8bef9SDimitry Andriclong double stold(const wstring& str, size_t* idx = nullptr); 4920b57cec5SDimitry Andric 4930b57cec5SDimitry Andricwstring to_wstring(int val); 4940b57cec5SDimitry Andricwstring to_wstring(unsigned val); 4950b57cec5SDimitry Andricwstring to_wstring(long val); 4960b57cec5SDimitry Andricwstring to_wstring(unsigned long val); 4970b57cec5SDimitry Andricwstring to_wstring(long long val); 4980b57cec5SDimitry Andricwstring to_wstring(unsigned long long val); 4990b57cec5SDimitry Andricwstring to_wstring(float val); 5000b57cec5SDimitry Andricwstring to_wstring(double val); 5010b57cec5SDimitry Andricwstring to_wstring(long double val); 5020b57cec5SDimitry Andric 5030b57cec5SDimitry Andrictemplate <> struct hash<string>; 504fe6060f1SDimitry Andrictemplate <> struct hash<u8string>; // C++20 5050b57cec5SDimitry Andrictemplate <> struct hash<u16string>; 5060b57cec5SDimitry Andrictemplate <> struct hash<u32string>; 5070b57cec5SDimitry Andrictemplate <> struct hash<wstring>; 5080b57cec5SDimitry Andric 50981ad6265SDimitry Andricbasic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20 51081ad6265SDimitry Andricbasic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20 51181ad6265SDimitry Andricconstexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20 51281ad6265SDimitry Andricbasic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20 51381ad6265SDimitry Andricbasic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14, constexpr since C++20 5140b57cec5SDimitry Andric 5150b57cec5SDimitry Andric} // std 5160b57cec5SDimitry Andric 5170b57cec5SDimitry Andric*/ 5180b57cec5SDimitry Andric 51981ad6265SDimitry Andric#include <__algorithm/max.h> 52081ad6265SDimitry Andric#include <__algorithm/min.h> 52181ad6265SDimitry Andric#include <__algorithm/remove.h> 52281ad6265SDimitry Andric#include <__algorithm/remove_if.h> 52381ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 5240b57cec5SDimitry Andric#include <__config> 525fe6060f1SDimitry Andric#include <__debug> 52681ad6265SDimitry Andric#include <__format/enable_insertable.h> 52781ad6265SDimitry Andric#include <__functional/hash.h> 52881ad6265SDimitry Andric#include <__functional/unary_function.h> 52981ad6265SDimitry Andric#include <__ios/fpos.h> 53081ad6265SDimitry Andric#include <__iterator/distance.h> 53181ad6265SDimitry Andric#include <__iterator/iterator_traits.h> 53281ad6265SDimitry Andric#include <__iterator/reverse_iterator.h> 533fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h> 53481ad6265SDimitry Andric#include <__memory/allocate_at_least.h> 535*972a253aSDimitry Andric#include <__memory/swap_allocator.h> 53681ad6265SDimitry Andric#include <__string/char_traits.h> 53781ad6265SDimitry Andric#include <__string/extern_template_lists.h> 53881ad6265SDimitry Andric#include <__utility/auto_cast.h> 53981ad6265SDimitry Andric#include <__utility/move.h> 54081ad6265SDimitry Andric#include <__utility/swap.h> 54181ad6265SDimitry Andric#include <__utility/unreachable.h> 54281ad6265SDimitry Andric#include <climits> 54381ad6265SDimitry Andric#include <cstdint> 544fe6060f1SDimitry Andric#include <cstdio> // EOF 54569ade1e0SDimitry Andric#include <cstdlib> 546fe6060f1SDimitry Andric#include <cstring> 547fe6060f1SDimitry Andric#include <iosfwd> 54881ad6265SDimitry Andric#include <limits> 5490b57cec5SDimitry Andric#include <memory> 5500b57cec5SDimitry Andric#include <stdexcept> 551fe6060f1SDimitry Andric#include <string_view> 5520b57cec5SDimitry Andric#include <type_traits> 5530b57cec5SDimitry Andric#include <version> 554fe6060f1SDimitry Andric 555349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 556349cc55cSDimitry Andric# include <cwchar> 557349cc55cSDimitry Andric#endif 558349cc55cSDimitry Andric 55981ad6265SDimitry Andric#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 56081ad6265SDimitry Andric# include <algorithm> 56181ad6265SDimitry Andric# include <functional> 56281ad6265SDimitry Andric# include <iterator> 56381ad6265SDimitry Andric# include <new> 56481ad6265SDimitry Andric# include <typeinfo> 56581ad6265SDimitry Andric# include <utility> 56681ad6265SDimitry Andric# include <vector> 5670b57cec5SDimitry Andric#endif 5680b57cec5SDimitry Andric 56981ad6265SDimitry Andric// standard-mandated includes 57081ad6265SDimitry Andric 57181ad6265SDimitry Andric// [iterator.range] 57281ad6265SDimitry Andric#include <__iterator/access.h> 57381ad6265SDimitry Andric#include <__iterator/data.h> 57481ad6265SDimitry Andric#include <__iterator/empty.h> 57581ad6265SDimitry Andric#include <__iterator/reverse_access.h> 57681ad6265SDimitry Andric#include <__iterator/size.h> 57781ad6265SDimitry Andric 57881ad6265SDimitry Andric// [string.syn] 57981ad6265SDimitry Andric#include <compare> 58081ad6265SDimitry Andric#include <initializer_list> 58181ad6265SDimitry Andric 5820b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 5830b57cec5SDimitry Andric# pragma GCC system_header 5840b57cec5SDimitry Andric#endif 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 5870b57cec5SDimitry Andric#include <__undef_macros> 5880b57cec5SDimitry Andric 5890b57cec5SDimitry Andric 5900b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 5910b57cec5SDimitry Andric 5920b57cec5SDimitry Andric// basic_string 5930b57cec5SDimitry Andric 5940b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 5950b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 59681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 5970b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, 5980b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __y); 5990b57cec5SDimitry Andric 6000b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 60181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 6020b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6030b57cec5SDimitry Andricoperator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); 6040b57cec5SDimitry Andric 6050b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 60681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 6070b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6080b57cec5SDimitry Andricoperator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); 6090b57cec5SDimitry Andric 6100b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 61181ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 6120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6130b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); 6140b57cec5SDimitry Andric 6150b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 61681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 6170b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6180b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); 6190b57cec5SDimitry Andric 62081ad6265SDimitry Andricextern template _LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&); 6210b57cec5SDimitry Andric 6220b57cec5SDimitry Andrictemplate <class _Iter> 623fe6060f1SDimitry Andricstruct __string_is_trivial_iterator : public false_type {}; 624fe6060f1SDimitry Andric 625fe6060f1SDimitry Andrictemplate <class _Tp> 626fe6060f1SDimitry Andricstruct __string_is_trivial_iterator<_Tp*> 627fe6060f1SDimitry Andric : public is_arithmetic<_Tp> {}; 6280b57cec5SDimitry Andric 6290b57cec5SDimitry Andrictemplate <class _Iter> 630fe6060f1SDimitry Andricstruct __string_is_trivial_iterator<__wrap_iter<_Iter> > 631fe6060f1SDimitry Andric : public __string_is_trivial_iterator<_Iter> {}; 6320b57cec5SDimitry Andric 6330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Tp> 6345ffd83dbSDimitry Andricstruct __can_be_converted_to_string_view : public _BoolConstant< 6355ffd83dbSDimitry Andric is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && 6365ffd83dbSDimitry Andric !is_convertible<const _Tp&, const _CharT*>::value 6375ffd83dbSDimitry Andric > {}; 6380b57cec5SDimitry Andric 639fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 640e8d8bef9SDimitry Andrictypedef basic_string<char8_t> u8string; 641e8d8bef9SDimitry Andric#endif 642e8d8bef9SDimitry Andrictypedef basic_string<char16_t> u16string; 643e8d8bef9SDimitry Andrictypedef basic_string<char32_t> u32string; 64481ad6265SDimitry Andric 64581ad6265SDimitry Andricstruct __uninitialized_size_tag {}; 646e8d8bef9SDimitry Andric 6470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 648e8d8bef9SDimitry Andricclass 649e8d8bef9SDimitry Andric _LIBCPP_TEMPLATE_VIS 650fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 651e8d8bef9SDimitry Andric _LIBCPP_PREFERRED_NAME(u8string) 652e8d8bef9SDimitry Andric#endif 653e8d8bef9SDimitry Andric _LIBCPP_PREFERRED_NAME(u16string) 654e8d8bef9SDimitry Andric _LIBCPP_PREFERRED_NAME(u32string) 655e8d8bef9SDimitry Andric basic_string 6560b57cec5SDimitry Andric{ 6570b57cec5SDimitry Andricpublic: 6580b57cec5SDimitry Andric typedef basic_string __self; 6590b57cec5SDimitry Andric typedef basic_string_view<_CharT, _Traits> __self_view; 6600b57cec5SDimitry Andric typedef _Traits traits_type; 6610b57cec5SDimitry Andric typedef _CharT value_type; 6620b57cec5SDimitry Andric typedef _Allocator allocator_type; 6630b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 6640b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 6650b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 6660b57cec5SDimitry Andric typedef value_type& reference; 6670b57cec5SDimitry Andric typedef const value_type& const_reference; 6680b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 6690b57cec5SDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 6700b57cec5SDimitry Andric 6710b57cec5SDimitry Andric static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); 6720b57cec5SDimitry Andric static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); 6730b57cec5SDimitry Andric static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); 6740b57cec5SDimitry Andric static_assert(( is_same<_CharT, typename traits_type::char_type>::value), 6750b57cec5SDimitry Andric "traits_type::char_type must be the same type as CharT"); 6760b57cec5SDimitry Andric static_assert(( is_same<typename allocator_type::value_type, value_type>::value), 6770b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 6780b57cec5SDimitry Andric 6790b57cec5SDimitry Andric typedef __wrap_iter<pointer> iterator; 6800b57cec5SDimitry Andric typedef __wrap_iter<const_pointer> const_iterator; 68181ad6265SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 68281ad6265SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 6830b57cec5SDimitry Andric 6840b57cec5SDimitry Andricprivate: 68581ad6265SDimitry Andric static_assert(CHAR_BIT == 8, "This implementation assumes that one byte contains 8 bits"); 6860b57cec5SDimitry Andric 6870b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 6880b57cec5SDimitry Andric 6890b57cec5SDimitry Andric struct __long 6900b57cec5SDimitry Andric { 6910b57cec5SDimitry Andric pointer __data_; 6920b57cec5SDimitry Andric size_type __size_; 69381ad6265SDimitry Andric size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; 69481ad6265SDimitry Andric size_type __is_long_ : 1; 6950b57cec5SDimitry Andric }; 6960b57cec5SDimitry Andric 6970b57cec5SDimitry Andric enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? 6980b57cec5SDimitry Andric (sizeof(__long) - 1)/sizeof(value_type) : 2}; 6990b57cec5SDimitry Andric 7000b57cec5SDimitry Andric struct __short 7010b57cec5SDimitry Andric { 7020b57cec5SDimitry Andric value_type __data_[__min_cap]; 70381ad6265SDimitry Andric unsigned char __padding_[sizeof(value_type) - 1]; 70481ad6265SDimitry Andric unsigned char __size_ : 7; 70581ad6265SDimitry Andric unsigned char __is_long_ : 1; 7060b57cec5SDimitry Andric }; 7070b57cec5SDimitry Andric 70881ad6265SDimitry Andric// The __endian_factor is required because the field we use to store the size 70981ad6265SDimitry Andric// has one fewer bit than it would if it were not a bitfield. 71081ad6265SDimitry Andric// 71181ad6265SDimitry Andric// If the LSB is used to store the short-flag in the short string representation, 71281ad6265SDimitry Andric// we have to multiply the size by two when it is stored and divide it by two when 71381ad6265SDimitry Andric// it is loaded to make sure that we always store an even number. In the long string 71481ad6265SDimitry Andric// representation, we can ignore this because we can assume that we always allocate 71581ad6265SDimitry Andric// an even amount of value_types. 71681ad6265SDimitry Andric// 71781ad6265SDimitry Andric// If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2. 71881ad6265SDimitry Andric// This does not impact the short string representation, since we never need the MSB 71981ad6265SDimitry Andric// for representing the size of a short string anyway. 72081ad6265SDimitry Andric 72181ad6265SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN 72281ad6265SDimitry Andric static const size_type __endian_factor = 2; 7230b57cec5SDimitry Andric#else 72481ad6265SDimitry Andric static const size_type __endian_factor = 1; 72581ad6265SDimitry Andric#endif 7260b57cec5SDimitry Andric 72781ad6265SDimitry Andric#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 72881ad6265SDimitry Andric 72981ad6265SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN 73081ad6265SDimitry Andric static const size_type __endian_factor = 1; 73181ad6265SDimitry Andric#else 73281ad6265SDimitry Andric static const size_type __endian_factor = 2; 73381ad6265SDimitry Andric#endif 73481ad6265SDimitry Andric 73581ad6265SDimitry Andric // Attribute 'packed' is used to keep the layout compatible with the 73681ad6265SDimitry Andric // previous definition that did not use bit fields. This is because on 73781ad6265SDimitry Andric // some platforms bit fields have a default size rather than the actual 73881ad6265SDimitry Andric // size used, e.g., it is 4 bytes on AIX. See D128285 for details. 7390b57cec5SDimitry Andric struct __long 7400b57cec5SDimitry Andric { 74181ad6265SDimitry Andric struct _LIBCPP_PACKED { 74281ad6265SDimitry Andric size_type __is_long_ : 1; 74381ad6265SDimitry Andric size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; 74481ad6265SDimitry Andric }; 7450b57cec5SDimitry Andric size_type __size_; 7460b57cec5SDimitry Andric pointer __data_; 7470b57cec5SDimitry Andric }; 7480b57cec5SDimitry Andric 7490b57cec5SDimitry Andric enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? 7500b57cec5SDimitry Andric (sizeof(__long) - 1)/sizeof(value_type) : 2}; 7510b57cec5SDimitry Andric 7520b57cec5SDimitry Andric struct __short 7530b57cec5SDimitry Andric { 75481ad6265SDimitry Andric struct _LIBCPP_PACKED { 75581ad6265SDimitry Andric unsigned char __is_long_ : 1; 75681ad6265SDimitry Andric unsigned char __size_ : 7; 7570b57cec5SDimitry Andric }; 75881ad6265SDimitry Andric char __padding_[sizeof(value_type) - 1]; 7590b57cec5SDimitry Andric value_type __data_[__min_cap]; 7600b57cec5SDimitry Andric }; 7610b57cec5SDimitry Andric 7620b57cec5SDimitry Andric#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 7630b57cec5SDimitry Andric 76481ad6265SDimitry Andric static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size."); 76581ad6265SDimitry Andric 7660b57cec5SDimitry Andric union __ulx{__long __lx; __short __lxx;}; 7670b57cec5SDimitry Andric 7680b57cec5SDimitry Andric enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; 7690b57cec5SDimitry Andric 7700b57cec5SDimitry Andric struct __raw 7710b57cec5SDimitry Andric { 7720b57cec5SDimitry Andric size_type __words[__n_words]; 7730b57cec5SDimitry Andric }; 7740b57cec5SDimitry Andric 7750b57cec5SDimitry Andric struct __rep 7760b57cec5SDimitry Andric { 7770b57cec5SDimitry Andric union 7780b57cec5SDimitry Andric { 7790b57cec5SDimitry Andric __long __l; 7800b57cec5SDimitry Andric __short __s; 7810b57cec5SDimitry Andric __raw __r; 7820b57cec5SDimitry Andric }; 7830b57cec5SDimitry Andric }; 7840b57cec5SDimitry Andric 7850b57cec5SDimitry Andric __compressed_pair<__rep, allocator_type> __r_; 7860b57cec5SDimitry Andric 78781ad6265SDimitry Andric // Construct a string with the given allocator and enough storage to hold `__size` characters, but 78881ad6265SDimitry Andric // don't initialize the characters. The contents of the string, including the null terminator, must be 78981ad6265SDimitry Andric // initialized separately. 79081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 79181ad6265SDimitry Andric explicit basic_string(__uninitialized_size_tag, size_type __size, const allocator_type& __a) 79281ad6265SDimitry Andric : __r_(__default_init_tag(), __a) { 79381ad6265SDimitry Andric if (__size > max_size()) 79481ad6265SDimitry Andric __throw_length_error(); 79581ad6265SDimitry Andric if (__fits_in_sso(__size)) { 79681ad6265SDimitry Andric __zero(); 79781ad6265SDimitry Andric __set_short_size(__size); 79881ad6265SDimitry Andric } else { 79981ad6265SDimitry Andric auto __capacity = __recommend(__size) + 1; 80081ad6265SDimitry Andric auto __allocation = __alloc_traits::allocate(__alloc(), __capacity); 80181ad6265SDimitry Andric __begin_lifetime(__allocation, __capacity); 80281ad6265SDimitry Andric __set_long_cap(__capacity); 80381ad6265SDimitry Andric __set_long_pointer(__allocation); 80481ad6265SDimitry Andric __set_long_size(__size); 80581ad6265SDimitry Andric } 80681ad6265SDimitry Andric std::__debug_db_insert_c(this); 80781ad6265SDimitry Andric } 80881ad6265SDimitry Andric 8090b57cec5SDimitry Andricpublic: 810fe6060f1SDimitry Andric _LIBCPP_TEMPLATE_DATA_VIS 8110b57cec5SDimitry Andric static const size_type npos = -1; 8120b57cec5SDimitry Andric 81381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string() 8140b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); 8150b57cec5SDimitry Andric 81681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit basic_string(const allocator_type& __a) 8170b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 8180b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); 8190b57cec5SDimitry Andric#else 8200b57cec5SDimitry Andric _NOEXCEPT; 8210b57cec5SDimitry Andric#endif 8220b57cec5SDimitry Andric 82381ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str); 82481ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str, const allocator_type& __a); 8250b57cec5SDimitry Andric 8260b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 82781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8280b57cec5SDimitry Andric basic_string(basic_string&& __str) 8290b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 8300b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); 8310b57cec5SDimitry Andric#else 8320b57cec5SDimitry Andric _NOEXCEPT; 8330b57cec5SDimitry Andric#endif 8340b57cec5SDimitry Andric 83581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8360b57cec5SDimitry Andric basic_string(basic_string&& __str, const allocator_type& __a); 8370b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 8380b57cec5SDimitry Andric 839349cc55cSDimitry Andric template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > 84081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 841480093f4SDimitry Andric basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) { 8420b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); 8430b57cec5SDimitry Andric __init(__s, traits_type::length(__s)); 84481ad6265SDimitry Andric std::__debug_db_insert_c(this); 8450b57cec5SDimitry Andric } 8460b57cec5SDimitry Andric 847349cc55cSDimitry Andric template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > 84881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8490b57cec5SDimitry Andric basic_string(const _CharT* __s, const _Allocator& __a); 8500b57cec5SDimitry Andric 851fe6060f1SDimitry Andric#if _LIBCPP_STD_VER > 20 852fe6060f1SDimitry Andric basic_string(nullptr_t) = delete; 853fe6060f1SDimitry Andric#endif 854fe6060f1SDimitry Andric 85581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8560b57cec5SDimitry Andric basic_string(const _CharT* __s, size_type __n); 85781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8580b57cec5SDimitry Andric basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); 85981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8600b57cec5SDimitry Andric basic_string(size_type __n, _CharT __c); 8610b57cec5SDimitry Andric 862349cc55cSDimitry Andric template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > 86381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8640b57cec5SDimitry Andric basic_string(size_type __n, _CharT __c, const _Allocator& __a); 8650b57cec5SDimitry Andric 86681ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 8670b57cec5SDimitry Andric basic_string(const basic_string& __str, size_type __pos, size_type __n, 8680b57cec5SDimitry Andric const _Allocator& __a = _Allocator()); 86981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8700b57cec5SDimitry Andric basic_string(const basic_string& __str, size_type __pos, 8710b57cec5SDimitry Andric const _Allocator& __a = _Allocator()); 8720b57cec5SDimitry Andric 873349cc55cSDimitry Andric template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> > 87481ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 8750b57cec5SDimitry Andric basic_string(const _Tp& __t, size_type __pos, size_type __n, 8760b57cec5SDimitry Andric const allocator_type& __a = allocator_type()); 8770b57cec5SDimitry Andric 878349cc55cSDimitry Andric template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 8795ffd83dbSDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value> > 88081ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 8810b57cec5SDimitry Andric explicit basic_string(const _Tp& __t); 8820b57cec5SDimitry Andric 883349cc55cSDimitry Andric template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> > 88481ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 8850b57cec5SDimitry Andric explicit basic_string(const _Tp& __t, const allocator_type& __a); 8860b57cec5SDimitry Andric 887349cc55cSDimitry Andric template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > 88881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8890b57cec5SDimitry Andric basic_string(_InputIterator __first, _InputIterator __last); 890349cc55cSDimitry Andric template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > 89181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8920b57cec5SDimitry Andric basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); 8930b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 89481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8950b57cec5SDimitry Andric basic_string(initializer_list<_CharT> __il); 89681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 8970b57cec5SDimitry Andric basic_string(initializer_list<_CharT> __il, const _Allocator& __a); 8980b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 8990b57cec5SDimitry Andric 90081ad6265SDimitry Andric inline _LIBCPP_CONSTEXPR_AFTER_CXX17 ~basic_string(); 9010b57cec5SDimitry Andric 90281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9030b57cec5SDimitry Andric operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } 9040b57cec5SDimitry Andric 90581ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const basic_string& __str); 9060b57cec5SDimitry Andric 90781ad6265SDimitry Andric template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 90881ad6265SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value> > 90981ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const _Tp& __t) { 91081ad6265SDimitry Andric __self_view __sv = __t; 91181ad6265SDimitry Andric return assign(__sv); 91281ad6265SDimitry Andric } 9130b57cec5SDimitry Andric 9140b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 91581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9160b57cec5SDimitry Andric basic_string& operator=(basic_string&& __str) 9170b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); 91881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9190b57cec5SDimitry Andric basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} 9200b57cec5SDimitry Andric#endif 92181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 92281ad6265SDimitry Andric basic_string& operator=(const value_type* __s) {return assign(__s);} 923fe6060f1SDimitry Andric#if _LIBCPP_STD_VER > 20 924fe6060f1SDimitry Andric basic_string& operator=(nullptr_t) = delete; 925fe6060f1SDimitry Andric#endif 92681ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(value_type __c); 9270b57cec5SDimitry Andric 92881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9290b57cec5SDimitry Andric iterator begin() _NOEXCEPT 9300b57cec5SDimitry Andric {return iterator(this, __get_pointer());} 93181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9320b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT 9330b57cec5SDimitry Andric {return const_iterator(this, __get_pointer());} 93481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9350b57cec5SDimitry Andric iterator end() _NOEXCEPT 9360b57cec5SDimitry Andric {return iterator(this, __get_pointer() + size());} 93781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9380b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT 9390b57cec5SDimitry Andric {return const_iterator(this, __get_pointer() + size());} 94081ad6265SDimitry Andric 94181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9420b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 9430b57cec5SDimitry Andric {return reverse_iterator(end());} 94481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9450b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 9460b57cec5SDimitry Andric {return const_reverse_iterator(end());} 94781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9480b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 9490b57cec5SDimitry Andric {return reverse_iterator(begin());} 95081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9510b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 9520b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 9530b57cec5SDimitry Andric 95481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9550b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 9560b57cec5SDimitry Andric {return begin();} 95781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9580b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 9590b57cec5SDimitry Andric {return end();} 96081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9610b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 9620b57cec5SDimitry Andric {return rbegin();} 96381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9640b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 9650b57cec5SDimitry Andric {return rend();} 9660b57cec5SDimitry Andric 96781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type size() const _NOEXCEPT 9680b57cec5SDimitry Andric {return __is_long() ? __get_long_size() : __get_short_size();} 96981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type length() const _NOEXCEPT {return size();} 97081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT; 97181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type capacity() const _NOEXCEPT { 97281ad6265SDimitry Andric return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1; 97381ad6265SDimitry Andric } 9740b57cec5SDimitry Andric 97581ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n, value_type __c); 97681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n) { resize(__n, value_type()); } 9770b57cec5SDimitry Andric 97881ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __requested_capacity); 97904eeddc0SDimitry Andric 98004eeddc0SDimitry Andric#if _LIBCPP_STD_VER > 20 98104eeddc0SDimitry Andric template <class _Op> 98204eeddc0SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 98304eeddc0SDimitry Andric void resize_and_overwrite(size_type __n, _Op __op) { 98404eeddc0SDimitry Andric __resize_default_init(__n); 98581ad6265SDimitry Andric __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n))); 98604eeddc0SDimitry Andric } 98704eeddc0SDimitry Andric#endif 98804eeddc0SDimitry Andric 98981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __resize_default_init(size_type __n); 9900b57cec5SDimitry Andric 99181ad6265SDimitry Andric _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); } 99281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT; 99381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void clear() _NOEXCEPT; 99481ad6265SDimitry Andric 99581ad6265SDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 9960b57cec5SDimitry Andric bool empty() const _NOEXCEPT {return size() == 0;} 9970b57cec5SDimitry Andric 99881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 99981ad6265SDimitry Andric const_reference operator[](size_type __pos) const _NOEXCEPT; 100081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](size_type __pos) _NOEXCEPT; 10010b57cec5SDimitry Andric 100281ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference at(size_type __n) const; 100381ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 reference at(size_type __n); 10040b57cec5SDimitry Andric 100581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const basic_string& __str) { 100681ad6265SDimitry Andric return append(__str); 100781ad6265SDimitry Andric } 10080b57cec5SDimitry Andric 10090b57cec5SDimitry Andric template <class _Tp> 101081ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1011349cc55cSDimitry Andric __enable_if_t 10120b57cec5SDimitry Andric < 10135ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value 10145ffd83dbSDimitry Andric && !__is_same_uncvref<_Tp, basic_string >::value, 10150b57cec5SDimitry Andric basic_string& 10165ffd83dbSDimitry Andric > 101781ad6265SDimitry Andric operator+=(const _Tp& __t) { 101881ad6265SDimitry Andric __self_view __sv = __t; return append(__sv); 101981ad6265SDimitry Andric } 102081ad6265SDimitry Andric 102181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const value_type* __s) { 102281ad6265SDimitry Andric return append(__s); 102381ad6265SDimitry Andric } 102481ad6265SDimitry Andric 102581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(value_type __c) { 102681ad6265SDimitry Andric push_back(__c); 102781ad6265SDimitry Andric return *this; 102881ad6265SDimitry Andric } 102981ad6265SDimitry Andric 10300b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 103181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 103281ad6265SDimitry Andric basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); } 10330b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 10340b57cec5SDimitry Andric 103581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 10360b57cec5SDimitry Andric basic_string& append(const basic_string& __str); 10370b57cec5SDimitry Andric 10380b57cec5SDimitry Andric template <class _Tp> 103981ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1040349cc55cSDimitry Andric __enable_if_t< 10415ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value 10425ffd83dbSDimitry Andric && !__is_same_uncvref<_Tp, basic_string>::value, 10430b57cec5SDimitry Andric basic_string& 10445ffd83dbSDimitry Andric > 10450b57cec5SDimitry Andric append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); } 104681ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos); 10470b57cec5SDimitry Andric 10480b57cec5SDimitry Andric template <class _Tp> 104981ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1050349cc55cSDimitry Andric __enable_if_t 10510b57cec5SDimitry Andric < 10525ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value 10535ffd83dbSDimitry Andric && !__is_same_uncvref<_Tp, basic_string>::value, 10540b57cec5SDimitry Andric basic_string& 10555ffd83dbSDimitry Andric > 10560b57cec5SDimitry Andric append(const _Tp& __t, size_type __pos, size_type __n=npos); 105781ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s, size_type __n); 105881ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s); 105981ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(size_type __n, value_type __c); 10600b57cec5SDimitry Andric 106181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 10620b57cec5SDimitry Andric void __append_default_init(size_type __n); 10630b57cec5SDimitry Andric 10640b57cec5SDimitry Andric template<class _InputIterator> 10650b57cec5SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 1066349cc55cSDimitry Andric __enable_if_t 10670b57cec5SDimitry Andric < 1068fe6060f1SDimitry Andric __is_exactly_cpp17_input_iterator<_InputIterator>::value, 10690b57cec5SDimitry Andric basic_string& 10705ffd83dbSDimitry Andric > 107181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 10720b57cec5SDimitry Andric append(_InputIterator __first, _InputIterator __last) { 10730b57cec5SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 10740b57cec5SDimitry Andric append(__temp.data(), __temp.size()); 10750b57cec5SDimitry Andric return *this; 10760b57cec5SDimitry Andric } 10770b57cec5SDimitry Andric template<class _ForwardIterator> 10780b57cec5SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS 1079349cc55cSDimitry Andric __enable_if_t 10800b57cec5SDimitry Andric < 1081fe6060f1SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 10820b57cec5SDimitry Andric basic_string& 10835ffd83dbSDimitry Andric > 108481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 1085fe6060f1SDimitry Andric append(_ForwardIterator __first, _ForwardIterator __last); 10860b57cec5SDimitry Andric 10870b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 108881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 10890b57cec5SDimitry Andric basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} 10900b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 10910b57cec5SDimitry Andric 109281ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(value_type __c); 109381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void pop_back(); 109481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 reference front() _NOEXCEPT; 109581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference front() const _NOEXCEPT; 109681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 reference back() _NOEXCEPT; 109781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference back() const _NOEXCEPT; 10980b57cec5SDimitry Andric 10990b57cec5SDimitry Andric template <class _Tp> 110081ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1101349cc55cSDimitry Andric __enable_if_t 11020b57cec5SDimitry Andric < 11030b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 11040b57cec5SDimitry Andric basic_string& 11055ffd83dbSDimitry Andric > 11060b57cec5SDimitry Andric assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); } 110781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 11080b57cec5SDimitry Andric basic_string& assign(const basic_string& __str) { return *this = __str; } 11090b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 111081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 11110b57cec5SDimitry Andric basic_string& assign(basic_string&& __str) 11120b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 111381ad6265SDimitry Andric {*this = std::move(__str); return *this;} 11140b57cec5SDimitry Andric#endif 111581ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); 11160b57cec5SDimitry Andric template <class _Tp> 111781ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1118349cc55cSDimitry Andric __enable_if_t 11190b57cec5SDimitry Andric < 11205ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value 11215ffd83dbSDimitry Andric && !__is_same_uncvref<_Tp, basic_string>::value, 11220b57cec5SDimitry Andric basic_string& 11235ffd83dbSDimitry Andric > 11240b57cec5SDimitry Andric assign(const _Tp & __t, size_type __pos, size_type __n=npos); 112581ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s, size_type __n); 112681ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s); 112781ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(size_type __n, value_type __c); 11280b57cec5SDimitry Andric template<class _InputIterator> 112981ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1130349cc55cSDimitry Andric __enable_if_t 11310b57cec5SDimitry Andric < 1132fe6060f1SDimitry Andric __is_exactly_cpp17_input_iterator<_InputIterator>::value, 11330b57cec5SDimitry Andric basic_string& 11345ffd83dbSDimitry Andric > 11350b57cec5SDimitry Andric assign(_InputIterator __first, _InputIterator __last); 11360b57cec5SDimitry Andric template<class _ForwardIterator> 113781ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1138349cc55cSDimitry Andric __enable_if_t 11390b57cec5SDimitry Andric < 1140fe6060f1SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 11410b57cec5SDimitry Andric basic_string& 11425ffd83dbSDimitry Andric > 11430b57cec5SDimitry Andric assign(_ForwardIterator __first, _ForwardIterator __last); 11440b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 114581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 11460b57cec5SDimitry Andric basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} 11470b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 11480b57cec5SDimitry Andric 114981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 11500b57cec5SDimitry Andric basic_string& insert(size_type __pos1, const basic_string& __str); 11510b57cec5SDimitry Andric 11520b57cec5SDimitry Andric template <class _Tp> 115381ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1154349cc55cSDimitry Andric __enable_if_t 11550b57cec5SDimitry Andric < 11560b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 11570b57cec5SDimitry Andric basic_string& 11585ffd83dbSDimitry Andric > 11590b57cec5SDimitry Andric insert(size_type __pos1, const _Tp& __t) 11600b57cec5SDimitry Andric { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); } 11610b57cec5SDimitry Andric 11620b57cec5SDimitry Andric template <class _Tp> 116381ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1164349cc55cSDimitry Andric __enable_if_t 11650b57cec5SDimitry Andric < 11665ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value, 11670b57cec5SDimitry Andric basic_string& 11685ffd83dbSDimitry Andric > 11690b57cec5SDimitry Andric insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos); 117081ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 11710b57cec5SDimitry Andric basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos); 117281ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s, size_type __n); 117381ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s); 117481ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, size_type __n, value_type __c); 117581ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __pos, value_type __c); 117681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 11770b57cec5SDimitry Andric iterator insert(const_iterator __pos, size_type __n, value_type __c); 11780b57cec5SDimitry Andric template<class _InputIterator> 117981ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1180349cc55cSDimitry Andric __enable_if_t 11810b57cec5SDimitry Andric < 1182fe6060f1SDimitry Andric __is_exactly_cpp17_input_iterator<_InputIterator>::value, 11830b57cec5SDimitry Andric iterator 11845ffd83dbSDimitry Andric > 11850b57cec5SDimitry Andric insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); 11860b57cec5SDimitry Andric template<class _ForwardIterator> 118781ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1188349cc55cSDimitry Andric __enable_if_t 11890b57cec5SDimitry Andric < 1190fe6060f1SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 11910b57cec5SDimitry Andric iterator 11925ffd83dbSDimitry Andric > 11930b57cec5SDimitry Andric insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); 11940b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 119581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 11960b57cec5SDimitry Andric iterator insert(const_iterator __pos, initializer_list<value_type> __il) 11970b57cec5SDimitry Andric {return insert(__pos, __il.begin(), __il.end());} 11980b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 11990b57cec5SDimitry Andric 120081ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& erase(size_type __pos = 0, size_type __n = npos); 120181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12020b57cec5SDimitry Andric iterator erase(const_iterator __pos); 120381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12040b57cec5SDimitry Andric iterator erase(const_iterator __first, const_iterator __last); 12050b57cec5SDimitry Andric 120681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12070b57cec5SDimitry Andric basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); 12080b57cec5SDimitry Andric 12090b57cec5SDimitry Andric template <class _Tp> 121081ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1211349cc55cSDimitry Andric __enable_if_t 12120b57cec5SDimitry Andric < 12130b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 12140b57cec5SDimitry Andric basic_string& 12155ffd83dbSDimitry Andric > 12160b57cec5SDimitry Andric replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); } 121781ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 12180b57cec5SDimitry Andric basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos); 12190b57cec5SDimitry Andric template <class _Tp> 122081ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1221349cc55cSDimitry Andric __enable_if_t 12220b57cec5SDimitry Andric < 12235ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value, 12240b57cec5SDimitry Andric basic_string& 12255ffd83dbSDimitry Andric > 12260b57cec5SDimitry Andric replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos); 122781ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 12280b57cec5SDimitry Andric basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2); 122981ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); 123081ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); 123181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12320b57cec5SDimitry Andric basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str); 12330b57cec5SDimitry Andric 12340b57cec5SDimitry Andric template <class _Tp> 123581ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1236349cc55cSDimitry Andric __enable_if_t 12370b57cec5SDimitry Andric < 12380b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 12390b57cec5SDimitry Andric basic_string& 12405ffd83dbSDimitry Andric > 12410b57cec5SDimitry Andric replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); } 12420b57cec5SDimitry Andric 124381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12440b57cec5SDimitry Andric basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n); 124581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12460b57cec5SDimitry Andric basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s); 124781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12480b57cec5SDimitry Andric basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); 12490b57cec5SDimitry Andric template<class _InputIterator> 125081ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1251349cc55cSDimitry Andric __enable_if_t 12520b57cec5SDimitry Andric < 1253480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIterator>::value, 12540b57cec5SDimitry Andric basic_string& 12555ffd83dbSDimitry Andric > 12560b57cec5SDimitry Andric replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); 12570b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 125881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12590b57cec5SDimitry Andric basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) 12600b57cec5SDimitry Andric {return replace(__i1, __i2, __il.begin(), __il.end());} 12610b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 12620b57cec5SDimitry Andric 126381ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; 126481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12650b57cec5SDimitry Andric basic_string substr(size_type __pos = 0, size_type __n = npos) const; 12660b57cec5SDimitry Andric 126781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12680b57cec5SDimitry Andric void swap(basic_string& __str) 12690b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 12700b57cec5SDimitry Andric _NOEXCEPT; 12710b57cec5SDimitry Andric#else 12720b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 12730b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 12740b57cec5SDimitry Andric#endif 12750b57cec5SDimitry Andric 127681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12770b57cec5SDimitry Andric const value_type* c_str() const _NOEXCEPT {return data();} 127881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 127981ad6265SDimitry Andric const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());} 12800b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) 128181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 128281ad6265SDimitry Andric value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());} 12830b57cec5SDimitry Andric#endif 12840b57cec5SDimitry Andric 128581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12860b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT {return __alloc();} 12870b57cec5SDimitry Andric 128881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 12890b57cec5SDimitry Andric size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 12900b57cec5SDimitry Andric 12910b57cec5SDimitry Andric template <class _Tp> 129281ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1293349cc55cSDimitry Andric __enable_if_t 12940b57cec5SDimitry Andric < 12950b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 12960b57cec5SDimitry Andric size_type 12975ffd83dbSDimitry Andric > 1298fe6060f1SDimitry Andric find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; 129981ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 13000b57cec5SDimitry Andric size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 130181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13020b57cec5SDimitry Andric size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; 130381ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; 13040b57cec5SDimitry Andric 130581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13060b57cec5SDimitry Andric size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 13070b57cec5SDimitry Andric 13080b57cec5SDimitry Andric template <class _Tp> 130981ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1310349cc55cSDimitry Andric __enable_if_t 13110b57cec5SDimitry Andric < 13120b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 13130b57cec5SDimitry Andric size_type 13145ffd83dbSDimitry Andric > 1315fe6060f1SDimitry Andric rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; 131681ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 13170b57cec5SDimitry Andric size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 131881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13190b57cec5SDimitry Andric size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; 132081ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; 13210b57cec5SDimitry Andric 132281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13230b57cec5SDimitry Andric size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 13240b57cec5SDimitry Andric 13250b57cec5SDimitry Andric template <class _Tp> 132681ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1327349cc55cSDimitry Andric __enable_if_t 13280b57cec5SDimitry Andric < 13290b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 13300b57cec5SDimitry Andric size_type 13315ffd83dbSDimitry Andric > 1332fe6060f1SDimitry Andric find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; 133381ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 13340b57cec5SDimitry Andric size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 133581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13360b57cec5SDimitry Andric size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; 133781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13380b57cec5SDimitry Andric size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; 13390b57cec5SDimitry Andric 134081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13410b57cec5SDimitry Andric size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 13420b57cec5SDimitry Andric 13430b57cec5SDimitry Andric template <class _Tp> 134481ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1345349cc55cSDimitry Andric __enable_if_t 13460b57cec5SDimitry Andric < 13470b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 13480b57cec5SDimitry Andric size_type 13495ffd83dbSDimitry Andric > 1350fe6060f1SDimitry Andric find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; 135181ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 13520b57cec5SDimitry Andric size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 135381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13540b57cec5SDimitry Andric size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; 135581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13560b57cec5SDimitry Andric size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; 13570b57cec5SDimitry Andric 135881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13590b57cec5SDimitry Andric size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 13600b57cec5SDimitry Andric 13610b57cec5SDimitry Andric template <class _Tp> 136281ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1363349cc55cSDimitry Andric __enable_if_t 13640b57cec5SDimitry Andric < 13650b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 13660b57cec5SDimitry Andric size_type 13675ffd83dbSDimitry Andric > 1368fe6060f1SDimitry Andric find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT; 136981ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 13700b57cec5SDimitry Andric size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 137181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13720b57cec5SDimitry Andric size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; 137381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13740b57cec5SDimitry Andric size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; 13750b57cec5SDimitry Andric 137681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13770b57cec5SDimitry Andric size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 13780b57cec5SDimitry Andric 13790b57cec5SDimitry Andric template <class _Tp> 138081ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1381349cc55cSDimitry Andric __enable_if_t 13820b57cec5SDimitry Andric < 13830b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 13840b57cec5SDimitry Andric size_type 13855ffd83dbSDimitry Andric > 1386fe6060f1SDimitry Andric find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; 138781ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 13880b57cec5SDimitry Andric size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 138981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13900b57cec5SDimitry Andric size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; 139181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13920b57cec5SDimitry Andric size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; 13930b57cec5SDimitry Andric 139481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 13950b57cec5SDimitry Andric int compare(const basic_string& __str) const _NOEXCEPT; 13960b57cec5SDimitry Andric 13970b57cec5SDimitry Andric template <class _Tp> 139881ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1399349cc55cSDimitry Andric __enable_if_t 14000b57cec5SDimitry Andric < 14010b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 14020b57cec5SDimitry Andric int 14035ffd83dbSDimitry Andric > 1404fe6060f1SDimitry Andric compare(const _Tp &__t) const _NOEXCEPT; 14050b57cec5SDimitry Andric 14060b57cec5SDimitry Andric template <class _Tp> 140781ad6265SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 1408349cc55cSDimitry Andric __enable_if_t 14090b57cec5SDimitry Andric < 14100b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 14110b57cec5SDimitry Andric int 14125ffd83dbSDimitry Andric > 14130b57cec5SDimitry Andric compare(size_type __pos1, size_type __n1, const _Tp& __t) const; 14140b57cec5SDimitry Andric 141581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 14160b57cec5SDimitry Andric int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; 141781ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 141881ad6265SDimitry Andric int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, 141981ad6265SDimitry Andric size_type __n2 = npos) const; 14200b57cec5SDimitry Andric 14210b57cec5SDimitry Andric template <class _Tp> 142281ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 1423349cc55cSDimitry Andric __enable_if_t 14240b57cec5SDimitry Andric < 14255ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value, 14260b57cec5SDimitry Andric int 14275ffd83dbSDimitry Andric > 14280b57cec5SDimitry Andric compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const; 142981ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(const value_type* __s) const _NOEXCEPT; 143081ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(size_type __pos1, size_type __n1, const value_type* __s) const; 143181ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 14320b57cec5SDimitry Andric int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const; 14330b57cec5SDimitry Andric 14340b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 143581ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1436349cc55cSDimitry Andric bool starts_with(__self_view __sv) const noexcept 14370b57cec5SDimitry Andric { return __self_view(data(), size()).starts_with(__sv); } 14380b57cec5SDimitry Andric 143981ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1440349cc55cSDimitry Andric bool starts_with(value_type __c) const noexcept 14410b57cec5SDimitry Andric { return !empty() && _Traits::eq(front(), __c); } 14420b57cec5SDimitry Andric 144381ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1444349cc55cSDimitry Andric bool starts_with(const value_type* __s) const noexcept 14450b57cec5SDimitry Andric { return starts_with(__self_view(__s)); } 14460b57cec5SDimitry Andric 144781ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1448349cc55cSDimitry Andric bool ends_with(__self_view __sv) const noexcept 14490b57cec5SDimitry Andric { return __self_view(data(), size()).ends_with( __sv); } 14500b57cec5SDimitry Andric 145181ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1452349cc55cSDimitry Andric bool ends_with(value_type __c) const noexcept 14530b57cec5SDimitry Andric { return !empty() && _Traits::eq(back(), __c); } 14540b57cec5SDimitry Andric 145581ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1456349cc55cSDimitry Andric bool ends_with(const value_type* __s) const noexcept 14570b57cec5SDimitry Andric { return ends_with(__self_view(__s)); } 14580b57cec5SDimitry Andric#endif 14590b57cec5SDimitry Andric 1460e8d8bef9SDimitry Andric#if _LIBCPP_STD_VER > 20 146181ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1462e8d8bef9SDimitry Andric bool contains(__self_view __sv) const noexcept 1463e8d8bef9SDimitry Andric { return __self_view(data(), size()).contains(__sv); } 1464e8d8bef9SDimitry Andric 146581ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1466e8d8bef9SDimitry Andric bool contains(value_type __c) const noexcept 1467e8d8bef9SDimitry Andric { return __self_view(data(), size()).contains(__c); } 1468e8d8bef9SDimitry Andric 146981ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1470e8d8bef9SDimitry Andric bool contains(const value_type* __s) const 1471e8d8bef9SDimitry Andric { return __self_view(data(), size()).contains(__s); } 1472e8d8bef9SDimitry Andric#endif 1473e8d8bef9SDimitry Andric 147481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const; 14750b57cec5SDimitry Andric 147681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __clear_and_shrink() _NOEXCEPT; 14770b57cec5SDimitry Andric 147881ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 14790b57cec5SDimitry Andric 14800b57cec5SDimitry Andric bool __dereferenceable(const const_iterator* __i) const; 14810b57cec5SDimitry Andric bool __decrementable(const const_iterator* __i) const; 14820b57cec5SDimitry Andric bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 14830b57cec5SDimitry Andric bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 14840b57cec5SDimitry Andric 148581ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE 14860b57cec5SDimitry Andric 14870b57cec5SDimitry Andricprivate: 148881ad6265SDimitry Andric template<class _Alloc> 148981ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 149081ad6265SDimitry Andric bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs, 149181ad6265SDimitry Andric const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT; 149281ad6265SDimitry Andric 149381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __shrink_or_extend(size_type __target_capacity); 149481ad6265SDimitry Andric 149581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 149681ad6265SDimitry Andric bool __is_long() const _NOEXCEPT { 149781ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 149881ad6265SDimitry Andric return true; 149981ad6265SDimitry Andric return __r_.first().__s.__is_long_; 150081ad6265SDimitry Andric } 150181ad6265SDimitry Andric 150281ad6265SDimitry Andric static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __begin_lifetime(pointer __begin, size_type __n) { 150381ad6265SDimitry Andric#if _LIBCPP_STD_VER > 17 150481ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 150581ad6265SDimitry Andric for (size_type __i = 0; __i != __n; ++__i) 150681ad6265SDimitry Andric std::construct_at(std::addressof(__begin[__i])); 150781ad6265SDimitry Andric } 150881ad6265SDimitry Andric#else 150981ad6265SDimitry Andric (void)__begin; 151081ad6265SDimitry Andric (void)__n; 151181ad6265SDimitry Andric#endif // _LIBCPP_STD_VER > 17 151281ad6265SDimitry Andric } 151381ad6265SDimitry Andric 151481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __default_init() { 151581ad6265SDimitry Andric __zero(); 151681ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 151781ad6265SDimitry Andric size_type __sz = __recommend(0) + 1; 151881ad6265SDimitry Andric pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); 151981ad6265SDimitry Andric __begin_lifetime(__ptr, __sz); 152081ad6265SDimitry Andric __set_long_pointer(__ptr); 152181ad6265SDimitry Andric __set_long_cap(__sz); 152281ad6265SDimitry Andric __set_long_size(0); 152381ad6265SDimitry Andric } 152481ad6265SDimitry Andric } 152581ad6265SDimitry Andric 152681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __deallocate_constexpr() { 152781ad6265SDimitry Andric if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr) 152881ad6265SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap()); 152981ad6265SDimitry Andric } 153081ad6265SDimitry Andric 153104eeddc0SDimitry Andric _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { 153204eeddc0SDimitry Andric // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly 153304eeddc0SDimitry Andric return !__libcpp_is_constant_evaluated() && (__sz < __min_cap); 153404eeddc0SDimitry Andric } 153504eeddc0SDimitry Andric 153681ad6265SDimitry Andric template <class _ForwardIterator> 153781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 153881ad6265SDimitry Andric iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) { 153981ad6265SDimitry Andric size_type __sz = size(); 154081ad6265SDimitry Andric size_type __cap = capacity(); 154181ad6265SDimitry Andric value_type* __p; 154281ad6265SDimitry Andric if (__cap - __sz >= __n) 154381ad6265SDimitry Andric { 154481ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 154581ad6265SDimitry Andric size_type __n_move = __sz - __ip; 154681ad6265SDimitry Andric if (__n_move != 0) 154781ad6265SDimitry Andric traits_type::move(__p + __ip + __n, __p + __ip, __n_move); 154881ad6265SDimitry Andric } 154981ad6265SDimitry Andric else 155081ad6265SDimitry Andric { 155181ad6265SDimitry Andric __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); 155281ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 155381ad6265SDimitry Andric } 155481ad6265SDimitry Andric __sz += __n; 155581ad6265SDimitry Andric __set_size(__sz); 155681ad6265SDimitry Andric traits_type::assign(__p[__sz], value_type()); 155781ad6265SDimitry Andric for (__p += __ip; __first != __last; ++__p, ++__first) 155881ad6265SDimitry Andric traits_type::assign(*__p, *__first); 15590b57cec5SDimitry Andric 156081ad6265SDimitry Andric return begin() + __ip; 156181ad6265SDimitry Andric } 15620b57cec5SDimitry Andric 156381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); } 156481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); } 15650b57cec5SDimitry Andric 156681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 156781ad6265SDimitry Andric void __set_short_size(size_type __s) _NOEXCEPT { 156881ad6265SDimitry Andric _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity"); 156981ad6265SDimitry Andric __r_.first().__s.__size_ = __s; 157081ad6265SDimitry Andric __r_.first().__s.__is_long_ = false; 157181ad6265SDimitry Andric } 15720b57cec5SDimitry Andric 157381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 157481ad6265SDimitry Andric size_type __get_short_size() const _NOEXCEPT { 157581ad6265SDimitry Andric _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); 157681ad6265SDimitry Andric return __r_.first().__s.__size_; 157781ad6265SDimitry Andric } 15780b57cec5SDimitry Andric 157981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 15800b57cec5SDimitry Andric void __set_long_size(size_type __s) _NOEXCEPT 15810b57cec5SDimitry Andric {__r_.first().__l.__size_ = __s;} 158281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 15830b57cec5SDimitry Andric size_type __get_long_size() const _NOEXCEPT 15840b57cec5SDimitry Andric {return __r_.first().__l.__size_;} 158581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 15860b57cec5SDimitry Andric void __set_size(size_type __s) _NOEXCEPT 15870b57cec5SDimitry Andric {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} 15880b57cec5SDimitry Andric 158981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 159081ad6265SDimitry Andric void __set_long_cap(size_type __s) _NOEXCEPT { 159181ad6265SDimitry Andric __r_.first().__l.__cap_ = __s / __endian_factor; 159281ad6265SDimitry Andric __r_.first().__l.__is_long_ = true; 159381ad6265SDimitry Andric } 15940b57cec5SDimitry Andric 159581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 159681ad6265SDimitry Andric size_type __get_long_cap() const _NOEXCEPT { 159781ad6265SDimitry Andric return __r_.first().__l.__cap_ * __endian_factor; 159881ad6265SDimitry Andric } 159981ad6265SDimitry Andric 160081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16010b57cec5SDimitry Andric void __set_long_pointer(pointer __p) _NOEXCEPT 16020b57cec5SDimitry Andric {__r_.first().__l.__data_ = __p;} 160381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16040b57cec5SDimitry Andric pointer __get_long_pointer() _NOEXCEPT 16050b57cec5SDimitry Andric {return __r_.first().__l.__data_;} 160681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16070b57cec5SDimitry Andric const_pointer __get_long_pointer() const _NOEXCEPT 16080b57cec5SDimitry Andric {return __r_.first().__l.__data_;} 160981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16100b57cec5SDimitry Andric pointer __get_short_pointer() _NOEXCEPT 16110b57cec5SDimitry Andric {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} 161281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16130b57cec5SDimitry Andric const_pointer __get_short_pointer() const _NOEXCEPT 16140b57cec5SDimitry Andric {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} 161581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16160b57cec5SDimitry Andric pointer __get_pointer() _NOEXCEPT 16170b57cec5SDimitry Andric {return __is_long() ? __get_long_pointer() : __get_short_pointer();} 161881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16190b57cec5SDimitry Andric const_pointer __get_pointer() const _NOEXCEPT 16200b57cec5SDimitry Andric {return __is_long() ? __get_long_pointer() : __get_short_pointer();} 16210b57cec5SDimitry Andric 162281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 162381ad6265SDimitry Andric void __zero() _NOEXCEPT { 162481ad6265SDimitry Andric __r_.first() = __rep(); 16250b57cec5SDimitry Andric } 16260b57cec5SDimitry Andric 16270b57cec5SDimitry Andric template <size_type __a> static 162881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16290b57cec5SDimitry Andric size_type __align_it(size_type __s) _NOEXCEPT 16300b57cec5SDimitry Andric {return (__s + (__a-1)) & ~(__a-1);} 16310b57cec5SDimitry Andric enum {__alignment = 16}; 163281ad6265SDimitry Andric static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16330b57cec5SDimitry Andric size_type __recommend(size_type __s) _NOEXCEPT 16340b57cec5SDimitry Andric { 163581ad6265SDimitry Andric if (__s < __min_cap) { 163681ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 163781ad6265SDimitry Andric return static_cast<size_type>(__min_cap); 163881ad6265SDimitry Andric else 163981ad6265SDimitry Andric return static_cast<size_type>(__min_cap) - 1; 164081ad6265SDimitry Andric } 16410b57cec5SDimitry Andric size_type __guess = __align_it<sizeof(value_type) < __alignment ? 16420b57cec5SDimitry Andric __alignment/sizeof(value_type) : 1 > (__s+1) - 1; 16430b57cec5SDimitry Andric if (__guess == __min_cap) ++__guess; 16440b57cec5SDimitry Andric return __guess; 16450b57cec5SDimitry Andric } 16460b57cec5SDimitry Andric 164781ad6265SDimitry Andric inline _LIBCPP_CONSTEXPR_AFTER_CXX17 16480b57cec5SDimitry Andric void __init(const value_type* __s, size_type __sz, size_type __reserve); 164981ad6265SDimitry Andric inline _LIBCPP_CONSTEXPR_AFTER_CXX17 16500b57cec5SDimitry Andric void __init(const value_type* __s, size_type __sz); 165181ad6265SDimitry Andric inline _LIBCPP_CONSTEXPR_AFTER_CXX17 16520b57cec5SDimitry Andric void __init(size_type __n, value_type __c); 16530b57cec5SDimitry Andric 16545ffd83dbSDimitry Andric // Slow path for the (inlined) copy constructor for 'long' strings. 16555ffd83dbSDimitry Andric // Always externally instantiated and not inlined. 16565ffd83dbSDimitry Andric // Requires that __s is zero terminated. 16575ffd83dbSDimitry Andric // The main reason for this function to exist is because for unstable, we 16585ffd83dbSDimitry Andric // want to allow inlining of the copy constructor. However, we don't want 16595ffd83dbSDimitry Andric // to call the __init() functions as those are marked as inline which may 16605ffd83dbSDimitry Andric // result in over-aggressive inlining by the compiler, where our aim is 16615ffd83dbSDimitry Andric // to only inline the fast path code directly in the ctor. 166281ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __init_copy_ctor_external(const value_type* __s, size_type __sz); 16635ffd83dbSDimitry Andric 16640b57cec5SDimitry Andric template <class _InputIterator> 166581ad6265SDimitry Andric inline _LIBCPP_CONSTEXPR_AFTER_CXX17 1666349cc55cSDimitry Andric __enable_if_t 16670b57cec5SDimitry Andric < 16685ffd83dbSDimitry Andric __is_exactly_cpp17_input_iterator<_InputIterator>::value 16695ffd83dbSDimitry Andric > 16700b57cec5SDimitry Andric __init(_InputIterator __first, _InputIterator __last); 16710b57cec5SDimitry Andric 16720b57cec5SDimitry Andric template <class _ForwardIterator> 167381ad6265SDimitry Andric inline _LIBCPP_CONSTEXPR_AFTER_CXX17 1674349cc55cSDimitry Andric __enable_if_t 16750b57cec5SDimitry Andric < 16765ffd83dbSDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value 16775ffd83dbSDimitry Andric > 16780b57cec5SDimitry Andric __init(_ForwardIterator __first, _ForwardIterator __last); 16790b57cec5SDimitry Andric 168081ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 16810b57cec5SDimitry Andric void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 16820b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, size_type __n_add = 0); 168381ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 16840b57cec5SDimitry Andric void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 16850b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, 16860b57cec5SDimitry Andric size_type __n_add, const value_type* __p_new_stuff); 16870b57cec5SDimitry Andric 16885ffd83dbSDimitry Andric // __assign_no_alias is invoked for assignment operations where we 16895ffd83dbSDimitry Andric // have proof that the input does not alias the current instance. 16905ffd83dbSDimitry Andric // For example, operator=(basic_string) performs a 'self' check. 16915ffd83dbSDimitry Andric template <bool __is_short> 169281ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_no_alias(const value_type* __s, size_type __n); 16935ffd83dbSDimitry Andric 169481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 16950b57cec5SDimitry Andric void __erase_to_end(size_type __pos); 16960b57cec5SDimitry Andric 16975ffd83dbSDimitry Andric // __erase_external_with_move is invoked for erase() invocations where 16985ffd83dbSDimitry Andric // `n ~= npos`, likely requiring memory moves on the string data. 169981ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 void __erase_external_with_move(size_type __pos, size_type __n); 17005ffd83dbSDimitry Andric 170181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17020b57cec5SDimitry Andric void __copy_assign_alloc(const basic_string& __str) 17030b57cec5SDimitry Andric {__copy_assign_alloc(__str, integral_constant<bool, 17040b57cec5SDimitry Andric __alloc_traits::propagate_on_container_copy_assignment::value>());} 17050b57cec5SDimitry Andric 170681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17070b57cec5SDimitry Andric void __copy_assign_alloc(const basic_string& __str, true_type) 17080b57cec5SDimitry Andric { 17090b57cec5SDimitry Andric if (__alloc() == __str.__alloc()) 17100b57cec5SDimitry Andric __alloc() = __str.__alloc(); 17110b57cec5SDimitry Andric else 17120b57cec5SDimitry Andric { 17130b57cec5SDimitry Andric if (!__str.__is_long()) 17140b57cec5SDimitry Andric { 17150b57cec5SDimitry Andric __clear_and_shrink(); 17160b57cec5SDimitry Andric __alloc() = __str.__alloc(); 17170b57cec5SDimitry Andric } 17180b57cec5SDimitry Andric else 17190b57cec5SDimitry Andric { 17200b57cec5SDimitry Andric allocator_type __a = __str.__alloc(); 172181ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap()); 172281ad6265SDimitry Andric __begin_lifetime(__allocation.ptr, __allocation.count); 17230b57cec5SDimitry Andric __clear_and_shrink(); 172481ad6265SDimitry Andric __alloc() = std::move(__a); 172581ad6265SDimitry Andric __set_long_pointer(__allocation.ptr); 172681ad6265SDimitry Andric __set_long_cap(__allocation.count); 17270b57cec5SDimitry Andric __set_long_size(__str.size()); 17280b57cec5SDimitry Andric } 17290b57cec5SDimitry Andric } 17300b57cec5SDimitry Andric } 17310b57cec5SDimitry Andric 173281ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17330b57cec5SDimitry Andric void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT 17340b57cec5SDimitry Andric {} 17350b57cec5SDimitry Andric 17360b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 173781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17380b57cec5SDimitry Andric void __move_assign(basic_string& __str, false_type) 17390b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 174081ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17410b57cec5SDimitry Andric void __move_assign(basic_string& __str, true_type) 17420b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 17430b57cec5SDimitry Andric _NOEXCEPT; 17440b57cec5SDimitry Andric#else 17450b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 17460b57cec5SDimitry Andric#endif 17470b57cec5SDimitry Andric#endif 17480b57cec5SDimitry Andric 174981ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17500b57cec5SDimitry Andric void 17510b57cec5SDimitry Andric __move_assign_alloc(basic_string& __str) 17520b57cec5SDimitry Andric _NOEXCEPT_( 17530b57cec5SDimitry Andric !__alloc_traits::propagate_on_container_move_assignment::value || 17540b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 17550b57cec5SDimitry Andric {__move_assign_alloc(__str, integral_constant<bool, 17560b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>());} 17570b57cec5SDimitry Andric 175881ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17590b57cec5SDimitry Andric void __move_assign_alloc(basic_string& __c, true_type) 17600b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 17610b57cec5SDimitry Andric { 176281ad6265SDimitry Andric __alloc() = std::move(__c.__alloc()); 17630b57cec5SDimitry Andric } 17640b57cec5SDimitry Andric 176581ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 17660b57cec5SDimitry Andric void __move_assign_alloc(basic_string&, false_type) 17670b57cec5SDimitry Andric _NOEXCEPT 17680b57cec5SDimitry Andric {} 17690b57cec5SDimitry Andric 177081ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s); 177181ad6265SDimitry Andric _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s, size_type __n); 17725ffd83dbSDimitry Andric 17735ffd83dbSDimitry Andric // Assigns the value in __s, guaranteed to be __n < __min_cap in length. 17745ffd83dbSDimitry Andric inline basic_string& __assign_short(const value_type* __s, size_type __n) { 17755ffd83dbSDimitry Andric pointer __p = __is_long() 17765ffd83dbSDimitry Andric ? (__set_long_size(__n), __get_long_pointer()) 17775ffd83dbSDimitry Andric : (__set_short_size(__n), __get_short_pointer()); 177881ad6265SDimitry Andric traits_type::move(std::__to_address(__p), __s, __n); 17795ffd83dbSDimitry Andric traits_type::assign(__p[__n], value_type()); 17805ffd83dbSDimitry Andric return *this; 17815ffd83dbSDimitry Andric } 17825ffd83dbSDimitry Andric 178381ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 178481ad6265SDimitry Andric basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { 17850eae32dcSDimitry Andric __set_size(__newsz); 17860eae32dcSDimitry Andric __invalidate_iterators_past(__newsz); 17870eae32dcSDimitry Andric traits_type::assign(__p[__newsz], value_type()); 17880eae32dcSDimitry Andric return *this; 17890eae32dcSDimitry Andric } 17900eae32dcSDimitry Andric 179181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __invalidate_iterators_past(size_type); 17920b57cec5SDimitry Andric 1793fe6060f1SDimitry Andric template<class _Tp> 179481ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 1795fe6060f1SDimitry Andric bool __addr_in_range(_Tp&& __t) const { 179681ad6265SDimitry Andric // assume that the ranges overlap, because we can't check during constant evaluation 179781ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 179881ad6265SDimitry Andric return true; 179981ad6265SDimitry Andric const volatile void *__p = std::addressof(__t); 1800fe6060f1SDimitry Andric return data() <= __p && __p <= data() + size(); 1801fe6060f1SDimitry Andric } 1802fe6060f1SDimitry Andric 180369ade1e0SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 180469ade1e0SDimitry Andric void __throw_length_error() const { 180581ad6265SDimitry Andric std::__throw_length_error("basic_string"); 180669ade1e0SDimitry Andric } 180769ade1e0SDimitry Andric 180869ade1e0SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 180969ade1e0SDimitry Andric void __throw_out_of_range() const { 181081ad6265SDimitry Andric std::__throw_out_of_range("basic_string"); 181169ade1e0SDimitry Andric } 181269ade1e0SDimitry Andric 181381ad6265SDimitry Andric friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const basic_string&); 181481ad6265SDimitry Andric friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const value_type*, const basic_string&); 181581ad6265SDimitry Andric friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(value_type, const basic_string&); 181681ad6265SDimitry Andric friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const value_type*); 181781ad6265SDimitry Andric friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, value_type); 18180b57cec5SDimitry Andric}; 18190b57cec5SDimitry Andric 18205ffd83dbSDimitry Andric// These declarations must appear before any functions are implicitly used 18215ffd83dbSDimitry Andric// so that they have the correct visibility specifier. 182281ad6265SDimitry Andric#define _LIBCPP_DECLARE(...) extern template __VA_ARGS__; 18235ffd83dbSDimitry Andric#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 182481ad6265SDimitry Andric _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) 1825349cc55cSDimitry Andric# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 182681ad6265SDimitry Andric _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) 1827349cc55cSDimitry Andric# endif 18285ffd83dbSDimitry Andric#else 182981ad6265SDimitry Andric _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) 1830349cc55cSDimitry Andric# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 183181ad6265SDimitry Andric _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) 18325ffd83dbSDimitry Andric# endif 1833349cc55cSDimitry Andric#endif 183481ad6265SDimitry Andric#undef _LIBCPP_DECLARE 18355ffd83dbSDimitry Andric 18365ffd83dbSDimitry Andric 1837349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 18380b57cec5SDimitry Andrictemplate<class _InputIterator, 1839fe6060f1SDimitry Andric class _CharT = __iter_value_type<_InputIterator>, 18400b57cec5SDimitry Andric class _Allocator = allocator<_CharT>, 1841349cc55cSDimitry Andric class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, 1842349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value> 18430b57cec5SDimitry Andric > 18440b57cec5SDimitry Andricbasic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) 18450b57cec5SDimitry Andric -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; 18460b57cec5SDimitry Andric 18470b57cec5SDimitry Andrictemplate<class _CharT, 18480b57cec5SDimitry Andric class _Traits, 18490b57cec5SDimitry Andric class _Allocator = allocator<_CharT>, 1850349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value> 18510b57cec5SDimitry Andric > 18520b57cec5SDimitry Andricexplicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) 18530b57cec5SDimitry Andric -> basic_string<_CharT, _Traits, _Allocator>; 18540b57cec5SDimitry Andric 18550b57cec5SDimitry Andrictemplate<class _CharT, 18560b57cec5SDimitry Andric class _Traits, 18570b57cec5SDimitry Andric class _Allocator = allocator<_CharT>, 1858349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value>, 18590b57cec5SDimitry Andric class _Sz = typename allocator_traits<_Allocator>::size_type 18600b57cec5SDimitry Andric > 18610b57cec5SDimitry Andricbasic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) 18620b57cec5SDimitry Andric -> basic_string<_CharT, _Traits, _Allocator>; 18630b57cec5SDimitry Andric#endif 18640b57cec5SDimitry Andric 18650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 186681ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 18670b57cec5SDimitry Andricvoid 1868fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) 18690b57cec5SDimitry Andric{ 187081ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 18710eae32dcSDimitry Andric if (!__libcpp_is_constant_evaluated()) { 18720b57cec5SDimitry Andric __c_node* __c = __get_db()->__find_c_and_lock(this); 18730b57cec5SDimitry Andric if (__c) 18740b57cec5SDimitry Andric { 18750b57cec5SDimitry Andric const_pointer __new_last = __get_pointer() + __pos; 18760b57cec5SDimitry Andric for (__i_node** __p = __c->end_; __p != __c->beg_; ) 18770b57cec5SDimitry Andric { 18780b57cec5SDimitry Andric --__p; 18790b57cec5SDimitry Andric const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 18800b57cec5SDimitry Andric if (__i->base() > __new_last) 18810b57cec5SDimitry Andric { 18820b57cec5SDimitry Andric (*__p)->__c_ = nullptr; 18830b57cec5SDimitry Andric if (--__c->end_ != __p) 188481ad6265SDimitry Andric std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 18850b57cec5SDimitry Andric } 18860b57cec5SDimitry Andric } 18870b57cec5SDimitry Andric __get_db()->unlock(); 18880b57cec5SDimitry Andric } 18890eae32dcSDimitry Andric } 1890fe6060f1SDimitry Andric#else 1891fe6060f1SDimitry Andric (void)__pos; 189281ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE 18930b57cec5SDimitry Andric} 18940b57cec5SDimitry Andric 18950b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 189681ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 18970b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string() 18980b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 1899480093f4SDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) 19000b57cec5SDimitry Andric{ 190181ad6265SDimitry Andric std::__debug_db_insert_c(this); 190281ad6265SDimitry Andric __default_init(); 19030b57cec5SDimitry Andric} 19040b57cec5SDimitry Andric 19050b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 190681ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 19070b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) 19080b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 19090b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 19100b57cec5SDimitry Andric#else 19110b57cec5SDimitry Andric _NOEXCEPT 19120b57cec5SDimitry Andric#endif 1913480093f4SDimitry Andric: __r_(__default_init_tag(), __a) 19140b57cec5SDimitry Andric{ 191581ad6265SDimitry Andric std::__debug_db_insert_c(this); 191681ad6265SDimitry Andric __default_init(); 19170b57cec5SDimitry Andric} 19180b57cec5SDimitry Andric 19190b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 192081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 19210b57cec5SDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, 19220b57cec5SDimitry Andric size_type __sz, 19230b57cec5SDimitry Andric size_type __reserve) 19240b57cec5SDimitry Andric{ 192581ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 192681ad6265SDimitry Andric __zero(); 19270b57cec5SDimitry Andric if (__reserve > max_size()) 192804eeddc0SDimitry Andric __throw_length_error(); 19290b57cec5SDimitry Andric pointer __p; 193004eeddc0SDimitry Andric if (__fits_in_sso(__reserve)) 19310b57cec5SDimitry Andric { 19320b57cec5SDimitry Andric __set_short_size(__sz); 19330b57cec5SDimitry Andric __p = __get_short_pointer(); 19340b57cec5SDimitry Andric } 19350b57cec5SDimitry Andric else 19360b57cec5SDimitry Andric { 193781ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1); 193881ad6265SDimitry Andric __p = __allocation.ptr; 193981ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 19400b57cec5SDimitry Andric __set_long_pointer(__p); 194181ad6265SDimitry Andric __set_long_cap(__allocation.count); 19420b57cec5SDimitry Andric __set_long_size(__sz); 19430b57cec5SDimitry Andric } 194481ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __sz); 19450b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 19460b57cec5SDimitry Andric} 19470b57cec5SDimitry Andric 19480b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 194981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 19500b57cec5SDimitry Andricvoid 19510b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) 19520b57cec5SDimitry Andric{ 195381ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 195481ad6265SDimitry Andric __zero(); 19550b57cec5SDimitry Andric if (__sz > max_size()) 195604eeddc0SDimitry Andric __throw_length_error(); 19570b57cec5SDimitry Andric pointer __p; 195804eeddc0SDimitry Andric if (__fits_in_sso(__sz)) 19590b57cec5SDimitry Andric { 19600b57cec5SDimitry Andric __set_short_size(__sz); 19610b57cec5SDimitry Andric __p = __get_short_pointer(); 19620b57cec5SDimitry Andric } 19630b57cec5SDimitry Andric else 19640b57cec5SDimitry Andric { 196581ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); 196681ad6265SDimitry Andric __p = __allocation.ptr; 196781ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 19680b57cec5SDimitry Andric __set_long_pointer(__p); 196981ad6265SDimitry Andric __set_long_cap(__allocation.count); 19700b57cec5SDimitry Andric __set_long_size(__sz); 19710b57cec5SDimitry Andric } 197281ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __sz); 19730b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 19740b57cec5SDimitry Andric} 19750b57cec5SDimitry Andric 19760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 19770b57cec5SDimitry Andrictemplate <class> 197881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 19790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) 1980480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 19810b57cec5SDimitry Andric{ 19820b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); 19830b57cec5SDimitry Andric __init(__s, traits_type::length(__s)); 198481ad6265SDimitry Andric std::__debug_db_insert_c(this); 19850b57cec5SDimitry Andric} 19860b57cec5SDimitry Andric 19870b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 198881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 19890b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) 1990480093f4SDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) 19910b57cec5SDimitry Andric{ 19920b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); 19930b57cec5SDimitry Andric __init(__s, __n); 199481ad6265SDimitry Andric std::__debug_db_insert_c(this); 19950b57cec5SDimitry Andric} 19960b57cec5SDimitry Andric 19970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 199881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 19990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) 2000480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 20010b57cec5SDimitry Andric{ 20020b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); 20030b57cec5SDimitry Andric __init(__s, __n); 200481ad6265SDimitry Andric std::__debug_db_insert_c(this); 20050b57cec5SDimitry Andric} 20060b57cec5SDimitry Andric 20070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 200881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 20090b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) 2010480093f4SDimitry Andric : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) 20110b57cec5SDimitry Andric{ 20120b57cec5SDimitry Andric if (!__str.__is_long()) 20130b57cec5SDimitry Andric __r_.first().__r = __str.__r_.first().__r; 20140b57cec5SDimitry Andric else 201581ad6265SDimitry Andric __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), 20165ffd83dbSDimitry Andric __str.__get_long_size()); 201781ad6265SDimitry Andric std::__debug_db_insert_c(this); 20180b57cec5SDimitry Andric} 20190b57cec5SDimitry Andric 20200b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 202181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 20220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string( 20230b57cec5SDimitry Andric const basic_string& __str, const allocator_type& __a) 2024480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 20250b57cec5SDimitry Andric{ 20260b57cec5SDimitry Andric if (!__str.__is_long()) 20270b57cec5SDimitry Andric __r_.first().__r = __str.__r_.first().__r; 20280b57cec5SDimitry Andric else 202981ad6265SDimitry Andric __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), 20305ffd83dbSDimitry Andric __str.__get_long_size()); 203181ad6265SDimitry Andric std::__debug_db_insert_c(this); 20320b57cec5SDimitry Andric} 20330b57cec5SDimitry Andric 20345ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 203581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 20365ffd83dbSDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( 20375ffd83dbSDimitry Andric const value_type* __s, size_type __sz) { 203881ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 203981ad6265SDimitry Andric __zero(); 20405ffd83dbSDimitry Andric pointer __p; 204104eeddc0SDimitry Andric if (__fits_in_sso(__sz)) { 20425ffd83dbSDimitry Andric __p = __get_short_pointer(); 20435ffd83dbSDimitry Andric __set_short_size(__sz); 20445ffd83dbSDimitry Andric } else { 20455ffd83dbSDimitry Andric if (__sz > max_size()) 204604eeddc0SDimitry Andric __throw_length_error(); 204781ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); 204881ad6265SDimitry Andric __p = __allocation.ptr; 204981ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 20505ffd83dbSDimitry Andric __set_long_pointer(__p); 205181ad6265SDimitry Andric __set_long_cap(__allocation.count); 20525ffd83dbSDimitry Andric __set_long_size(__sz); 20535ffd83dbSDimitry Andric } 205481ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __sz + 1); 20555ffd83dbSDimitry Andric} 20565ffd83dbSDimitry Andric 20570b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 20580b57cec5SDimitry Andric 20590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 206081ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 20610b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) 20620b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 20630b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 20640b57cec5SDimitry Andric#else 20650b57cec5SDimitry Andric _NOEXCEPT 20660b57cec5SDimitry Andric#endif 206781ad6265SDimitry Andric : __r_(std::move(__str.__r_)) 20680b57cec5SDimitry Andric{ 206981ad6265SDimitry Andric __str.__default_init(); 207081ad6265SDimitry Andric std::__debug_db_insert_c(this); 207181ad6265SDimitry Andric if (__is_long()) 207281ad6265SDimitry Andric std::__debug_db_swap(this, &__str); 20730b57cec5SDimitry Andric} 20740b57cec5SDimitry Andric 20750b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 207681ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 20770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) 2078480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 20790b57cec5SDimitry Andric{ 20800b57cec5SDimitry Andric if (__str.__is_long() && __a != __str.__alloc()) // copy, not move 208181ad6265SDimitry Andric __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); 20820b57cec5SDimitry Andric else 20830b57cec5SDimitry Andric { 208481ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 208581ad6265SDimitry Andric __zero(); 208681ad6265SDimitry Andric __r_.first().__l = __str.__r_.first().__l; 208781ad6265SDimitry Andric } else { 20880b57cec5SDimitry Andric __r_.first().__r = __str.__r_.first().__r; 20890b57cec5SDimitry Andric } 209081ad6265SDimitry Andric __str.__default_init(); 209181ad6265SDimitry Andric } 209281ad6265SDimitry Andric std::__debug_db_insert_c(this); 209381ad6265SDimitry Andric if (__is_long()) 209481ad6265SDimitry Andric std::__debug_db_swap(this, &__str); 20950b57cec5SDimitry Andric} 20960b57cec5SDimitry Andric 20970b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 20980b57cec5SDimitry Andric 20990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 210081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 21010b57cec5SDimitry Andricvoid 21020b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) 21030b57cec5SDimitry Andric{ 210481ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 210581ad6265SDimitry Andric __zero(); 21060b57cec5SDimitry Andric if (__n > max_size()) 210704eeddc0SDimitry Andric __throw_length_error(); 21080b57cec5SDimitry Andric pointer __p; 210904eeddc0SDimitry Andric if (__fits_in_sso(__n)) 21100b57cec5SDimitry Andric { 21110b57cec5SDimitry Andric __set_short_size(__n); 21120b57cec5SDimitry Andric __p = __get_short_pointer(); 21130b57cec5SDimitry Andric } 21140b57cec5SDimitry Andric else 21150b57cec5SDimitry Andric { 211681ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1); 211781ad6265SDimitry Andric __p = __allocation.ptr; 211881ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 21190b57cec5SDimitry Andric __set_long_pointer(__p); 212081ad6265SDimitry Andric __set_long_cap(__allocation.count); 21210b57cec5SDimitry Andric __set_long_size(__n); 21220b57cec5SDimitry Andric } 212381ad6265SDimitry Andric traits_type::assign(std::__to_address(__p), __n, __c); 21240b57cec5SDimitry Andric traits_type::assign(__p[__n], value_type()); 21250b57cec5SDimitry Andric} 21260b57cec5SDimitry Andric 21270b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 212881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 21290b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) 2130480093f4SDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) 21310b57cec5SDimitry Andric{ 21320b57cec5SDimitry Andric __init(__n, __c); 213381ad6265SDimitry Andric std::__debug_db_insert_c(this); 21340b57cec5SDimitry Andric} 21350b57cec5SDimitry Andric 21360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 21370b57cec5SDimitry Andrictemplate <class> 213881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 21390b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) 2140480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 21410b57cec5SDimitry Andric{ 21420b57cec5SDimitry Andric __init(__n, __c); 214381ad6265SDimitry Andric std::__debug_db_insert_c(this); 21440b57cec5SDimitry Andric} 21450b57cec5SDimitry Andric 21460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 214781ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 21480b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, 21490b57cec5SDimitry Andric size_type __pos, size_type __n, 21500b57cec5SDimitry Andric const _Allocator& __a) 2151480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 21520b57cec5SDimitry Andric{ 21530b57cec5SDimitry Andric size_type __str_sz = __str.size(); 21540b57cec5SDimitry Andric if (__pos > __str_sz) 215504eeddc0SDimitry Andric __throw_out_of_range(); 215681ad6265SDimitry Andric __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); 215781ad6265SDimitry Andric std::__debug_db_insert_c(this); 21580b57cec5SDimitry Andric} 21590b57cec5SDimitry Andric 21600b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 216181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 21620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, 21630b57cec5SDimitry Andric const _Allocator& __a) 2164480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 21650b57cec5SDimitry Andric{ 21660b57cec5SDimitry Andric size_type __str_sz = __str.size(); 21670b57cec5SDimitry Andric if (__pos > __str_sz) 216804eeddc0SDimitry Andric __throw_out_of_range(); 21690b57cec5SDimitry Andric __init(__str.data() + __pos, __str_sz - __pos); 217081ad6265SDimitry Andric std::__debug_db_insert_c(this); 21710b57cec5SDimitry Andric} 21720b57cec5SDimitry Andric 21730b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 21740b57cec5SDimitry Andrictemplate <class _Tp, class> 217581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 21760b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string( 21770b57cec5SDimitry Andric const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a) 2178480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 21790b57cec5SDimitry Andric{ 21800b57cec5SDimitry Andric __self_view __sv0 = __t; 21810b57cec5SDimitry Andric __self_view __sv = __sv0.substr(__pos, __n); 21820b57cec5SDimitry Andric __init(__sv.data(), __sv.size()); 218381ad6265SDimitry Andric std::__debug_db_insert_c(this); 21840b57cec5SDimitry Andric} 21850b57cec5SDimitry Andric 21860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 21870b57cec5SDimitry Andrictemplate <class _Tp, class> 218881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 21890b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) 2190480093f4SDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) 21910b57cec5SDimitry Andric{ 21920b57cec5SDimitry Andric __self_view __sv = __t; 21930b57cec5SDimitry Andric __init(__sv.data(), __sv.size()); 219481ad6265SDimitry Andric std::__debug_db_insert_c(this); 21950b57cec5SDimitry Andric} 21960b57cec5SDimitry Andric 21970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 21980b57cec5SDimitry Andrictemplate <class _Tp, class> 219981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 22000b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a) 2201480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 22020b57cec5SDimitry Andric{ 22030b57cec5SDimitry Andric __self_view __sv = __t; 22040b57cec5SDimitry Andric __init(__sv.data(), __sv.size()); 220581ad6265SDimitry Andric std::__debug_db_insert_c(this); 22060b57cec5SDimitry Andric} 22070b57cec5SDimitry Andric 22080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 22090b57cec5SDimitry Andrictemplate <class _InputIterator> 221081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2211349cc55cSDimitry Andric__enable_if_t 22120b57cec5SDimitry Andric< 22135ffd83dbSDimitry Andric __is_exactly_cpp17_input_iterator<_InputIterator>::value 22145ffd83dbSDimitry Andric> 22150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) 22160b57cec5SDimitry Andric{ 221781ad6265SDimitry Andric __default_init(); 22180b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 22190b57cec5SDimitry Andric try 22200b57cec5SDimitry Andric { 22210b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 22220b57cec5SDimitry Andric for (; __first != __last; ++__first) 22230b57cec5SDimitry Andric push_back(*__first); 22240b57cec5SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 22250b57cec5SDimitry Andric } 22260b57cec5SDimitry Andric catch (...) 22270b57cec5SDimitry Andric { 22280b57cec5SDimitry Andric if (__is_long()) 22290b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 22300b57cec5SDimitry Andric throw; 22310b57cec5SDimitry Andric } 22320b57cec5SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 22330b57cec5SDimitry Andric} 22340b57cec5SDimitry Andric 22350b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 22360b57cec5SDimitry Andrictemplate <class _ForwardIterator> 223781ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2238349cc55cSDimitry Andric__enable_if_t 22390b57cec5SDimitry Andric< 22405ffd83dbSDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value 22415ffd83dbSDimitry Andric> 22420b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) 22430b57cec5SDimitry Andric{ 224481ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 224581ad6265SDimitry Andric __zero(); 224681ad6265SDimitry Andric size_type __sz = static_cast<size_type>(std::distance(__first, __last)); 22470b57cec5SDimitry Andric if (__sz > max_size()) 224804eeddc0SDimitry Andric __throw_length_error(); 22490b57cec5SDimitry Andric pointer __p; 225004eeddc0SDimitry Andric if (__fits_in_sso(__sz)) 22510b57cec5SDimitry Andric { 22520b57cec5SDimitry Andric __set_short_size(__sz); 22530b57cec5SDimitry Andric __p = __get_short_pointer(); 22540b57cec5SDimitry Andric } 22550b57cec5SDimitry Andric else 22560b57cec5SDimitry Andric { 225781ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); 225881ad6265SDimitry Andric __p = __allocation.ptr; 225981ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 22600b57cec5SDimitry Andric __set_long_pointer(__p); 226181ad6265SDimitry Andric __set_long_cap(__allocation.count); 22620b57cec5SDimitry Andric __set_long_size(__sz); 22630b57cec5SDimitry Andric } 2264fe6060f1SDimitry Andric 2265fe6060f1SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 2266fe6060f1SDimitry Andric try 2267fe6060f1SDimitry Andric { 2268fe6060f1SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 22690b57cec5SDimitry Andric for (; __first != __last; ++__first, (void) ++__p) 22700b57cec5SDimitry Andric traits_type::assign(*__p, *__first); 22710b57cec5SDimitry Andric traits_type::assign(*__p, value_type()); 2272fe6060f1SDimitry Andric#ifndef _LIBCPP_NO_EXCEPTIONS 2273fe6060f1SDimitry Andric } 2274fe6060f1SDimitry Andric catch (...) 2275fe6060f1SDimitry Andric { 2276fe6060f1SDimitry Andric if (__is_long()) 2277fe6060f1SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 2278fe6060f1SDimitry Andric throw; 2279fe6060f1SDimitry Andric } 2280fe6060f1SDimitry Andric#endif // _LIBCPP_NO_EXCEPTIONS 22810b57cec5SDimitry Andric} 22820b57cec5SDimitry Andric 22830b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 22840b57cec5SDimitry Andrictemplate<class _InputIterator, class> 228581ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 22860b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) 2287480093f4SDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) 22880b57cec5SDimitry Andric{ 22890b57cec5SDimitry Andric __init(__first, __last); 229081ad6265SDimitry Andric std::__debug_db_insert_c(this); 22910b57cec5SDimitry Andric} 22920b57cec5SDimitry Andric 22930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 22940b57cec5SDimitry Andrictemplate<class _InputIterator, class> 229581ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 22960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, 22970b57cec5SDimitry Andric const allocator_type& __a) 2298480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 22990b57cec5SDimitry Andric{ 23000b57cec5SDimitry Andric __init(__first, __last); 230181ad6265SDimitry Andric std::__debug_db_insert_c(this); 23020b57cec5SDimitry Andric} 23030b57cec5SDimitry Andric 23040b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 23050b57cec5SDimitry Andric 23060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 230781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 23080b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string( 23090b57cec5SDimitry Andric initializer_list<_CharT> __il) 2310480093f4SDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) 23110b57cec5SDimitry Andric{ 23120b57cec5SDimitry Andric __init(__il.begin(), __il.end()); 231381ad6265SDimitry Andric std::__debug_db_insert_c(this); 23140b57cec5SDimitry Andric} 23150b57cec5SDimitry Andric 23160b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 231781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 23180b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::basic_string( 23190b57cec5SDimitry Andric initializer_list<_CharT> __il, const _Allocator& __a) 2320480093f4SDimitry Andric : __r_(__default_init_tag(), __a) 23210b57cec5SDimitry Andric{ 23220b57cec5SDimitry Andric __init(__il.begin(), __il.end()); 232381ad6265SDimitry Andric std::__debug_db_insert_c(this); 23240b57cec5SDimitry Andric} 23250b57cec5SDimitry Andric 23260b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 23270b57cec5SDimitry Andric 23280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 232981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 23300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::~basic_string() 23310b57cec5SDimitry Andric{ 233281ad6265SDimitry Andric std::__debug_db_erase_c(this); 23330b57cec5SDimitry Andric if (__is_long()) 23340b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 23350b57cec5SDimitry Andric} 23360b57cec5SDimitry Andric 23370b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 233881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 23390b57cec5SDimitry Andricvoid 23400b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace 23410b57cec5SDimitry Andric (size_type __old_cap, size_type __delta_cap, size_type __old_sz, 23420b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff) 23430b57cec5SDimitry Andric{ 23440b57cec5SDimitry Andric size_type __ms = max_size(); 23450b57cec5SDimitry Andric if (__delta_cap > __ms - __old_cap - 1) 234604eeddc0SDimitry Andric __throw_length_error(); 23470b57cec5SDimitry Andric pointer __old_p = __get_pointer(); 23480b57cec5SDimitry Andric size_type __cap = __old_cap < __ms / 2 - __alignment ? 234981ad6265SDimitry Andric __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : 23500b57cec5SDimitry Andric __ms - 1; 235181ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); 235281ad6265SDimitry Andric pointer __p = __allocation.ptr; 235381ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 235481ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 23550b57cec5SDimitry Andric if (__n_copy != 0) 235681ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), 235781ad6265SDimitry Andric std::__to_address(__old_p), __n_copy); 23580b57cec5SDimitry Andric if (__n_add != 0) 235981ad6265SDimitry Andric traits_type::copy(std::__to_address(__p) + __n_copy, __p_new_stuff, __n_add); 23600b57cec5SDimitry Andric size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 23610b57cec5SDimitry Andric if (__sec_cp_sz != 0) 236281ad6265SDimitry Andric traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, 236381ad6265SDimitry Andric std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); 236481ad6265SDimitry Andric if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated()) 23650b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); 23660b57cec5SDimitry Andric __set_long_pointer(__p); 236781ad6265SDimitry Andric __set_long_cap(__allocation.count); 23680b57cec5SDimitry Andric __old_sz = __n_copy + __n_add + __sec_cp_sz; 23690b57cec5SDimitry Andric __set_long_size(__old_sz); 23700b57cec5SDimitry Andric traits_type::assign(__p[__old_sz], value_type()); 23710b57cec5SDimitry Andric} 23720b57cec5SDimitry Andric 23730b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 23740b57cec5SDimitry Andricvoid 237581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 23760b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 23770b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, size_type __n_add) 23780b57cec5SDimitry Andric{ 23790b57cec5SDimitry Andric size_type __ms = max_size(); 23800b57cec5SDimitry Andric if (__delta_cap > __ms - __old_cap) 238104eeddc0SDimitry Andric __throw_length_error(); 23820b57cec5SDimitry Andric pointer __old_p = __get_pointer(); 23830b57cec5SDimitry Andric size_type __cap = __old_cap < __ms / 2 - __alignment ? 238481ad6265SDimitry Andric __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : 23850b57cec5SDimitry Andric __ms - 1; 238681ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); 238781ad6265SDimitry Andric pointer __p = __allocation.ptr; 238881ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 238981ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 23900b57cec5SDimitry Andric if (__n_copy != 0) 239181ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), 239281ad6265SDimitry Andric std::__to_address(__old_p), __n_copy); 23930b57cec5SDimitry Andric size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 23940b57cec5SDimitry Andric if (__sec_cp_sz != 0) 239581ad6265SDimitry Andric traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, 239681ad6265SDimitry Andric std::__to_address(__old_p) + __n_copy + __n_del, 23970b57cec5SDimitry Andric __sec_cp_sz); 239881ad6265SDimitry Andric if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap) 23990b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1); 24000b57cec5SDimitry Andric __set_long_pointer(__p); 240181ad6265SDimitry Andric __set_long_cap(__allocation.count); 24020b57cec5SDimitry Andric} 24030b57cec5SDimitry Andric 24040b57cec5SDimitry Andric// assign 24050b57cec5SDimitry Andric 24060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 24075ffd83dbSDimitry Andrictemplate <bool __is_short> 240881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24090b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24105ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_no_alias( 24115ffd83dbSDimitry Andric const value_type* __s, size_type __n) { 241281ad6265SDimitry Andric size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap(); 24135ffd83dbSDimitry Andric if (__n < __cap) { 24145ffd83dbSDimitry Andric pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer(); 24155ffd83dbSDimitry Andric __is_short ? __set_short_size(__n) : __set_long_size(__n); 241681ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __n); 24175ffd83dbSDimitry Andric traits_type::assign(__p[__n], value_type()); 24185ffd83dbSDimitry Andric __invalidate_iterators_past(__n); 24195ffd83dbSDimitry Andric } else { 24205ffd83dbSDimitry Andric size_type __sz = __is_short ? __get_short_size() : __get_long_size(); 24215ffd83dbSDimitry Andric __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s); 24225ffd83dbSDimitry Andric } 24235ffd83dbSDimitry Andric return *this; 24245ffd83dbSDimitry Andric} 24255ffd83dbSDimitry Andric 24265ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 242781ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24285ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24295ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external( 24305ffd83dbSDimitry Andric const value_type* __s, size_type __n) { 24310b57cec5SDimitry Andric size_type __cap = capacity(); 24325ffd83dbSDimitry Andric if (__cap >= __n) { 243381ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 24340b57cec5SDimitry Andric traits_type::move(__p, __s, __n); 24350eae32dcSDimitry Andric return __null_terminate_at(__p, __n); 24365ffd83dbSDimitry Andric } else { 24370b57cec5SDimitry Andric size_type __sz = size(); 24380b57cec5SDimitry Andric __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); 24390b57cec5SDimitry Andric return *this; 24400b57cec5SDimitry Andric } 24410eae32dcSDimitry Andric} 24420b57cec5SDimitry Andric 24430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 244481ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24450b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24465ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) 24475ffd83dbSDimitry Andric{ 24485ffd83dbSDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); 244904eeddc0SDimitry Andric return (__builtin_constant_p(__n) && __fits_in_sso(__n)) 24505ffd83dbSDimitry Andric ? __assign_short(__s, __n) 24515ffd83dbSDimitry Andric : __assign_external(__s, __n); 24525ffd83dbSDimitry Andric} 24535ffd83dbSDimitry Andric 24545ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 245581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24565ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) 24580b57cec5SDimitry Andric{ 24590b57cec5SDimitry Andric size_type __cap = capacity(); 24600b57cec5SDimitry Andric if (__cap < __n) 24610b57cec5SDimitry Andric { 24620b57cec5SDimitry Andric size_type __sz = size(); 24630b57cec5SDimitry Andric __grow_by(__cap, __n - __cap, __sz, 0, __sz); 24640b57cec5SDimitry Andric } 246581ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 24660b57cec5SDimitry Andric traits_type::assign(__p, __n, __c); 24670eae32dcSDimitry Andric return __null_terminate_at(__p, __n); 24680b57cec5SDimitry Andric} 24690b57cec5SDimitry Andric 24700b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 247181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24720b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) 24740b57cec5SDimitry Andric{ 24750b57cec5SDimitry Andric pointer __p; 24760b57cec5SDimitry Andric if (__is_long()) 24770b57cec5SDimitry Andric { 24780b57cec5SDimitry Andric __p = __get_long_pointer(); 24790b57cec5SDimitry Andric __set_long_size(1); 24800b57cec5SDimitry Andric } 24810b57cec5SDimitry Andric else 24820b57cec5SDimitry Andric { 24830b57cec5SDimitry Andric __p = __get_short_pointer(); 24840b57cec5SDimitry Andric __set_short_size(1); 24850b57cec5SDimitry Andric } 24860b57cec5SDimitry Andric traits_type::assign(*__p, __c); 24870b57cec5SDimitry Andric traits_type::assign(*++__p, value_type()); 24880b57cec5SDimitry Andric __invalidate_iterators_past(1); 24890b57cec5SDimitry Andric return *this; 24900b57cec5SDimitry Andric} 24910b57cec5SDimitry Andric 24920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 249381ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 24940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24950b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) 24960b57cec5SDimitry Andric{ 24975ffd83dbSDimitry Andric if (this != &__str) { 24980b57cec5SDimitry Andric __copy_assign_alloc(__str); 24995ffd83dbSDimitry Andric if (!__is_long()) { 25005ffd83dbSDimitry Andric if (!__str.__is_long()) { 25015ffd83dbSDimitry Andric __r_.first().__r = __str.__r_.first().__r; 25025ffd83dbSDimitry Andric } else { 25035ffd83dbSDimitry Andric return __assign_no_alias<true>(__str.data(), __str.size()); 25045ffd83dbSDimitry Andric } 25055ffd83dbSDimitry Andric } else { 25065ffd83dbSDimitry Andric return __assign_no_alias<false>(__str.data(), __str.size()); 25075ffd83dbSDimitry Andric } 25080b57cec5SDimitry Andric } 25090b57cec5SDimitry Andric return *this; 25100b57cec5SDimitry Andric} 25110b57cec5SDimitry Andric 25120b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 25130b57cec5SDimitry Andric 25140b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 251581ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 25160b57cec5SDimitry Andricvoid 25170b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) 25180b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) 25190b57cec5SDimitry Andric{ 25200b57cec5SDimitry Andric if (__alloc() != __str.__alloc()) 25210b57cec5SDimitry Andric assign(__str); 25220b57cec5SDimitry Andric else 25230b57cec5SDimitry Andric __move_assign(__str, true_type()); 25240b57cec5SDimitry Andric} 25250b57cec5SDimitry Andric 25260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 252781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 25280b57cec5SDimitry Andricvoid 25290b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) 25300b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 25310b57cec5SDimitry Andric _NOEXCEPT 25320b57cec5SDimitry Andric#else 25330b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 25340b57cec5SDimitry Andric#endif 25350b57cec5SDimitry Andric{ 2536480093f4SDimitry Andric if (__is_long()) { 2537480093f4SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), 2538480093f4SDimitry Andric __get_long_cap()); 2539480093f4SDimitry Andric#if _LIBCPP_STD_VER <= 14 2540480093f4SDimitry Andric if (!is_nothrow_move_assignable<allocator_type>::value) { 2541480093f4SDimitry Andric __set_short_size(0); 2542480093f4SDimitry Andric traits_type::assign(__get_short_pointer()[0], value_type()); 2543480093f4SDimitry Andric } 2544480093f4SDimitry Andric#endif 2545480093f4SDimitry Andric } 25460b57cec5SDimitry Andric __move_assign_alloc(__str); 2547480093f4SDimitry Andric __r_.first() = __str.__r_.first(); 254881ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 254981ad6265SDimitry Andric __str.__default_init(); 255081ad6265SDimitry Andric } else { 2551480093f4SDimitry Andric __str.__set_short_size(0); 2552480093f4SDimitry Andric traits_type::assign(__str.__get_short_pointer()[0], value_type()); 25530b57cec5SDimitry Andric } 255481ad6265SDimitry Andric} 25550b57cec5SDimitry Andric 25560b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 255781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 25580b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 25590b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) 25600b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 25610b57cec5SDimitry Andric{ 25620b57cec5SDimitry Andric __move_assign(__str, integral_constant<bool, 25630b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>()); 25640b57cec5SDimitry Andric return *this; 25650b57cec5SDimitry Andric} 25660b57cec5SDimitry Andric 25670b57cec5SDimitry Andric#endif 25680b57cec5SDimitry Andric 25690b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 25700b57cec5SDimitry Andrictemplate<class _InputIterator> 257181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2572349cc55cSDimitry Andric__enable_if_t 25730b57cec5SDimitry Andric< 2574fe6060f1SDimitry Andric __is_exactly_cpp17_input_iterator<_InputIterator>::value, 25750b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 25765ffd83dbSDimitry Andric> 25770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 25780b57cec5SDimitry Andric{ 25790b57cec5SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 25800b57cec5SDimitry Andric assign(__temp.data(), __temp.size()); 25810b57cec5SDimitry Andric return *this; 25820b57cec5SDimitry Andric} 25830b57cec5SDimitry Andric 25840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 25850b57cec5SDimitry Andrictemplate<class _ForwardIterator> 258681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2587349cc55cSDimitry Andric__enable_if_t 25880b57cec5SDimitry Andric< 2589fe6060f1SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 25900b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 25915ffd83dbSDimitry Andric> 25920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 25930b57cec5SDimitry Andric{ 25940b57cec5SDimitry Andric size_type __cap = capacity(); 2595fe6060f1SDimitry Andric size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ? 259681ad6265SDimitry Andric static_cast<size_type>(std::distance(__first, __last)) : 0; 2597fe6060f1SDimitry Andric 2598fe6060f1SDimitry Andric if (__string_is_trivial_iterator<_ForwardIterator>::value && 2599fe6060f1SDimitry Andric (__cap >= __n || !__addr_in_range(*__first))) 2600fe6060f1SDimitry Andric { 26010b57cec5SDimitry Andric if (__cap < __n) 26020b57cec5SDimitry Andric { 26030b57cec5SDimitry Andric size_type __sz = size(); 26040b57cec5SDimitry Andric __grow_by(__cap, __n - __cap, __sz, 0, __sz); 26050b57cec5SDimitry Andric } 26060b57cec5SDimitry Andric pointer __p = __get_pointer(); 2607349cc55cSDimitry Andric for (; __first != __last; ++__p, (void) ++__first) 26080b57cec5SDimitry Andric traits_type::assign(*__p, *__first); 26090b57cec5SDimitry Andric traits_type::assign(*__p, value_type()); 26100b57cec5SDimitry Andric __set_size(__n); 2611fe6060f1SDimitry Andric __invalidate_iterators_past(__n); 2612fe6060f1SDimitry Andric } 2613fe6060f1SDimitry Andric else 2614fe6060f1SDimitry Andric { 2615fe6060f1SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 2616fe6060f1SDimitry Andric assign(__temp.data(), __temp.size()); 2617fe6060f1SDimitry Andric } 26180b57cec5SDimitry Andric return *this; 26190b57cec5SDimitry Andric} 26200b57cec5SDimitry Andric 26210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 262281ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26240b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) 26250b57cec5SDimitry Andric{ 26260b57cec5SDimitry Andric size_type __sz = __str.size(); 26270b57cec5SDimitry Andric if (__pos > __sz) 262804eeddc0SDimitry Andric __throw_out_of_range(); 262981ad6265SDimitry Andric return assign(__str.data() + __pos, std::min(__n, __sz - __pos)); 26300b57cec5SDimitry Andric} 26310b57cec5SDimitry Andric 26320b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 26330b57cec5SDimitry Andrictemplate <class _Tp> 263481ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2635349cc55cSDimitry Andric__enable_if_t 26360b57cec5SDimitry Andric< 26375ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value 26385ffd83dbSDimitry Andric && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 26390b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 26405ffd83dbSDimitry Andric> 26410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n) 26420b57cec5SDimitry Andric{ 26430b57cec5SDimitry Andric __self_view __sv = __t; 26440b57cec5SDimitry Andric size_type __sz = __sv.size(); 26450b57cec5SDimitry Andric if (__pos > __sz) 264604eeddc0SDimitry Andric __throw_out_of_range(); 264781ad6265SDimitry Andric return assign(__sv.data() + __pos, std::min(__n, __sz - __pos)); 26480b57cec5SDimitry Andric} 26490b57cec5SDimitry Andric 26500b57cec5SDimitry Andric 26510b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 265281ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26545ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) { 26555ffd83dbSDimitry Andric return __assign_external(__s, traits_type::length(__s)); 26565ffd83dbSDimitry Andric} 26575ffd83dbSDimitry Andric 26585ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 265981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26605ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26610b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) 26620b57cec5SDimitry Andric{ 26630b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); 2664349cc55cSDimitry Andric return __builtin_constant_p(*__s) 266504eeddc0SDimitry Andric ? (__fits_in_sso(traits_type::length(__s)) 26665ffd83dbSDimitry Andric ? __assign_short(__s, traits_type::length(__s)) 26675ffd83dbSDimitry Andric : __assign_external(__s, traits_type::length(__s))) 26685ffd83dbSDimitry Andric : __assign_external(__s); 26690b57cec5SDimitry Andric} 26700b57cec5SDimitry Andric// append 26710b57cec5SDimitry Andric 26720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 267381ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) 26760b57cec5SDimitry Andric{ 26770b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); 26780b57cec5SDimitry Andric size_type __cap = capacity(); 26790b57cec5SDimitry Andric size_type __sz = size(); 26800b57cec5SDimitry Andric if (__cap - __sz >= __n) 26810b57cec5SDimitry Andric { 26820b57cec5SDimitry Andric if (__n) 26830b57cec5SDimitry Andric { 268481ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 26850b57cec5SDimitry Andric traits_type::copy(__p + __sz, __s, __n); 26860b57cec5SDimitry Andric __sz += __n; 26870b57cec5SDimitry Andric __set_size(__sz); 26880b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 26890b57cec5SDimitry Andric } 26900b57cec5SDimitry Andric } 26910b57cec5SDimitry Andric else 26920b57cec5SDimitry Andric __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); 26930b57cec5SDimitry Andric return *this; 26940b57cec5SDimitry Andric} 26950b57cec5SDimitry Andric 26960b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 269781ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 26980b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) 27000b57cec5SDimitry Andric{ 27010b57cec5SDimitry Andric if (__n) 27020b57cec5SDimitry Andric { 27030b57cec5SDimitry Andric size_type __cap = capacity(); 27040b57cec5SDimitry Andric size_type __sz = size(); 27050b57cec5SDimitry Andric if (__cap - __sz < __n) 27060b57cec5SDimitry Andric __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); 27070b57cec5SDimitry Andric pointer __p = __get_pointer(); 270881ad6265SDimitry Andric traits_type::assign(std::__to_address(__p) + __sz, __n, __c); 27090b57cec5SDimitry Andric __sz += __n; 27100b57cec5SDimitry Andric __set_size(__sz); 27110b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 27120b57cec5SDimitry Andric } 27130b57cec5SDimitry Andric return *this; 27140b57cec5SDimitry Andric} 27150b57cec5SDimitry Andric 27160b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 271781ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 inline void 27180b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) 27190b57cec5SDimitry Andric{ 27200b57cec5SDimitry Andric if (__n) 27210b57cec5SDimitry Andric { 27220b57cec5SDimitry Andric size_type __cap = capacity(); 27230b57cec5SDimitry Andric size_type __sz = size(); 27240b57cec5SDimitry Andric if (__cap - __sz < __n) 27250b57cec5SDimitry Andric __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); 27260b57cec5SDimitry Andric pointer __p = __get_pointer(); 27270b57cec5SDimitry Andric __sz += __n; 27280b57cec5SDimitry Andric __set_size(__sz); 27290b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 27300b57cec5SDimitry Andric } 27310b57cec5SDimitry Andric} 27320b57cec5SDimitry Andric 27330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 273481ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 27350b57cec5SDimitry Andricvoid 27360b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) 27370b57cec5SDimitry Andric{ 27380b57cec5SDimitry Andric bool __is_short = !__is_long(); 27390b57cec5SDimitry Andric size_type __cap; 27400b57cec5SDimitry Andric size_type __sz; 27410b57cec5SDimitry Andric if (__is_short) 27420b57cec5SDimitry Andric { 27430b57cec5SDimitry Andric __cap = __min_cap - 1; 27440b57cec5SDimitry Andric __sz = __get_short_size(); 27450b57cec5SDimitry Andric } 27460b57cec5SDimitry Andric else 27470b57cec5SDimitry Andric { 27480b57cec5SDimitry Andric __cap = __get_long_cap() - 1; 27490b57cec5SDimitry Andric __sz = __get_long_size(); 27500b57cec5SDimitry Andric } 27510b57cec5SDimitry Andric if (__sz == __cap) 27520b57cec5SDimitry Andric { 27530b57cec5SDimitry Andric __grow_by(__cap, 1, __sz, __sz, 0); 2754349cc55cSDimitry Andric __is_short = false; // the string is always long after __grow_by 27550b57cec5SDimitry Andric } 275681ad6265SDimitry Andric pointer __p = __get_pointer(); 27570b57cec5SDimitry Andric if (__is_short) 27580b57cec5SDimitry Andric { 27590b57cec5SDimitry Andric __p = __get_short_pointer() + __sz; 27600b57cec5SDimitry Andric __set_short_size(__sz+1); 27610b57cec5SDimitry Andric } 27620b57cec5SDimitry Andric else 27630b57cec5SDimitry Andric { 27640b57cec5SDimitry Andric __p = __get_long_pointer() + __sz; 27650b57cec5SDimitry Andric __set_long_size(__sz+1); 27660b57cec5SDimitry Andric } 27670b57cec5SDimitry Andric traits_type::assign(*__p, __c); 27680b57cec5SDimitry Andric traits_type::assign(*++__p, value_type()); 27690b57cec5SDimitry Andric} 27700b57cec5SDimitry Andric 27710b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 27720b57cec5SDimitry Andrictemplate<class _ForwardIterator> 277381ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2774349cc55cSDimitry Andric__enable_if_t 2775fe6060f1SDimitry Andric< 2776fe6060f1SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 27770b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 2778fe6060f1SDimitry Andric> 2779fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append( 27800b57cec5SDimitry Andric _ForwardIterator __first, _ForwardIterator __last) 27810b57cec5SDimitry Andric{ 27820b57cec5SDimitry Andric size_type __sz = size(); 27830b57cec5SDimitry Andric size_type __cap = capacity(); 278481ad6265SDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 27850b57cec5SDimitry Andric if (__n) 27860b57cec5SDimitry Andric { 2787fe6060f1SDimitry Andric if (__string_is_trivial_iterator<_ForwardIterator>::value && 2788fe6060f1SDimitry Andric !__addr_in_range(*__first)) 27890b57cec5SDimitry Andric { 27900b57cec5SDimitry Andric if (__cap - __sz < __n) 27910b57cec5SDimitry Andric __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); 27920b57cec5SDimitry Andric pointer __p = __get_pointer() + __sz; 2793349cc55cSDimitry Andric for (; __first != __last; ++__p, (void) ++__first) 27940b57cec5SDimitry Andric traits_type::assign(*__p, *__first); 27950b57cec5SDimitry Andric traits_type::assign(*__p, value_type()); 27960b57cec5SDimitry Andric __set_size(__sz + __n); 27970b57cec5SDimitry Andric } 2798fe6060f1SDimitry Andric else 2799fe6060f1SDimitry Andric { 2800fe6060f1SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 2801fe6060f1SDimitry Andric append(__temp.data(), __temp.size()); 2802fe6060f1SDimitry Andric } 28030b57cec5SDimitry Andric } 28040b57cec5SDimitry Andric return *this; 28050b57cec5SDimitry Andric} 28060b57cec5SDimitry Andric 28070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 280881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 28090b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28100b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) 28110b57cec5SDimitry Andric{ 28120b57cec5SDimitry Andric return append(__str.data(), __str.size()); 28130b57cec5SDimitry Andric} 28140b57cec5SDimitry Andric 28150b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 281681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 28170b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28180b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) 28190b57cec5SDimitry Andric{ 28200b57cec5SDimitry Andric size_type __sz = __str.size(); 28210b57cec5SDimitry Andric if (__pos > __sz) 282204eeddc0SDimitry Andric __throw_out_of_range(); 282381ad6265SDimitry Andric return append(__str.data() + __pos, std::min(__n, __sz - __pos)); 28240b57cec5SDimitry Andric} 28250b57cec5SDimitry Andric 28260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 28270b57cec5SDimitry Andrictemplate <class _Tp> 282881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2829349cc55cSDimitry Andric __enable_if_t 28300b57cec5SDimitry Andric < 28315ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 28320b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 28335ffd83dbSDimitry Andric > 28340b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n) 28350b57cec5SDimitry Andric{ 28360b57cec5SDimitry Andric __self_view __sv = __t; 28370b57cec5SDimitry Andric size_type __sz = __sv.size(); 28380b57cec5SDimitry Andric if (__pos > __sz) 283904eeddc0SDimitry Andric __throw_out_of_range(); 284081ad6265SDimitry Andric return append(__sv.data() + __pos, std::min(__n, __sz - __pos)); 28410b57cec5SDimitry Andric} 28420b57cec5SDimitry Andric 28430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 284481ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 28450b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28460b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) 28470b57cec5SDimitry Andric{ 28480b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); 28490b57cec5SDimitry Andric return append(__s, traits_type::length(__s)); 28500b57cec5SDimitry Andric} 28510b57cec5SDimitry Andric 28520b57cec5SDimitry Andric// insert 28530b57cec5SDimitry Andric 28540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 285581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 28560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) 28580b57cec5SDimitry Andric{ 28590b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); 28600b57cec5SDimitry Andric size_type __sz = size(); 28610b57cec5SDimitry Andric if (__pos > __sz) 286204eeddc0SDimitry Andric __throw_out_of_range(); 28630b57cec5SDimitry Andric size_type __cap = capacity(); 286481ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 286581ad6265SDimitry Andric if (__cap - __sz >= __n) 286681ad6265SDimitry Andric __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s); 286781ad6265SDimitry Andric else 286881ad6265SDimitry Andric __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); 286981ad6265SDimitry Andric return *this; 287081ad6265SDimitry Andric } 28710b57cec5SDimitry Andric if (__cap - __sz >= __n) 28720b57cec5SDimitry Andric { 28730b57cec5SDimitry Andric if (__n) 28740b57cec5SDimitry Andric { 287581ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 28760b57cec5SDimitry Andric size_type __n_move = __sz - __pos; 28770b57cec5SDimitry Andric if (__n_move != 0) 28780b57cec5SDimitry Andric { 28790b57cec5SDimitry Andric if (__p + __pos <= __s && __s < __p + __sz) 28800b57cec5SDimitry Andric __s += __n; 28810b57cec5SDimitry Andric traits_type::move(__p + __pos + __n, __p + __pos, __n_move); 28820b57cec5SDimitry Andric } 28830b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n); 28840b57cec5SDimitry Andric __sz += __n; 28850b57cec5SDimitry Andric __set_size(__sz); 28860b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 28870b57cec5SDimitry Andric } 28880b57cec5SDimitry Andric } 28890b57cec5SDimitry Andric else 28900b57cec5SDimitry Andric __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); 28910b57cec5SDimitry Andric return *this; 28920b57cec5SDimitry Andric} 28930b57cec5SDimitry Andric 28940b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 289581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 28960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28970b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) 28980b57cec5SDimitry Andric{ 28990b57cec5SDimitry Andric size_type __sz = size(); 29000b57cec5SDimitry Andric if (__pos > __sz) 290104eeddc0SDimitry Andric __throw_out_of_range(); 29020b57cec5SDimitry Andric if (__n) 29030b57cec5SDimitry Andric { 29040b57cec5SDimitry Andric size_type __cap = capacity(); 29050b57cec5SDimitry Andric value_type* __p; 29060b57cec5SDimitry Andric if (__cap - __sz >= __n) 29070b57cec5SDimitry Andric { 290881ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 29090b57cec5SDimitry Andric size_type __n_move = __sz - __pos; 29100b57cec5SDimitry Andric if (__n_move != 0) 29110b57cec5SDimitry Andric traits_type::move(__p + __pos + __n, __p + __pos, __n_move); 29120b57cec5SDimitry Andric } 29130b57cec5SDimitry Andric else 29140b57cec5SDimitry Andric { 29150b57cec5SDimitry Andric __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); 291681ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 29170b57cec5SDimitry Andric } 29180b57cec5SDimitry Andric traits_type::assign(__p + __pos, __n, __c); 29190b57cec5SDimitry Andric __sz += __n; 29200b57cec5SDimitry Andric __set_size(__sz); 29210b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 29220b57cec5SDimitry Andric } 29230b57cec5SDimitry Andric return *this; 29240b57cec5SDimitry Andric} 29250b57cec5SDimitry Andric 29260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 29270b57cec5SDimitry Andrictemplate<class _InputIterator> 292881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2929349cc55cSDimitry Andric__enable_if_t 29300b57cec5SDimitry Andric< 2931fe6060f1SDimitry Andric __is_exactly_cpp17_input_iterator<_InputIterator>::value, 29320b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::iterator 29335ffd83dbSDimitry Andric> 29340b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) 29350b57cec5SDimitry Andric{ 29360eae32dcSDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, 29370b57cec5SDimitry Andric "string::insert(iterator, range) called with an iterator not" 29380b57cec5SDimitry Andric " referring to this string"); 29390b57cec5SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 29400b57cec5SDimitry Andric return insert(__pos, __temp.data(), __temp.data() + __temp.size()); 29410b57cec5SDimitry Andric} 29420b57cec5SDimitry Andric 29430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 29440b57cec5SDimitry Andrictemplate<class _ForwardIterator> 294581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2946349cc55cSDimitry Andric__enable_if_t 29470b57cec5SDimitry Andric< 2948fe6060f1SDimitry Andric __is_cpp17_forward_iterator<_ForwardIterator>::value, 29490b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::iterator 29505ffd83dbSDimitry Andric> 29510b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) 29520b57cec5SDimitry Andric{ 29530eae32dcSDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, 295481ad6265SDimitry Andric "string::insert(iterator, range) called with an iterator not referring to this string"); 29550eae32dcSDimitry Andric 29560b57cec5SDimitry Andric size_type __ip = static_cast<size_type>(__pos - begin()); 295781ad6265SDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 295881ad6265SDimitry Andric if (__n == 0) 295981ad6265SDimitry Andric return begin() + __ip; 296081ad6265SDimitry Andric 296181ad6265SDimitry Andric if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) 29620b57cec5SDimitry Andric { 296381ad6265SDimitry Andric return __insert_from_safe_copy(__n, __ip, __first, __last); 29640b57cec5SDimitry Andric } 2965fe6060f1SDimitry Andric else 2966fe6060f1SDimitry Andric { 2967fe6060f1SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 296881ad6265SDimitry Andric return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end()); 2969fe6060f1SDimitry Andric } 2970fe6060f1SDimitry Andric} 29710b57cec5SDimitry Andric 29720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 297381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 29740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 29750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) 29760b57cec5SDimitry Andric{ 29770b57cec5SDimitry Andric return insert(__pos1, __str.data(), __str.size()); 29780b57cec5SDimitry Andric} 29790b57cec5SDimitry Andric 29800b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 298181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 29820b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 29830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, 29840b57cec5SDimitry Andric size_type __pos2, size_type __n) 29850b57cec5SDimitry Andric{ 29860b57cec5SDimitry Andric size_type __str_sz = __str.size(); 29870b57cec5SDimitry Andric if (__pos2 > __str_sz) 298804eeddc0SDimitry Andric __throw_out_of_range(); 298981ad6265SDimitry Andric return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2)); 29900b57cec5SDimitry Andric} 29910b57cec5SDimitry Andric 29920b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 29930b57cec5SDimitry Andrictemplate <class _Tp> 299481ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 2995349cc55cSDimitry Andric__enable_if_t 29960b57cec5SDimitry Andric< 29975ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 29980b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 29995ffd83dbSDimitry Andric> 30000b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, 30010b57cec5SDimitry Andric size_type __pos2, size_type __n) 30020b57cec5SDimitry Andric{ 30030b57cec5SDimitry Andric __self_view __sv = __t; 30040b57cec5SDimitry Andric size_type __str_sz = __sv.size(); 30050b57cec5SDimitry Andric if (__pos2 > __str_sz) 300604eeddc0SDimitry Andric __throw_out_of_range(); 300781ad6265SDimitry Andric return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2)); 30080b57cec5SDimitry Andric} 30090b57cec5SDimitry Andric 30100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 301181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 30120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 30130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) 30140b57cec5SDimitry Andric{ 30150b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); 30160b57cec5SDimitry Andric return insert(__pos, __s, traits_type::length(__s)); 30170b57cec5SDimitry Andric} 30180b57cec5SDimitry Andric 30190b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 302081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 30210b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 30220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) 30230b57cec5SDimitry Andric{ 3024d56accc7SDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, 3025d56accc7SDimitry Andric "string::insert(iterator, character) called with an iterator not" 3026d56accc7SDimitry Andric " referring to this string"); 3027d56accc7SDimitry Andric 30280b57cec5SDimitry Andric size_type __ip = static_cast<size_type>(__pos - begin()); 30290b57cec5SDimitry Andric size_type __sz = size(); 30300b57cec5SDimitry Andric size_type __cap = capacity(); 30310b57cec5SDimitry Andric value_type* __p; 30320b57cec5SDimitry Andric if (__cap == __sz) 30330b57cec5SDimitry Andric { 30340b57cec5SDimitry Andric __grow_by(__cap, 1, __sz, __ip, 0, 1); 303581ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 30360b57cec5SDimitry Andric } 30370b57cec5SDimitry Andric else 30380b57cec5SDimitry Andric { 303981ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 30400b57cec5SDimitry Andric size_type __n_move = __sz - __ip; 30410b57cec5SDimitry Andric if (__n_move != 0) 30420b57cec5SDimitry Andric traits_type::move(__p + __ip + 1, __p + __ip, __n_move); 30430b57cec5SDimitry Andric } 30440b57cec5SDimitry Andric traits_type::assign(__p[__ip], __c); 30450b57cec5SDimitry Andric traits_type::assign(__p[++__sz], value_type()); 30460b57cec5SDimitry Andric __set_size(__sz); 30470b57cec5SDimitry Andric return begin() + static_cast<difference_type>(__ip); 30480b57cec5SDimitry Andric} 30490b57cec5SDimitry Andric 30500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 305181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 30520b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 30530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) 30540b57cec5SDimitry Andric{ 30550eae32dcSDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, 30560b57cec5SDimitry Andric "string::insert(iterator, n, value) called with an iterator not" 30570b57cec5SDimitry Andric " referring to this string"); 30580b57cec5SDimitry Andric difference_type __p = __pos - begin(); 30590b57cec5SDimitry Andric insert(static_cast<size_type>(__p), __n, __c); 30600b57cec5SDimitry Andric return begin() + __p; 30610b57cec5SDimitry Andric} 30620b57cec5SDimitry Andric 30630b57cec5SDimitry Andric// replace 30640b57cec5SDimitry Andric 30650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 306681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 30670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 30680b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) 30690b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 30700b57cec5SDimitry Andric{ 30710b57cec5SDimitry Andric _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); 30720b57cec5SDimitry Andric size_type __sz = size(); 30730b57cec5SDimitry Andric if (__pos > __sz) 307404eeddc0SDimitry Andric __throw_out_of_range(); 307581ad6265SDimitry Andric __n1 = std::min(__n1, __sz - __pos); 30760b57cec5SDimitry Andric size_type __cap = capacity(); 30770b57cec5SDimitry Andric if (__cap - __sz + __n1 >= __n2) 30780b57cec5SDimitry Andric { 307981ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 308081ad6265SDimitry Andric __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s); 308181ad6265SDimitry Andric return *this; 308281ad6265SDimitry Andric } 308381ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 30840b57cec5SDimitry Andric if (__n1 != __n2) 30850b57cec5SDimitry Andric { 30860b57cec5SDimitry Andric size_type __n_move = __sz - __pos - __n1; 30870b57cec5SDimitry Andric if (__n_move != 0) 30880b57cec5SDimitry Andric { 30890b57cec5SDimitry Andric if (__n1 > __n2) 30900b57cec5SDimitry Andric { 30910b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n2); 30920b57cec5SDimitry Andric traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 30930eae32dcSDimitry Andric return __null_terminate_at(__p, __sz + (__n2 - __n1)); 30940b57cec5SDimitry Andric } 30950b57cec5SDimitry Andric if (__p + __pos < __s && __s < __p + __sz) 30960b57cec5SDimitry Andric { 30970b57cec5SDimitry Andric if (__p + __pos + __n1 <= __s) 30980b57cec5SDimitry Andric __s += __n2 - __n1; 30990b57cec5SDimitry Andric else // __p + __pos < __s < __p + __pos + __n1 31000b57cec5SDimitry Andric { 31010b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n1); 31020b57cec5SDimitry Andric __pos += __n1; 31030b57cec5SDimitry Andric __s += __n2; 31040b57cec5SDimitry Andric __n2 -= __n1; 31050b57cec5SDimitry Andric __n1 = 0; 31060b57cec5SDimitry Andric } 31070b57cec5SDimitry Andric } 31080b57cec5SDimitry Andric traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 31090b57cec5SDimitry Andric } 31100b57cec5SDimitry Andric } 31110b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n2); 31120eae32dcSDimitry Andric return __null_terminate_at(__p, __sz + (__n2 - __n1)); 31130b57cec5SDimitry Andric } 31140b57cec5SDimitry Andric else 31150b57cec5SDimitry Andric __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); 31160b57cec5SDimitry Andric return *this; 31170b57cec5SDimitry Andric} 31180b57cec5SDimitry Andric 31190b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 312081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 31210b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 31220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) 31230b57cec5SDimitry Andric{ 31240b57cec5SDimitry Andric size_type __sz = size(); 31250b57cec5SDimitry Andric if (__pos > __sz) 312604eeddc0SDimitry Andric __throw_out_of_range(); 312781ad6265SDimitry Andric __n1 = std::min(__n1, __sz - __pos); 31280b57cec5SDimitry Andric size_type __cap = capacity(); 31290b57cec5SDimitry Andric value_type* __p; 31300b57cec5SDimitry Andric if (__cap - __sz + __n1 >= __n2) 31310b57cec5SDimitry Andric { 313281ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 31330b57cec5SDimitry Andric if (__n1 != __n2) 31340b57cec5SDimitry Andric { 31350b57cec5SDimitry Andric size_type __n_move = __sz - __pos - __n1; 31360b57cec5SDimitry Andric if (__n_move != 0) 31370b57cec5SDimitry Andric traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 31380b57cec5SDimitry Andric } 31390b57cec5SDimitry Andric } 31400b57cec5SDimitry Andric else 31410b57cec5SDimitry Andric { 31420b57cec5SDimitry Andric __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); 314381ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 31440b57cec5SDimitry Andric } 31450b57cec5SDimitry Andric traits_type::assign(__p + __pos, __n2, __c); 31460eae32dcSDimitry Andric return __null_terminate_at(__p, __sz - (__n1 - __n2)); 31470b57cec5SDimitry Andric} 31480b57cec5SDimitry Andric 31490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 31500b57cec5SDimitry Andrictemplate<class _InputIterator> 315181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3152349cc55cSDimitry Andric__enable_if_t 31530b57cec5SDimitry Andric< 3154480093f4SDimitry Andric __is_cpp17_input_iterator<_InputIterator>::value, 31550b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 31565ffd83dbSDimitry Andric> 31570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, 31580b57cec5SDimitry Andric _InputIterator __j1, _InputIterator __j2) 31590b57cec5SDimitry Andric{ 31600b57cec5SDimitry Andric const basic_string __temp(__j1, __j2, __alloc()); 316104eeddc0SDimitry Andric return replace(__i1, __i2, __temp); 31620b57cec5SDimitry Andric} 31630b57cec5SDimitry Andric 31640b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 316581ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 31660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 31670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) 31680b57cec5SDimitry Andric{ 31690b57cec5SDimitry Andric return replace(__pos1, __n1, __str.data(), __str.size()); 31700b57cec5SDimitry Andric} 31710b57cec5SDimitry Andric 31720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 317381ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 31740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 31750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, 31760b57cec5SDimitry Andric size_type __pos2, size_type __n2) 31770b57cec5SDimitry Andric{ 31780b57cec5SDimitry Andric size_type __str_sz = __str.size(); 31790b57cec5SDimitry Andric if (__pos2 > __str_sz) 318004eeddc0SDimitry Andric __throw_out_of_range(); 318181ad6265SDimitry Andric return replace(__pos1, __n1, __str.data() + __pos2, std::min(__n2, __str_sz - __pos2)); 31820b57cec5SDimitry Andric} 31830b57cec5SDimitry Andric 31840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 31850b57cec5SDimitry Andrictemplate <class _Tp> 318681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3187349cc55cSDimitry Andric__enable_if_t 31880b57cec5SDimitry Andric< 31895ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 31900b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& 31915ffd83dbSDimitry Andric> 31920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t, 31930b57cec5SDimitry Andric size_type __pos2, size_type __n2) 31940b57cec5SDimitry Andric{ 31950b57cec5SDimitry Andric __self_view __sv = __t; 31960b57cec5SDimitry Andric size_type __str_sz = __sv.size(); 31970b57cec5SDimitry Andric if (__pos2 > __str_sz) 319804eeddc0SDimitry Andric __throw_out_of_range(); 319981ad6265SDimitry Andric return replace(__pos1, __n1, __sv.data() + __pos2, std::min(__n2, __str_sz - __pos2)); 32000b57cec5SDimitry Andric} 32010b57cec5SDimitry Andric 32020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 320381ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 32050b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) 32060b57cec5SDimitry Andric{ 32070b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); 32080b57cec5SDimitry Andric return replace(__pos, __n1, __s, traits_type::length(__s)); 32090b57cec5SDimitry Andric} 32100b57cec5SDimitry Andric 32110b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 321281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 32130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 32140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) 32150b57cec5SDimitry Andric{ 32160b57cec5SDimitry Andric return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), 32170b57cec5SDimitry Andric __str.data(), __str.size()); 32180b57cec5SDimitry Andric} 32190b57cec5SDimitry Andric 32200b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 322181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 32220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 32230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) 32240b57cec5SDimitry Andric{ 32250b57cec5SDimitry Andric return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); 32260b57cec5SDimitry Andric} 32270b57cec5SDimitry Andric 32280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 322981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 32300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 32310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s) 32320b57cec5SDimitry Andric{ 32330b57cec5SDimitry Andric return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); 32340b57cec5SDimitry Andric} 32350b57cec5SDimitry Andric 32360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 323781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 32380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 32390b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) 32400b57cec5SDimitry Andric{ 32410b57cec5SDimitry Andric return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); 32420b57cec5SDimitry Andric} 32430b57cec5SDimitry Andric 32440b57cec5SDimitry Andric// erase 32450b57cec5SDimitry Andric 32465ffd83dbSDimitry Andric// 'externally instantiated' erase() implementation, called when __n != npos. 32475ffd83dbSDimitry Andric// Does not check __pos against size() 32480b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 324981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32505ffd83dbSDimitry Andricvoid 32515ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( 32525ffd83dbSDimitry Andric size_type __pos, size_type __n) 32530b57cec5SDimitry Andric{ 32540b57cec5SDimitry Andric if (__n) 32550b57cec5SDimitry Andric { 32565ffd83dbSDimitry Andric size_type __sz = size(); 325781ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 325881ad6265SDimitry Andric __n = std::min(__n, __sz - __pos); 32590b57cec5SDimitry Andric size_type __n_move = __sz - __pos - __n; 32600b57cec5SDimitry Andric if (__n_move != 0) 32610b57cec5SDimitry Andric traits_type::move(__p + __pos, __p + __pos + __n, __n_move); 32620eae32dcSDimitry Andric __null_terminate_at(__p, __sz - __n); 32630b57cec5SDimitry Andric } 32645ffd83dbSDimitry Andric} 32655ffd83dbSDimitry Andric 32665ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 326781ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 32685ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 32695ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, 32705ffd83dbSDimitry Andric size_type __n) { 327104eeddc0SDimitry Andric if (__pos > size()) 327204eeddc0SDimitry Andric __throw_out_of_range(); 32735ffd83dbSDimitry Andric if (__n == npos) { 32745ffd83dbSDimitry Andric __erase_to_end(__pos); 32755ffd83dbSDimitry Andric } else { 32765ffd83dbSDimitry Andric __erase_external_with_move(__pos, __n); 32775ffd83dbSDimitry Andric } 32780b57cec5SDimitry Andric return *this; 32790b57cec5SDimitry Andric} 32800b57cec5SDimitry Andric 32810b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 328281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 32830b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 32840b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) 32850b57cec5SDimitry Andric{ 32860eae32dcSDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, 32870b57cec5SDimitry Andric "string::erase(iterator) called with an iterator not" 32880b57cec5SDimitry Andric " referring to this string"); 32890eae32dcSDimitry Andric 32900eae32dcSDimitry Andric _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); 32910b57cec5SDimitry Andric iterator __b = begin(); 32920b57cec5SDimitry Andric size_type __r = static_cast<size_type>(__pos - __b); 32930b57cec5SDimitry Andric erase(__r, 1); 32940b57cec5SDimitry Andric return __b + static_cast<difference_type>(__r); 32950b57cec5SDimitry Andric} 32960b57cec5SDimitry Andric 32970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 329881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 32990b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 33000b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) 33010b57cec5SDimitry Andric{ 33020eae32dcSDimitry Andric _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, 33030b57cec5SDimitry Andric "string::erase(iterator, iterator) called with an iterator not" 33040b57cec5SDimitry Andric " referring to this string"); 33050eae32dcSDimitry Andric 33060b57cec5SDimitry Andric _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); 33070b57cec5SDimitry Andric iterator __b = begin(); 33080b57cec5SDimitry Andric size_type __r = static_cast<size_type>(__first - __b); 33090b57cec5SDimitry Andric erase(__r, static_cast<size_type>(__last - __first)); 33100b57cec5SDimitry Andric return __b + static_cast<difference_type>(__r); 33110b57cec5SDimitry Andric} 33120b57cec5SDimitry Andric 33130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 331481ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 33150b57cec5SDimitry Andricvoid 33160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::pop_back() 33170b57cec5SDimitry Andric{ 33180b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); 33190eae32dcSDimitry Andric __erase_to_end(size() - 1); 33200b57cec5SDimitry Andric} 33210b57cec5SDimitry Andric 33220b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 332381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 33240b57cec5SDimitry Andricvoid 33250b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT 33260b57cec5SDimitry Andric{ 332781ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 33280b57cec5SDimitry Andric if (__is_long()) 33290b57cec5SDimitry Andric { 33300b57cec5SDimitry Andric traits_type::assign(*__get_long_pointer(), value_type()); 33310b57cec5SDimitry Andric __set_long_size(0); 33320b57cec5SDimitry Andric } 33330b57cec5SDimitry Andric else 33340b57cec5SDimitry Andric { 33350b57cec5SDimitry Andric traits_type::assign(*__get_short_pointer(), value_type()); 33360b57cec5SDimitry Andric __set_short_size(0); 33370b57cec5SDimitry Andric } 33380b57cec5SDimitry Andric} 33390b57cec5SDimitry Andric 33400b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 334181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 33420b57cec5SDimitry Andricvoid 33430b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) 33440b57cec5SDimitry Andric{ 334581ad6265SDimitry Andric __null_terminate_at(std::__to_address(__get_pointer()), __pos); 33460b57cec5SDimitry Andric} 33470b57cec5SDimitry Andric 33480b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 334981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 33500b57cec5SDimitry Andricvoid 33510b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) 33520b57cec5SDimitry Andric{ 33530b57cec5SDimitry Andric size_type __sz = size(); 33540b57cec5SDimitry Andric if (__n > __sz) 33550b57cec5SDimitry Andric append(__n - __sz, __c); 33560b57cec5SDimitry Andric else 33570b57cec5SDimitry Andric __erase_to_end(__n); 33580b57cec5SDimitry Andric} 33590b57cec5SDimitry Andric 33600b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 336181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 inline void 33620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) 33630b57cec5SDimitry Andric{ 33640b57cec5SDimitry Andric size_type __sz = size(); 33650b57cec5SDimitry Andric if (__n > __sz) { 33660b57cec5SDimitry Andric __append_default_init(__n - __sz); 33670b57cec5SDimitry Andric } else 33680b57cec5SDimitry Andric __erase_to_end(__n); 33690b57cec5SDimitry Andric} 33700b57cec5SDimitry Andric 33710b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 337281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 33730b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 33740b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT 33750b57cec5SDimitry Andric{ 33760b57cec5SDimitry Andric size_type __m = __alloc_traits::max_size(__alloc()); 337781ad6265SDimitry Andric if (__m <= std::numeric_limits<size_type>::max() / 2) { 33780b57cec5SDimitry Andric return __m - __alignment; 337981ad6265SDimitry Andric } else { 338081ad6265SDimitry Andric bool __uses_lsb = __endian_factor == 2; 338181ad6265SDimitry Andric return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment; 338281ad6265SDimitry Andric } 33830b57cec5SDimitry Andric} 33840b57cec5SDimitry Andric 33850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 338681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 33870b57cec5SDimitry Andricvoid 3388e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) 33890b57cec5SDimitry Andric{ 3390e8d8bef9SDimitry Andric if (__requested_capacity > max_size()) 339104eeddc0SDimitry Andric __throw_length_error(); 3392e8d8bef9SDimitry Andric 339304eeddc0SDimitry Andric // Make sure reserve(n) never shrinks. This is technically only required in C++20 339404eeddc0SDimitry Andric // and later (since P0966R1), however we provide consistent behavior in all Standard 339504eeddc0SDimitry Andric // modes because this function is instantiated in the shared library. 339604eeddc0SDimitry Andric if (__requested_capacity <= capacity()) 339704eeddc0SDimitry Andric return; 3398e8d8bef9SDimitry Andric 339981ad6265SDimitry Andric size_type __target_capacity = std::max(__requested_capacity, size()); 3400e8d8bef9SDimitry Andric __target_capacity = __recommend(__target_capacity); 3401e8d8bef9SDimitry Andric if (__target_capacity == capacity()) return; 3402e8d8bef9SDimitry Andric 3403e8d8bef9SDimitry Andric __shrink_or_extend(__target_capacity); 3404e8d8bef9SDimitry Andric} 3405e8d8bef9SDimitry Andric 3406e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 340781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 3408e8d8bef9SDimitry Andricvoid 3409e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT 3410e8d8bef9SDimitry Andric{ 3411e8d8bef9SDimitry Andric size_type __target_capacity = __recommend(size()); 3412e8d8bef9SDimitry Andric if (__target_capacity == capacity()) return; 3413e8d8bef9SDimitry Andric 3414e8d8bef9SDimitry Andric __shrink_or_extend(__target_capacity); 3415e8d8bef9SDimitry Andric} 3416e8d8bef9SDimitry Andric 3417e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 341881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 3419e8d8bef9SDimitry Andricvoid 3420e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) 3421e8d8bef9SDimitry Andric{ 34220b57cec5SDimitry Andric size_type __cap = capacity(); 34230b57cec5SDimitry Andric size_type __sz = size(); 3424e8d8bef9SDimitry Andric 34250b57cec5SDimitry Andric pointer __new_data, __p; 34260b57cec5SDimitry Andric bool __was_long, __now_long; 342781ad6265SDimitry Andric if (__fits_in_sso(__target_capacity)) 34280b57cec5SDimitry Andric { 34290b57cec5SDimitry Andric __was_long = true; 34300b57cec5SDimitry Andric __now_long = false; 34310b57cec5SDimitry Andric __new_data = __get_short_pointer(); 34320b57cec5SDimitry Andric __p = __get_long_pointer(); 34330b57cec5SDimitry Andric } 34340b57cec5SDimitry Andric else 34350b57cec5SDimitry Andric { 343681ad6265SDimitry Andric if (__target_capacity > __cap) { 343781ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); 343881ad6265SDimitry Andric __new_data = __allocation.ptr; 343981ad6265SDimitry Andric __target_capacity = __allocation.count - 1; 344081ad6265SDimitry Andric } 34410b57cec5SDimitry Andric else 34420b57cec5SDimitry Andric { 34430b57cec5SDimitry Andric #ifndef _LIBCPP_NO_EXCEPTIONS 34440b57cec5SDimitry Andric try 34450b57cec5SDimitry Andric { 34460b57cec5SDimitry Andric #endif // _LIBCPP_NO_EXCEPTIONS 344781ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); 344881ad6265SDimitry Andric __new_data = __allocation.ptr; 344981ad6265SDimitry Andric __target_capacity = __allocation.count - 1; 34500b57cec5SDimitry Andric #ifndef _LIBCPP_NO_EXCEPTIONS 34510b57cec5SDimitry Andric } 34520b57cec5SDimitry Andric catch (...) 34530b57cec5SDimitry Andric { 34540b57cec5SDimitry Andric return; 34550b57cec5SDimitry Andric } 34560b57cec5SDimitry Andric #else // _LIBCPP_NO_EXCEPTIONS 34570b57cec5SDimitry Andric if (__new_data == nullptr) 34580b57cec5SDimitry Andric return; 34590b57cec5SDimitry Andric #endif // _LIBCPP_NO_EXCEPTIONS 34600b57cec5SDimitry Andric } 346181ad6265SDimitry Andric __begin_lifetime(__new_data, __target_capacity + 1); 34620b57cec5SDimitry Andric __now_long = true; 34630b57cec5SDimitry Andric __was_long = __is_long(); 34640b57cec5SDimitry Andric __p = __get_pointer(); 34650b57cec5SDimitry Andric } 346681ad6265SDimitry Andric traits_type::copy(std::__to_address(__new_data), 346781ad6265SDimitry Andric std::__to_address(__p), size()+1); 34680b57cec5SDimitry Andric if (__was_long) 34690b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __p, __cap+1); 34700b57cec5SDimitry Andric if (__now_long) 34710b57cec5SDimitry Andric { 3472e8d8bef9SDimitry Andric __set_long_cap(__target_capacity+1); 34730b57cec5SDimitry Andric __set_long_size(__sz); 34740b57cec5SDimitry Andric __set_long_pointer(__new_data); 34750b57cec5SDimitry Andric } 34760b57cec5SDimitry Andric else 34770b57cec5SDimitry Andric __set_short_size(__sz); 347881ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 34790b57cec5SDimitry Andric} 34800b57cec5SDimitry Andric 34810b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 348281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 34830b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference 34840b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT 34850b57cec5SDimitry Andric{ 34860b57cec5SDimitry Andric _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); 34870b57cec5SDimitry Andric return *(data() + __pos); 34880b57cec5SDimitry Andric} 34890b57cec5SDimitry Andric 34900b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 349181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 34920b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference 34930b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT 34940b57cec5SDimitry Andric{ 34950b57cec5SDimitry Andric _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); 34960b57cec5SDimitry Andric return *(__get_pointer() + __pos); 34970b57cec5SDimitry Andric} 34980b57cec5SDimitry Andric 34990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 350081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 35010b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference 35020b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const 35030b57cec5SDimitry Andric{ 35040b57cec5SDimitry Andric if (__n >= size()) 350504eeddc0SDimitry Andric __throw_out_of_range(); 35060b57cec5SDimitry Andric return (*this)[__n]; 35070b57cec5SDimitry Andric} 35080b57cec5SDimitry Andric 35090b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 351081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 35110b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference 35120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n) 35130b57cec5SDimitry Andric{ 35140b57cec5SDimitry Andric if (__n >= size()) 351504eeddc0SDimitry Andric __throw_out_of_range(); 35160b57cec5SDimitry Andric return (*this)[__n]; 35170b57cec5SDimitry Andric} 35180b57cec5SDimitry Andric 35190b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 352081ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 35210b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference 35220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT 35230b57cec5SDimitry Andric{ 35240b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); 35250b57cec5SDimitry Andric return *__get_pointer(); 35260b57cec5SDimitry Andric} 35270b57cec5SDimitry Andric 35280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 352981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 35300b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference 35310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT 35320b57cec5SDimitry Andric{ 35330b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); 35340b57cec5SDimitry Andric return *data(); 35350b57cec5SDimitry Andric} 35360b57cec5SDimitry Andric 35370b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 353881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 35390b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference 35400b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT 35410b57cec5SDimitry Andric{ 35420b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); 35430b57cec5SDimitry Andric return *(__get_pointer() + size() - 1); 35440b57cec5SDimitry Andric} 35450b57cec5SDimitry Andric 35460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 354781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 35480b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference 35490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT 35500b57cec5SDimitry Andric{ 35510b57cec5SDimitry Andric _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); 35520b57cec5SDimitry Andric return *(data() + size() - 1); 35530b57cec5SDimitry Andric} 35540b57cec5SDimitry Andric 35550b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 355681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 35570b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35580b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const 35590b57cec5SDimitry Andric{ 35600b57cec5SDimitry Andric size_type __sz = size(); 35610b57cec5SDimitry Andric if (__pos > __sz) 356204eeddc0SDimitry Andric __throw_out_of_range(); 356381ad6265SDimitry Andric size_type __rlen = std::min(__n, __sz - __pos); 35640b57cec5SDimitry Andric traits_type::copy(__s, data() + __pos, __rlen); 35650b57cec5SDimitry Andric return __rlen; 35660b57cec5SDimitry Andric} 35670b57cec5SDimitry Andric 35680b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 356981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 35700b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 35710b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const 35720b57cec5SDimitry Andric{ 35730b57cec5SDimitry Andric return basic_string(*this, __pos, __n, __alloc()); 35740b57cec5SDimitry Andric} 35750b57cec5SDimitry Andric 35760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 357781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 35780b57cec5SDimitry Andricvoid 35790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) 35800b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 35810b57cec5SDimitry Andric _NOEXCEPT 35820b57cec5SDimitry Andric#else 35830b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 35840b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 35850b57cec5SDimitry Andric#endif 35860b57cec5SDimitry Andric{ 35870b57cec5SDimitry Andric if (!__is_long()) 358881ad6265SDimitry Andric std::__debug_db_invalidate_all(this); 35890b57cec5SDimitry Andric if (!__str.__is_long()) 359081ad6265SDimitry Andric std::__debug_db_invalidate_all(&__str); 359181ad6265SDimitry Andric std::__debug_db_swap(this, &__str); 359281ad6265SDimitry Andric 35930b57cec5SDimitry Andric _LIBCPP_ASSERT( 35940b57cec5SDimitry Andric __alloc_traits::propagate_on_container_swap::value || 35950b57cec5SDimitry Andric __alloc_traits::is_always_equal::value || 35960b57cec5SDimitry Andric __alloc() == __str.__alloc(), "swapping non-equal allocators"); 359781ad6265SDimitry Andric std::swap(__r_.first(), __str.__r_.first()); 359881ad6265SDimitry Andric std::__swap_allocator(__alloc(), __str.__alloc()); 35990b57cec5SDimitry Andric} 36000b57cec5SDimitry Andric 36010b57cec5SDimitry Andric// find 36020b57cec5SDimitry Andric 36030b57cec5SDimitry Andrictemplate <class _Traits> 36040b57cec5SDimitry Andricstruct _LIBCPP_HIDDEN __traits_eq 36050b57cec5SDimitry Andric{ 36060b57cec5SDimitry Andric typedef typename _Traits::char_type char_type; 360781ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI 36080b57cec5SDimitry Andric bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT 36090b57cec5SDimitry Andric {return _Traits::eq(__x, __y);} 36100b57cec5SDimitry Andric}; 36110b57cec5SDimitry Andric 36120b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 361381ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 36140b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, 36160b57cec5SDimitry Andric size_type __pos, 36170b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 36180b57cec5SDimitry Andric{ 36190b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); 36200b57cec5SDimitry Andric return __str_find<value_type, size_type, traits_type, npos> 36210b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 36220b57cec5SDimitry Andric} 36230b57cec5SDimitry Andric 36240b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 362581ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 36260b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, 36280b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36290b57cec5SDimitry Andric{ 36300b57cec5SDimitry Andric return __str_find<value_type, size_type, traits_type, npos> 36310b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 36320b57cec5SDimitry Andric} 36330b57cec5SDimitry Andric 36340b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 36350b57cec5SDimitry Andrictemplate <class _Tp> 363681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3637349cc55cSDimitry Andric__enable_if_t 36380b57cec5SDimitry Andric< 36390b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 36400b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 36415ffd83dbSDimitry Andric> 36420b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, 3643fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 36440b57cec5SDimitry Andric{ 36450b57cec5SDimitry Andric __self_view __sv = __t; 36460b57cec5SDimitry Andric return __str_find<value_type, size_type, traits_type, npos> 36470b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 36480b57cec5SDimitry Andric} 36490b57cec5SDimitry Andric 36500b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 365181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 36520b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, 36540b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36550b57cec5SDimitry Andric{ 36560b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); 36570b57cec5SDimitry Andric return __str_find<value_type, size_type, traits_type, npos> 36580b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 36590b57cec5SDimitry Andric} 36600b57cec5SDimitry Andric 36610b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 366281ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 36630b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(value_type __c, 36650b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36660b57cec5SDimitry Andric{ 36670b57cec5SDimitry Andric return __str_find<value_type, size_type, traits_type, npos> 36680b57cec5SDimitry Andric (data(), size(), __c, __pos); 36690b57cec5SDimitry Andric} 36700b57cec5SDimitry Andric 36710b57cec5SDimitry Andric// rfind 36720b57cec5SDimitry Andric 36730b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 367481ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 36750b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36760b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, 36770b57cec5SDimitry Andric size_type __pos, 36780b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 36790b57cec5SDimitry Andric{ 36800b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); 36810b57cec5SDimitry Andric return __str_rfind<value_type, size_type, traits_type, npos> 36820b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 36830b57cec5SDimitry Andric} 36840b57cec5SDimitry Andric 36850b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 368681ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 36870b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36880b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, 36890b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36900b57cec5SDimitry Andric{ 36910b57cec5SDimitry Andric return __str_rfind<value_type, size_type, traits_type, npos> 36920b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 36930b57cec5SDimitry Andric} 36940b57cec5SDimitry Andric 36950b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 36960b57cec5SDimitry Andrictemplate <class _Tp> 369781ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3698349cc55cSDimitry Andric__enable_if_t 36990b57cec5SDimitry Andric< 37000b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 37010b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 37025ffd83dbSDimitry Andric> 37030b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, 3704fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 37050b57cec5SDimitry Andric{ 37060b57cec5SDimitry Andric __self_view __sv = __t; 37070b57cec5SDimitry Andric return __str_rfind<value_type, size_type, traits_type, npos> 37080b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 37090b57cec5SDimitry Andric} 37100b57cec5SDimitry Andric 37110b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 371281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 37130b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, 37150b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 37160b57cec5SDimitry Andric{ 37170b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); 37180b57cec5SDimitry Andric return __str_rfind<value_type, size_type, traits_type, npos> 37190b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 37200b57cec5SDimitry Andric} 37210b57cec5SDimitry Andric 37220b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 372381ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 37240b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37250b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, 37260b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 37270b57cec5SDimitry Andric{ 37280b57cec5SDimitry Andric return __str_rfind<value_type, size_type, traits_type, npos> 37290b57cec5SDimitry Andric (data(), size(), __c, __pos); 37300b57cec5SDimitry Andric} 37310b57cec5SDimitry Andric 37320b57cec5SDimitry Andric// find_first_of 37330b57cec5SDimitry Andric 37340b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 373581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 37360b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37370b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, 37380b57cec5SDimitry Andric size_type __pos, 37390b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 37400b57cec5SDimitry Andric{ 37410b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); 37420b57cec5SDimitry Andric return __str_find_first_of<value_type, size_type, traits_type, npos> 37430b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 37440b57cec5SDimitry Andric} 37450b57cec5SDimitry Andric 37460b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 374781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 37480b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, 37500b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 37510b57cec5SDimitry Andric{ 37520b57cec5SDimitry Andric return __str_find_first_of<value_type, size_type, traits_type, npos> 37530b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 37540b57cec5SDimitry Andric} 37550b57cec5SDimitry Andric 37560b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 37570b57cec5SDimitry Andrictemplate <class _Tp> 375881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3759349cc55cSDimitry Andric__enable_if_t 37600b57cec5SDimitry Andric< 37610b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 37620b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 37635ffd83dbSDimitry Andric> 37640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, 3765fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 37660b57cec5SDimitry Andric{ 37670b57cec5SDimitry Andric __self_view __sv = __t; 37680b57cec5SDimitry Andric return __str_find_first_of<value_type, size_type, traits_type, npos> 37690b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 37700b57cec5SDimitry Andric} 37710b57cec5SDimitry Andric 37720b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 377381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 37740b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, 37760b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 37770b57cec5SDimitry Andric{ 37780b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); 37790b57cec5SDimitry Andric return __str_find_first_of<value_type, size_type, traits_type, npos> 37800b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 37810b57cec5SDimitry Andric} 37820b57cec5SDimitry Andric 37830b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 378481ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 37850b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37860b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, 37870b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 37880b57cec5SDimitry Andric{ 37890b57cec5SDimitry Andric return find(__c, __pos); 37900b57cec5SDimitry Andric} 37910b57cec5SDimitry Andric 37920b57cec5SDimitry Andric// find_last_of 37930b57cec5SDimitry Andric 37940b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 379581ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 37960b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37970b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, 37980b57cec5SDimitry Andric size_type __pos, 37990b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 38000b57cec5SDimitry Andric{ 38010b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); 38020b57cec5SDimitry Andric return __str_find_last_of<value_type, size_type, traits_type, npos> 38030b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 38040b57cec5SDimitry Andric} 38050b57cec5SDimitry Andric 38060b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 380781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 38080b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 38090b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, 38100b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 38110b57cec5SDimitry Andric{ 38120b57cec5SDimitry Andric return __str_find_last_of<value_type, size_type, traits_type, npos> 38130b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 38140b57cec5SDimitry Andric} 38150b57cec5SDimitry Andric 38160b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 38170b57cec5SDimitry Andrictemplate <class _Tp> 381881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3819349cc55cSDimitry Andric__enable_if_t 38200b57cec5SDimitry Andric< 38210b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 38220b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 38235ffd83dbSDimitry Andric> 38240b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, 3825fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 38260b57cec5SDimitry Andric{ 38270b57cec5SDimitry Andric __self_view __sv = __t; 38280b57cec5SDimitry Andric return __str_find_last_of<value_type, size_type, traits_type, npos> 38290b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 38300b57cec5SDimitry Andric} 38310b57cec5SDimitry Andric 38320b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 383381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 38340b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 38350b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, 38360b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 38370b57cec5SDimitry Andric{ 38380b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); 38390b57cec5SDimitry Andric return __str_find_last_of<value_type, size_type, traits_type, npos> 38400b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 38410b57cec5SDimitry Andric} 38420b57cec5SDimitry Andric 38430b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 384481ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 38450b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 38460b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, 38470b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 38480b57cec5SDimitry Andric{ 38490b57cec5SDimitry Andric return rfind(__c, __pos); 38500b57cec5SDimitry Andric} 38510b57cec5SDimitry Andric 38520b57cec5SDimitry Andric// find_first_not_of 38530b57cec5SDimitry Andric 38540b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 385581ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 38560b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 38570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, 38580b57cec5SDimitry Andric size_type __pos, 38590b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 38600b57cec5SDimitry Andric{ 38610b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); 38620b57cec5SDimitry Andric return __str_find_first_not_of<value_type, size_type, traits_type, npos> 38630b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 38640b57cec5SDimitry Andric} 38650b57cec5SDimitry Andric 38660b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 386781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 38680b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 38690b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, 38700b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 38710b57cec5SDimitry Andric{ 38720b57cec5SDimitry Andric return __str_find_first_not_of<value_type, size_type, traits_type, npos> 38730b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 38740b57cec5SDimitry Andric} 38750b57cec5SDimitry Andric 38760b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 38770b57cec5SDimitry Andrictemplate <class _Tp> 387881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3879349cc55cSDimitry Andric__enable_if_t 38800b57cec5SDimitry Andric< 38810b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 38820b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 38835ffd83dbSDimitry Andric> 38840b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, 3885fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 38860b57cec5SDimitry Andric{ 38870b57cec5SDimitry Andric __self_view __sv = __t; 38880b57cec5SDimitry Andric return __str_find_first_not_of<value_type, size_type, traits_type, npos> 38890b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 38900b57cec5SDimitry Andric} 38910b57cec5SDimitry Andric 38920b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 389381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 38940b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 38950b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, 38960b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 38970b57cec5SDimitry Andric{ 38980b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); 38990b57cec5SDimitry Andric return __str_find_first_not_of<value_type, size_type, traits_type, npos> 39000b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 39010b57cec5SDimitry Andric} 39020b57cec5SDimitry Andric 39030b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 390481ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 39050b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 39060b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, 39070b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 39080b57cec5SDimitry Andric{ 39090b57cec5SDimitry Andric return __str_find_first_not_of<value_type, size_type, traits_type, npos> 39100b57cec5SDimitry Andric (data(), size(), __c, __pos); 39110b57cec5SDimitry Andric} 39120b57cec5SDimitry Andric 39130b57cec5SDimitry Andric// find_last_not_of 39140b57cec5SDimitry Andric 39150b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 391681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 39170b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 39180b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, 39190b57cec5SDimitry Andric size_type __pos, 39200b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 39210b57cec5SDimitry Andric{ 39220b57cec5SDimitry Andric _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); 39230b57cec5SDimitry Andric return __str_find_last_not_of<value_type, size_type, traits_type, npos> 39240b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 39250b57cec5SDimitry Andric} 39260b57cec5SDimitry Andric 39270b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 392881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 39290b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 39300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, 39310b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 39320b57cec5SDimitry Andric{ 39330b57cec5SDimitry Andric return __str_find_last_not_of<value_type, size_type, traits_type, npos> 39340b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 39350b57cec5SDimitry Andric} 39360b57cec5SDimitry Andric 39370b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 39380b57cec5SDimitry Andrictemplate <class _Tp> 393981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3940349cc55cSDimitry Andric__enable_if_t 39410b57cec5SDimitry Andric< 39420b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 39430b57cec5SDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 39445ffd83dbSDimitry Andric> 39450b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, 3946fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 39470b57cec5SDimitry Andric{ 39480b57cec5SDimitry Andric __self_view __sv = __t; 39490b57cec5SDimitry Andric return __str_find_last_not_of<value_type, size_type, traits_type, npos> 39500b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 39510b57cec5SDimitry Andric} 39520b57cec5SDimitry Andric 39530b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 395481ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 39550b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 39560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, 39570b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 39580b57cec5SDimitry Andric{ 39590b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); 39600b57cec5SDimitry Andric return __str_find_last_not_of<value_type, size_type, traits_type, npos> 39610b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 39620b57cec5SDimitry Andric} 39630b57cec5SDimitry Andric 39640b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 396581ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 39660b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 39670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, 39680b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 39690b57cec5SDimitry Andric{ 39700b57cec5SDimitry Andric return __str_find_last_not_of<value_type, size_type, traits_type, npos> 39710b57cec5SDimitry Andric (data(), size(), __c, __pos); 39720b57cec5SDimitry Andric} 39730b57cec5SDimitry Andric 39740b57cec5SDimitry Andric// compare 39750b57cec5SDimitry Andric 39760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 39770b57cec5SDimitry Andrictemplate <class _Tp> 397881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 3979349cc55cSDimitry Andric__enable_if_t 39800b57cec5SDimitry Andric< 39810b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 39820b57cec5SDimitry Andric int 39835ffd83dbSDimitry Andric> 3984fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT 39850b57cec5SDimitry Andric{ 39860b57cec5SDimitry Andric __self_view __sv = __t; 39870b57cec5SDimitry Andric size_t __lhs_sz = size(); 39880b57cec5SDimitry Andric size_t __rhs_sz = __sv.size(); 39890b57cec5SDimitry Andric int __result = traits_type::compare(data(), __sv.data(), 399081ad6265SDimitry Andric std::min(__lhs_sz, __rhs_sz)); 39910b57cec5SDimitry Andric if (__result != 0) 39920b57cec5SDimitry Andric return __result; 39930b57cec5SDimitry Andric if (__lhs_sz < __rhs_sz) 39940b57cec5SDimitry Andric return -1; 39950b57cec5SDimitry Andric if (__lhs_sz > __rhs_sz) 39960b57cec5SDimitry Andric return 1; 39970b57cec5SDimitry Andric return 0; 39980b57cec5SDimitry Andric} 39990b57cec5SDimitry Andric 40000b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 400181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 40020b57cec5SDimitry Andricint 40030b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT 40040b57cec5SDimitry Andric{ 40050b57cec5SDimitry Andric return compare(__self_view(__str)); 40060b57cec5SDimitry Andric} 40070b57cec5SDimitry Andric 40080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 400981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 40100b57cec5SDimitry Andricint 40110b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 40120b57cec5SDimitry Andric size_type __n1, 40130b57cec5SDimitry Andric const value_type* __s, 40140b57cec5SDimitry Andric size_type __n2) const 40150b57cec5SDimitry Andric{ 40160b57cec5SDimitry Andric _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); 40170b57cec5SDimitry Andric size_type __sz = size(); 40180b57cec5SDimitry Andric if (__pos1 > __sz || __n2 == npos) 401904eeddc0SDimitry Andric __throw_out_of_range(); 402081ad6265SDimitry Andric size_type __rlen = std::min(__n1, __sz - __pos1); 402181ad6265SDimitry Andric int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2)); 40220b57cec5SDimitry Andric if (__r == 0) 40230b57cec5SDimitry Andric { 40240b57cec5SDimitry Andric if (__rlen < __n2) 40250b57cec5SDimitry Andric __r = -1; 40260b57cec5SDimitry Andric else if (__rlen > __n2) 40270b57cec5SDimitry Andric __r = 1; 40280b57cec5SDimitry Andric } 40290b57cec5SDimitry Andric return __r; 40300b57cec5SDimitry Andric} 40310b57cec5SDimitry Andric 40320b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 40330b57cec5SDimitry Andrictemplate <class _Tp> 403481ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 4035349cc55cSDimitry Andric__enable_if_t 40360b57cec5SDimitry Andric< 40370b57cec5SDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, 40380b57cec5SDimitry Andric int 40395ffd83dbSDimitry Andric> 40400b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 40410b57cec5SDimitry Andric size_type __n1, 40420b57cec5SDimitry Andric const _Tp& __t) const 40430b57cec5SDimitry Andric{ 40440b57cec5SDimitry Andric __self_view __sv = __t; 40450b57cec5SDimitry Andric return compare(__pos1, __n1, __sv.data(), __sv.size()); 40460b57cec5SDimitry Andric} 40470b57cec5SDimitry Andric 40480b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 404981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 40500b57cec5SDimitry Andricint 40510b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 40520b57cec5SDimitry Andric size_type __n1, 40530b57cec5SDimitry Andric const basic_string& __str) const 40540b57cec5SDimitry Andric{ 40550b57cec5SDimitry Andric return compare(__pos1, __n1, __str.data(), __str.size()); 40560b57cec5SDimitry Andric} 40570b57cec5SDimitry Andric 40580b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 40590b57cec5SDimitry Andrictemplate <class _Tp> 406081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 4061349cc55cSDimitry Andric__enable_if_t 40620b57cec5SDimitry Andric< 40635ffd83dbSDimitry Andric __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value 40645ffd83dbSDimitry Andric && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 40650b57cec5SDimitry Andric int 40665ffd83dbSDimitry Andric> 40670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 40680b57cec5SDimitry Andric size_type __n1, 40690b57cec5SDimitry Andric const _Tp& __t, 40700b57cec5SDimitry Andric size_type __pos2, 40710b57cec5SDimitry Andric size_type __n2) const 40720b57cec5SDimitry Andric{ 40730b57cec5SDimitry Andric __self_view __sv = __t; 40740b57cec5SDimitry Andric return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); 40750b57cec5SDimitry Andric} 40760b57cec5SDimitry Andric 40770b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 407881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 40790b57cec5SDimitry Andricint 40800b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 40810b57cec5SDimitry Andric size_type __n1, 40820b57cec5SDimitry Andric const basic_string& __str, 40830b57cec5SDimitry Andric size_type __pos2, 40840b57cec5SDimitry Andric size_type __n2) const 40850b57cec5SDimitry Andric{ 40860b57cec5SDimitry Andric return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); 40870b57cec5SDimitry Andric} 40880b57cec5SDimitry Andric 40890b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 409081ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 40910b57cec5SDimitry Andricint 40920b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT 40930b57cec5SDimitry Andric{ 40940b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); 40950b57cec5SDimitry Andric return compare(0, npos, __s, traits_type::length(__s)); 40960b57cec5SDimitry Andric} 40970b57cec5SDimitry Andric 40980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 409981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 41000b57cec5SDimitry Andricint 41010b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 41020b57cec5SDimitry Andric size_type __n1, 41030b57cec5SDimitry Andric const value_type* __s) const 41040b57cec5SDimitry Andric{ 41050b57cec5SDimitry Andric _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); 41060b57cec5SDimitry Andric return compare(__pos1, __n1, __s, traits_type::length(__s)); 41070b57cec5SDimitry Andric} 41080b57cec5SDimitry Andric 41090b57cec5SDimitry Andric// __invariants 41100b57cec5SDimitry Andric 41110b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 411281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 41130b57cec5SDimitry Andricbool 41140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invariants() const 41150b57cec5SDimitry Andric{ 41160b57cec5SDimitry Andric if (size() > capacity()) 41170b57cec5SDimitry Andric return false; 41180b57cec5SDimitry Andric if (capacity() < __min_cap - 1) 41190b57cec5SDimitry Andric return false; 4120e8d8bef9SDimitry Andric if (data() == nullptr) 41210b57cec5SDimitry Andric return false; 4122e8d8bef9SDimitry Andric if (data()[size()] != value_type()) 41230b57cec5SDimitry Andric return false; 41240b57cec5SDimitry Andric return true; 41250b57cec5SDimitry Andric} 41260b57cec5SDimitry Andric 41270b57cec5SDimitry Andric// __clear_and_shrink 41280b57cec5SDimitry Andric 41290b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 413081ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 41310b57cec5SDimitry Andricvoid 41320b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT 41330b57cec5SDimitry Andric{ 41340b57cec5SDimitry Andric clear(); 41350b57cec5SDimitry Andric if(__is_long()) 41360b57cec5SDimitry Andric { 41370b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); 41380b57cec5SDimitry Andric __set_long_cap(0); 41390b57cec5SDimitry Andric __set_short_size(0); 4140e8d8bef9SDimitry Andric traits_type::assign(*__get_short_pointer(), value_type()); 41410b57cec5SDimitry Andric } 41420b57cec5SDimitry Andric} 41430b57cec5SDimitry Andric 41440b57cec5SDimitry Andric// operator== 41450b57cec5SDimitry Andric 41460b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 414781ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 41480b57cec5SDimitry Andricbool 41490b57cec5SDimitry Andricoperator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 41500b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 41510b57cec5SDimitry Andric{ 41520b57cec5SDimitry Andric size_t __lhs_sz = __lhs.size(); 41530b57cec5SDimitry Andric return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), 41540b57cec5SDimitry Andric __rhs.data(), 41550b57cec5SDimitry Andric __lhs_sz) == 0; 41560b57cec5SDimitry Andric} 41570b57cec5SDimitry Andric 41580b57cec5SDimitry Andrictemplate<class _Allocator> 415981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 41600b57cec5SDimitry Andricbool 41610b57cec5SDimitry Andricoperator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, 41620b57cec5SDimitry Andric const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT 41630b57cec5SDimitry Andric{ 41640b57cec5SDimitry Andric size_t __lhs_sz = __lhs.size(); 41650b57cec5SDimitry Andric if (__lhs_sz != __rhs.size()) 41660b57cec5SDimitry Andric return false; 41670b57cec5SDimitry Andric const char* __lp = __lhs.data(); 41680b57cec5SDimitry Andric const char* __rp = __rhs.data(); 41690b57cec5SDimitry Andric if (__lhs.__is_long()) 41700b57cec5SDimitry Andric return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; 41710b57cec5SDimitry Andric for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) 41720b57cec5SDimitry Andric if (*__lp != *__rp) 41730b57cec5SDimitry Andric return false; 41740b57cec5SDimitry Andric return true; 41750b57cec5SDimitry Andric} 41760b57cec5SDimitry Andric 41770b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 417881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 41790b57cec5SDimitry Andricbool 41800b57cec5SDimitry Andricoperator==(const _CharT* __lhs, 41810b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 41820b57cec5SDimitry Andric{ 41830b57cec5SDimitry Andric typedef basic_string<_CharT, _Traits, _Allocator> _String; 41840b57cec5SDimitry Andric _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); 41850b57cec5SDimitry Andric size_t __lhs_len = _Traits::length(__lhs); 41860b57cec5SDimitry Andric if (__lhs_len != __rhs.size()) return false; 41870b57cec5SDimitry Andric return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; 41880b57cec5SDimitry Andric} 41890b57cec5SDimitry Andric 41900b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 419181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 41920b57cec5SDimitry Andricbool 41930b57cec5SDimitry Andricoperator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 41940b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 41950b57cec5SDimitry Andric{ 41960b57cec5SDimitry Andric typedef basic_string<_CharT, _Traits, _Allocator> _String; 41970b57cec5SDimitry Andric _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); 41980b57cec5SDimitry Andric size_t __rhs_len = _Traits::length(__rhs); 41990b57cec5SDimitry Andric if (__rhs_len != __lhs.size()) return false; 42000b57cec5SDimitry Andric return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; 42010b57cec5SDimitry Andric} 42020b57cec5SDimitry Andric 42030b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 420481ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42050b57cec5SDimitry Andricbool 42060b57cec5SDimitry Andricoperator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 42070b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 42080b57cec5SDimitry Andric{ 42090b57cec5SDimitry Andric return !(__lhs == __rhs); 42100b57cec5SDimitry Andric} 42110b57cec5SDimitry Andric 42120b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 421381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42140b57cec5SDimitry Andricbool 42150b57cec5SDimitry Andricoperator!=(const _CharT* __lhs, 42160b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 42170b57cec5SDimitry Andric{ 42180b57cec5SDimitry Andric return !(__lhs == __rhs); 42190b57cec5SDimitry Andric} 42200b57cec5SDimitry Andric 42210b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 422281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42230b57cec5SDimitry Andricbool 42240b57cec5SDimitry Andricoperator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 42250b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 42260b57cec5SDimitry Andric{ 42270b57cec5SDimitry Andric return !(__lhs == __rhs); 42280b57cec5SDimitry Andric} 42290b57cec5SDimitry Andric 42300b57cec5SDimitry Andric// operator< 42310b57cec5SDimitry Andric 42320b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 423381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42340b57cec5SDimitry Andricbool 42350b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 42360b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 42370b57cec5SDimitry Andric{ 42380b57cec5SDimitry Andric return __lhs.compare(__rhs) < 0; 42390b57cec5SDimitry Andric} 42400b57cec5SDimitry Andric 42410b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 424281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42430b57cec5SDimitry Andricbool 42440b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 42450b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 42460b57cec5SDimitry Andric{ 42470b57cec5SDimitry Andric return __lhs.compare(__rhs) < 0; 42480b57cec5SDimitry Andric} 42490b57cec5SDimitry Andric 42500b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 425181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42520b57cec5SDimitry Andricbool 42530b57cec5SDimitry Andricoperator< (const _CharT* __lhs, 42540b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 42550b57cec5SDimitry Andric{ 42560b57cec5SDimitry Andric return __rhs.compare(__lhs) > 0; 42570b57cec5SDimitry Andric} 42580b57cec5SDimitry Andric 42590b57cec5SDimitry Andric// operator> 42600b57cec5SDimitry Andric 42610b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 426281ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42630b57cec5SDimitry Andricbool 42640b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 42650b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 42660b57cec5SDimitry Andric{ 42670b57cec5SDimitry Andric return __rhs < __lhs; 42680b57cec5SDimitry Andric} 42690b57cec5SDimitry Andric 42700b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 427181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42720b57cec5SDimitry Andricbool 42730b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 42740b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 42750b57cec5SDimitry Andric{ 42760b57cec5SDimitry Andric return __rhs < __lhs; 42770b57cec5SDimitry Andric} 42780b57cec5SDimitry Andric 42790b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 428081ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42810b57cec5SDimitry Andricbool 42820b57cec5SDimitry Andricoperator> (const _CharT* __lhs, 42830b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 42840b57cec5SDimitry Andric{ 42850b57cec5SDimitry Andric return __rhs < __lhs; 42860b57cec5SDimitry Andric} 42870b57cec5SDimitry Andric 42880b57cec5SDimitry Andric// operator<= 42890b57cec5SDimitry Andric 42900b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 429181ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 42920b57cec5SDimitry Andricbool 42930b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 42940b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 42950b57cec5SDimitry Andric{ 42960b57cec5SDimitry Andric return !(__rhs < __lhs); 42970b57cec5SDimitry Andric} 42980b57cec5SDimitry Andric 42990b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 430081ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 43010b57cec5SDimitry Andricbool 43020b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 43030b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 43040b57cec5SDimitry Andric{ 43050b57cec5SDimitry Andric return !(__rhs < __lhs); 43060b57cec5SDimitry Andric} 43070b57cec5SDimitry Andric 43080b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 430981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 43100b57cec5SDimitry Andricbool 43110b57cec5SDimitry Andricoperator<=(const _CharT* __lhs, 43120b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 43130b57cec5SDimitry Andric{ 43140b57cec5SDimitry Andric return !(__rhs < __lhs); 43150b57cec5SDimitry Andric} 43160b57cec5SDimitry Andric 43170b57cec5SDimitry Andric// operator>= 43180b57cec5SDimitry Andric 43190b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 432081ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 43210b57cec5SDimitry Andricbool 43220b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 43230b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 43240b57cec5SDimitry Andric{ 43250b57cec5SDimitry Andric return !(__lhs < __rhs); 43260b57cec5SDimitry Andric} 43270b57cec5SDimitry Andric 43280b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 432981ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 43300b57cec5SDimitry Andricbool 43310b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 43320b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 43330b57cec5SDimitry Andric{ 43340b57cec5SDimitry Andric return !(__lhs < __rhs); 43350b57cec5SDimitry Andric} 43360b57cec5SDimitry Andric 43370b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 433881ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI 43390b57cec5SDimitry Andricbool 43400b57cec5SDimitry Andricoperator>=(const _CharT* __lhs, 43410b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 43420b57cec5SDimitry Andric{ 43430b57cec5SDimitry Andric return !(__lhs < __rhs); 43440b57cec5SDimitry Andric} 43450b57cec5SDimitry Andric 43460b57cec5SDimitry Andric// operator + 43470b57cec5SDimitry Andric 43480b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 434981ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 43500b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 43510b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 43520b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) 43530b57cec5SDimitry Andric{ 435481ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 435581ad6265SDimitry Andric auto __lhs_sz = __lhs.size(); 435681ad6265SDimitry Andric auto __rhs_sz = __rhs.size(); 435781ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 435881ad6265SDimitry Andric __lhs_sz + __rhs_sz, 435981ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); 436081ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 436181ad6265SDimitry Andric _Traits::copy(__ptr, __lhs.data(), __lhs_sz); 436281ad6265SDimitry Andric _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); 436381ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); 43640b57cec5SDimitry Andric return __r; 43650b57cec5SDimitry Andric} 43660b57cec5SDimitry Andric 43670b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 436881ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 43690b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 43700b57cec5SDimitry Andricoperator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) 43710b57cec5SDimitry Andric{ 437281ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 437381ad6265SDimitry Andric auto __lhs_sz = _Traits::length(__lhs); 437481ad6265SDimitry Andric auto __rhs_sz = __rhs.size(); 437581ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 437681ad6265SDimitry Andric __lhs_sz + __rhs_sz, 437781ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); 437881ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 437981ad6265SDimitry Andric _Traits::copy(__ptr, __lhs, __lhs_sz); 438081ad6265SDimitry Andric _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); 438181ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); 43820b57cec5SDimitry Andric return __r; 43830b57cec5SDimitry Andric} 43840b57cec5SDimitry Andric 43850b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 438681ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 43870b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 43880b57cec5SDimitry Andricoperator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) 43890b57cec5SDimitry Andric{ 439081ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 439181ad6265SDimitry Andric typename _String::size_type __rhs_sz = __rhs.size(); 439281ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 439381ad6265SDimitry Andric __rhs_sz + 1, 439481ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); 439581ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 439681ad6265SDimitry Andric _Traits::assign(__ptr, 1, __lhs); 439781ad6265SDimitry Andric _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz); 439881ad6265SDimitry Andric _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT()); 43990b57cec5SDimitry Andric return __r; 44000b57cec5SDimitry Andric} 44010b57cec5SDimitry Andric 44020b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 440381ad6265SDimitry Andricinline _LIBCPP_CONSTEXPR_AFTER_CXX17 44040b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44050b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) 44060b57cec5SDimitry Andric{ 440781ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 440881ad6265SDimitry Andric typename _String::size_type __lhs_sz = __lhs.size(); 440981ad6265SDimitry Andric typename _String::size_type __rhs_sz = _Traits::length(__rhs); 441081ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 441181ad6265SDimitry Andric __lhs_sz + __rhs_sz, 441281ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); 441381ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 441481ad6265SDimitry Andric _Traits::copy(__ptr, __lhs.data(), __lhs_sz); 441581ad6265SDimitry Andric _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz); 441681ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); 44170b57cec5SDimitry Andric return __r; 44180b57cec5SDimitry Andric} 44190b57cec5SDimitry Andric 44200b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 442181ad6265SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX17 44220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44230b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) 44240b57cec5SDimitry Andric{ 442581ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 442681ad6265SDimitry Andric typename _String::size_type __lhs_sz = __lhs.size(); 442781ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 442881ad6265SDimitry Andric __lhs_sz + 1, 442981ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); 443081ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 443181ad6265SDimitry Andric _Traits::copy(__ptr, __lhs.data(), __lhs_sz); 443281ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz, 1, __rhs); 443381ad6265SDimitry Andric _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT()); 44340b57cec5SDimitry Andric return __r; 44350b57cec5SDimitry Andric} 44360b57cec5SDimitry Andric 44370b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 44380b57cec5SDimitry Andric 44390b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 444081ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 44410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44420b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) 44430b57cec5SDimitry Andric{ 444481ad6265SDimitry Andric return std::move(__lhs.append(__rhs)); 44450b57cec5SDimitry Andric} 44460b57cec5SDimitry Andric 44470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 444881ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 44490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44500b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) 44510b57cec5SDimitry Andric{ 445281ad6265SDimitry Andric return std::move(__rhs.insert(0, __lhs)); 44530b57cec5SDimitry Andric} 44540b57cec5SDimitry Andric 44550b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 445681ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 44570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44580b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) 44590b57cec5SDimitry Andric{ 446081ad6265SDimitry Andric return std::move(__lhs.append(__rhs)); 44610b57cec5SDimitry Andric} 44620b57cec5SDimitry Andric 44630b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 446481ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 44650b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44660b57cec5SDimitry Andricoperator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) 44670b57cec5SDimitry Andric{ 446881ad6265SDimitry Andric return std::move(__rhs.insert(0, __lhs)); 44690b57cec5SDimitry Andric} 44700b57cec5SDimitry Andric 44710b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 447281ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 44730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44740b57cec5SDimitry Andricoperator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) 44750b57cec5SDimitry Andric{ 44760b57cec5SDimitry Andric __rhs.insert(__rhs.begin(), __lhs); 447781ad6265SDimitry Andric return std::move(__rhs); 44780b57cec5SDimitry Andric} 44790b57cec5SDimitry Andric 44800b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 448181ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 44820b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44830b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) 44840b57cec5SDimitry Andric{ 448581ad6265SDimitry Andric return std::move(__lhs.append(__rhs)); 44860b57cec5SDimitry Andric} 44870b57cec5SDimitry Andric 44880b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 448981ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 44900b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 44910b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) 44920b57cec5SDimitry Andric{ 44930b57cec5SDimitry Andric __lhs.push_back(__rhs); 449481ad6265SDimitry Andric return std::move(__lhs); 44950b57cec5SDimitry Andric} 44960b57cec5SDimitry Andric 44970b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 44980b57cec5SDimitry Andric 44990b57cec5SDimitry Andric// swap 45000b57cec5SDimitry Andric 45010b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 450281ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 45030b57cec5SDimitry Andricvoid 45040b57cec5SDimitry Andricswap(basic_string<_CharT, _Traits, _Allocator>& __lhs, 45050b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __rhs) 45060b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) 45070b57cec5SDimitry Andric{ 45080b57cec5SDimitry Andric __lhs.swap(__rhs); 45090b57cec5SDimitry Andric} 45100b57cec5SDimitry Andric 4511e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); 4512e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); 4513e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); 4514e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); 4515e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10); 45160b57cec5SDimitry Andric 4517e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr); 4518e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr); 4519e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr); 45200b57cec5SDimitry Andric 45210b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(int __val); 45220b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned __val); 45230b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long __val); 45240b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned long __val); 45250b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long long __val); 45260b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(unsigned long long __val); 45270b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(float __val); 45280b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(double __val); 45290b57cec5SDimitry Andric_LIBCPP_FUNC_VIS string to_string(long double __val); 45300b57cec5SDimitry Andric 4531349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 4532e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4533e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4534e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4535e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4536e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10); 45370b57cec5SDimitry Andric 4538e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr); 4539e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr); 4540e8d8bef9SDimitry Andric_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr); 45410b57cec5SDimitry Andric 45420b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(int __val); 45430b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); 45440b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long __val); 45450b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); 45460b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long long __val); 45470b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); 45480b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(float __val); 45490b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(double __val); 45500b57cec5SDimitry Andric_LIBCPP_FUNC_VIS wstring to_wstring(long double __val); 4551349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS 45520b57cec5SDimitry Andric 45530b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4554fe6060f1SDimitry Andric_LIBCPP_TEMPLATE_DATA_VIS 45550b57cec5SDimitry Andricconst typename basic_string<_CharT, _Traits, _Allocator>::size_type 45560b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>::npos; 45570b57cec5SDimitry Andric 45580b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator> 45590b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS 45600b57cec5SDimitry Andric hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> > 456181ad6265SDimitry Andric : public __unary_function<basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t> 45620b57cec5SDimitry Andric{ 45630b57cec5SDimitry Andric size_t 45640b57cec5SDimitry Andric operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT 45650b57cec5SDimitry Andric { return __do_string_hash(__val.data(), __val.data() + __val.size()); } 45660b57cec5SDimitry Andric}; 45670b57cec5SDimitry Andric 45680b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 45690b57cec5SDimitry Andricbasic_ostream<_CharT, _Traits>& 45700b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 45710b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __str); 45720b57cec5SDimitry Andric 45730b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 45740b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 45750b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 45760b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str); 45770b57cec5SDimitry Andric 45780b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 45790b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 45800b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is, 45810b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); 45820b57cec5SDimitry Andric 45830b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 458481ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 45850b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 45860b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is, 45870b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str); 45880b57cec5SDimitry Andric 45890b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 459081ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 45910b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 45920b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is, 45930b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); 45940b57cec5SDimitry Andric 45950b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 459681ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 45970b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 45980b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is, 45990b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str); 46000b57cec5SDimitry Andric 46010b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17 46020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Up> 460381ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 46045ffd83dbSDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 46055ffd83dbSDimitry Andric erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) { 46065ffd83dbSDimitry Andric auto __old_size = __str.size(); 460781ad6265SDimitry Andric __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end()); 46085ffd83dbSDimitry Andric return __old_size - __str.size(); 46095ffd83dbSDimitry Andric} 46100b57cec5SDimitry Andric 46110b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Predicate> 461281ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 46135ffd83dbSDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 46145ffd83dbSDimitry Andric erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, 46155ffd83dbSDimitry Andric _Predicate __pred) { 46165ffd83dbSDimitry Andric auto __old_size = __str.size(); 461781ad6265SDimitry Andric __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), 46185ffd83dbSDimitry Andric __str.end()); 46195ffd83dbSDimitry Andric return __old_size - __str.size(); 46205ffd83dbSDimitry Andric} 46210b57cec5SDimitry Andric#endif 46220b57cec5SDimitry Andric 462381ad6265SDimitry Andric#ifdef _LIBCPP_ENABLE_DEBUG_MODE 46240b57cec5SDimitry Andric 46250b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 46260b57cec5SDimitry Andricbool 46270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const 46280b57cec5SDimitry Andric{ 462981ad6265SDimitry Andric return data() <= std::__to_address(__i->base()) && 463081ad6265SDimitry Andric std::__to_address(__i->base()) < data() + size(); 46310b57cec5SDimitry Andric} 46320b57cec5SDimitry Andric 46330b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 46340b57cec5SDimitry Andricbool 46350b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const 46360b57cec5SDimitry Andric{ 463781ad6265SDimitry Andric return data() < std::__to_address(__i->base()) && 463881ad6265SDimitry Andric std::__to_address(__i->base()) <= data() + size(); 46390b57cec5SDimitry Andric} 46400b57cec5SDimitry Andric 46410b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 46420b57cec5SDimitry Andricbool 46430b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const 46440b57cec5SDimitry Andric{ 464581ad6265SDimitry Andric const value_type* __p = std::__to_address(__i->base()) + __n; 464604eeddc0SDimitry Andric return data() <= __p && __p <= data() + size(); 46470b57cec5SDimitry Andric} 46480b57cec5SDimitry Andric 46490b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 46500b57cec5SDimitry Andricbool 46510b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 46520b57cec5SDimitry Andric{ 465381ad6265SDimitry Andric const value_type* __p = std::__to_address(__i->base()) + __n; 465404eeddc0SDimitry Andric return data() <= __p && __p < data() + size(); 46550b57cec5SDimitry Andric} 46560b57cec5SDimitry Andric 465781ad6265SDimitry Andric#endif // _LIBCPP_ENABLE_DEBUG_MODE 46580b57cec5SDimitry Andric 46590b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11 46600b57cec5SDimitry Andric// Literal suffixes for basic_string [basic.string.literals] 46610b57cec5SDimitry Andricinline namespace literals 46620b57cec5SDimitry Andric{ 46630b57cec5SDimitry Andric inline namespace string_literals 46640b57cec5SDimitry Andric { 466581ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 46660b57cec5SDimitry Andric basic_string<char> operator "" s( const char *__str, size_t __len ) 46670b57cec5SDimitry Andric { 46680b57cec5SDimitry Andric return basic_string<char> (__str, __len); 46690b57cec5SDimitry Andric } 46700b57cec5SDimitry Andric 4671349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 467281ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 46730b57cec5SDimitry Andric basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) 46740b57cec5SDimitry Andric { 46750b57cec5SDimitry Andric return basic_string<wchar_t> (__str, __len); 46760b57cec5SDimitry Andric } 4677349cc55cSDimitry Andric#endif 46780b57cec5SDimitry Andric 4679fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 468081ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI constexpr 46810b57cec5SDimitry Andric basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT 46820b57cec5SDimitry Andric { 46830b57cec5SDimitry Andric return basic_string<char8_t> (__str, __len); 46840b57cec5SDimitry Andric } 46850b57cec5SDimitry Andric#endif 46860b57cec5SDimitry Andric 468781ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 46880b57cec5SDimitry Andric basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) 46890b57cec5SDimitry Andric { 46900b57cec5SDimitry Andric return basic_string<char16_t> (__str, __len); 46910b57cec5SDimitry Andric } 46920b57cec5SDimitry Andric 469381ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 46940b57cec5SDimitry Andric basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) 46950b57cec5SDimitry Andric { 46960b57cec5SDimitry Andric return basic_string<char32_t> (__str, __len); 46970b57cec5SDimitry Andric } 46980eae32dcSDimitry Andric } // namespace string_literals 46990eae32dcSDimitry Andric} // namespace literals 470081ad6265SDimitry Andric 470181ad6265SDimitry Andric#if _LIBCPP_STD_VER > 17 470281ad6265SDimitry Andrictemplate <> 470381ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true; 470481ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 470581ad6265SDimitry Andrictemplate <> 470681ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true; 470781ad6265SDimitry Andric#endif 470881ad6265SDimitry Andric#endif 470981ad6265SDimitry Andric 47100b57cec5SDimitry Andric#endif 47110b57cec5SDimitry Andric 47120b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 47130b57cec5SDimitry Andric 47140b57cec5SDimitry Andric_LIBCPP_POP_MACROS 47150b57cec5SDimitry Andric 47160b57cec5SDimitry Andric#endif // _LIBCPP_STRING 4717