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 16bdd1243dSDimitry Andric#include <compare> 17bdd1243dSDimitry Andric#include <initializer_list> 18bdd1243dSDimitry Andric 190b57cec5SDimitry Andricnamespace std 200b57cec5SDimitry Andric{ 210b57cec5SDimitry Andric 220b57cec5SDimitry Andrictemplate <class stateT> 230b57cec5SDimitry Andricclass fpos 240b57cec5SDimitry Andric{ 250b57cec5SDimitry Andricprivate: 260b57cec5SDimitry Andric stateT st; 270b57cec5SDimitry Andricpublic: 280b57cec5SDimitry Andric fpos(streamoff = streamoff()); 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric operator streamoff() const; 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric stateT state() const; 330b57cec5SDimitry Andric void state(stateT); 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric fpos& operator+=(streamoff); 360b57cec5SDimitry Andric fpos operator+ (streamoff) const; 370b57cec5SDimitry Andric fpos& operator-=(streamoff); 380b57cec5SDimitry Andric fpos operator- (streamoff) const; 390b57cec5SDimitry Andric}; 400b57cec5SDimitry Andric 410b57cec5SDimitry Andrictemplate <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); 420b57cec5SDimitry Andric 430b57cec5SDimitry Andrictemplate <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); 440b57cec5SDimitry Andrictemplate <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); 450b57cec5SDimitry Andric 460b57cec5SDimitry Andrictemplate <class charT> 470b57cec5SDimitry Andricstruct char_traits 480b57cec5SDimitry Andric{ 49bdd1243dSDimitry Andric using char_type = charT; 50bdd1243dSDimitry Andric using int_type = ...; 51bdd1243dSDimitry Andric using off_type = streamoff; 52bdd1243dSDimitry Andric using pos_type = streampos; 53bdd1243dSDimitry Andric using state_type = mbstate_t; 54bdd1243dSDimitry Andric using comparison_category = strong_ordering; // Since C++20 only for the specializations 55bdd1243dSDimitry Andric // char, wchar_t, char8_t, char16_t, and char32_t. 560b57cec5SDimitry Andric 570b57cec5SDimitry Andric static void assign(char_type& c1, const char_type& c2) noexcept; 580b57cec5SDimitry Andric static constexpr bool eq(char_type c1, char_type c2) noexcept; 590b57cec5SDimitry Andric static constexpr bool lt(char_type c1, char_type c2) noexcept; 600b57cec5SDimitry Andric 610b57cec5SDimitry Andric static int compare(const char_type* s1, const char_type* s2, size_t n); 620b57cec5SDimitry Andric static size_t length(const char_type* s); 630b57cec5SDimitry Andric static const char_type* find(const char_type* s, size_t n, const char_type& a); 640b57cec5SDimitry Andric static char_type* move(char_type* s1, const char_type* s2, size_t n); 650b57cec5SDimitry Andric static char_type* copy(char_type* s1, const char_type* s2, size_t n); 660b57cec5SDimitry Andric static char_type* assign(char_type* s, size_t n, char_type a); 670b57cec5SDimitry Andric 680b57cec5SDimitry Andric static constexpr int_type not_eof(int_type c) noexcept; 690b57cec5SDimitry Andric static constexpr char_type to_char_type(int_type c) noexcept; 700b57cec5SDimitry Andric static constexpr int_type to_int_type(char_type c) noexcept; 710b57cec5SDimitry Andric static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; 720b57cec5SDimitry Andric static constexpr int_type eof() noexcept; 730b57cec5SDimitry Andric}; 740b57cec5SDimitry Andric 750b57cec5SDimitry Andrictemplate <> struct char_traits<char>; 760b57cec5SDimitry Andrictemplate <> struct char_traits<wchar_t>; 77fe6060f1SDimitry Andrictemplate <> struct char_traits<char8_t>; // C++20 78fe6060f1SDimitry Andrictemplate <> struct char_traits<char16_t>; 79fe6060f1SDimitry Andrictemplate <> struct char_traits<char32_t>; 800b57cec5SDimitry Andric 810b57cec5SDimitry Andrictemplate<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 820b57cec5SDimitry Andricclass basic_string 830b57cec5SDimitry Andric{ 840b57cec5SDimitry Andricpublic: 850b57cec5SDimitry Andric// types: 860b57cec5SDimitry Andric typedef traits traits_type; 870b57cec5SDimitry Andric typedef typename traits_type::char_type value_type; 880b57cec5SDimitry Andric typedef Allocator allocator_type; 890b57cec5SDimitry Andric typedef typename allocator_type::size_type size_type; 900b57cec5SDimitry Andric typedef typename allocator_type::difference_type difference_type; 910b57cec5SDimitry Andric typedef typename allocator_type::reference reference; 920b57cec5SDimitry Andric typedef typename allocator_type::const_reference const_reference; 930b57cec5SDimitry Andric typedef typename allocator_type::pointer pointer; 940b57cec5SDimitry Andric typedef typename allocator_type::const_pointer const_pointer; 950b57cec5SDimitry Andric typedef implementation-defined iterator; 960b57cec5SDimitry Andric typedef implementation-defined const_iterator; 970b57cec5SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 980b57cec5SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric static const size_type npos = -1; 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric basic_string() 10381ad6265SDimitry Andric noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20 10481ad6265SDimitry Andric explicit basic_string(const allocator_type& a); // constexpr since C++20 10581ad6265SDimitry Andric basic_string(const basic_string& str); // constexpr since C++20 1060b57cec5SDimitry Andric basic_string(basic_string&& str) 10781ad6265SDimitry Andric noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20 1080b57cec5SDimitry Andric basic_string(const basic_string& str, size_type pos, 10981ad6265SDimitry Andric const allocator_type& a = allocator_type()); // constexpr since C++20 1100b57cec5SDimitry Andric basic_string(const basic_string& str, size_type pos, size_type n, 11181ad6265SDimitry Andric const Allocator& a = Allocator()); // constexpr since C++20 112bdd1243dSDimitry Andric constexpr basic_string( 113bdd1243dSDimitry Andric basic_string&& str, size_type pos, const Allocator& a = Allocator()); // since C++23 114bdd1243dSDimitry Andric constexpr basic_string( 115bdd1243dSDimitry Andric basic_string&& str, size_type pos, size_type n, const Allocator& a = Allocator()); // since C++23 1160b57cec5SDimitry Andric template<class T> 11781ad6265SDimitry Andric basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17, constexpr since C++20 1180b57cec5SDimitry Andric template <class T> 11981ad6265SDimitry Andric explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20 12081ad6265SDimitry Andric basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20 12181ad6265SDimitry Andric basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); // constexpr since C++20 122*06c3fb27SDimitry Andric basic_string(nullptr_t) = delete; // C++23 12381ad6265SDimitry Andric basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); // constexpr since C++20 1240b57cec5SDimitry Andric template<class InputIterator> 1250b57cec5SDimitry Andric basic_string(InputIterator begin, InputIterator end, 12681ad6265SDimitry Andric const allocator_type& a = allocator_type()); // constexpr since C++20 127*06c3fb27SDimitry Andric template<container-compatible-range<charT> R> 128*06c3fb27SDimitry Andric constexpr basic_string(from_range_t, R&& rg, const Allocator& a = Allocator()); // since C++23 12981ad6265SDimitry Andric basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20 13081ad6265SDimitry Andric basic_string(const basic_string&, const Allocator&); // constexpr since C++20 13181ad6265SDimitry Andric basic_string(basic_string&&, const Allocator&); // constexpr since C++20 1320b57cec5SDimitry Andric 13381ad6265SDimitry Andric ~basic_string(); // constexpr since C++20 1340b57cec5SDimitry Andric 13581ad6265SDimitry Andric operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20 1360b57cec5SDimitry Andric 13781ad6265SDimitry Andric basic_string& operator=(const basic_string& str); // constexpr since C++20 1380b57cec5SDimitry Andric template <class T> 13981ad6265SDimitry Andric basic_string& operator=(const T& t); // C++17, constexpr since C++20 1400b57cec5SDimitry Andric basic_string& operator=(basic_string&& str) 1410b57cec5SDimitry Andric noexcept( 1420b57cec5SDimitry Andric allocator_type::propagate_on_container_move_assignment::value || 14381ad6265SDimitry Andric allocator_type::is_always_equal::value ); // C++17, constexpr since C++20 14481ad6265SDimitry Andric basic_string& operator=(const value_type* s); // constexpr since C++20 145*06c3fb27SDimitry Andric basic_string& operator=(nullptr_t) = delete; // C++23 14681ad6265SDimitry Andric basic_string& operator=(value_type c); // constexpr since C++20 14781ad6265SDimitry Andric basic_string& operator=(initializer_list<value_type>); // constexpr since C++20 1480b57cec5SDimitry Andric 14981ad6265SDimitry Andric iterator begin() noexcept; // constexpr since C++20 15081ad6265SDimitry Andric const_iterator begin() const noexcept; // constexpr since C++20 15181ad6265SDimitry Andric iterator end() noexcept; // constexpr since C++20 15281ad6265SDimitry Andric const_iterator end() const noexcept; // constexpr since C++20 1530b57cec5SDimitry Andric 15481ad6265SDimitry Andric reverse_iterator rbegin() noexcept; // constexpr since C++20 15581ad6265SDimitry Andric const_reverse_iterator rbegin() const noexcept; // constexpr since C++20 15681ad6265SDimitry Andric reverse_iterator rend() noexcept; // constexpr since C++20 15781ad6265SDimitry Andric const_reverse_iterator rend() const noexcept; // constexpr since C++20 1580b57cec5SDimitry Andric 15981ad6265SDimitry Andric const_iterator cbegin() const noexcept; // constexpr since C++20 16081ad6265SDimitry Andric const_iterator cend() const noexcept; // constexpr since C++20 16181ad6265SDimitry Andric const_reverse_iterator crbegin() const noexcept; // constexpr since C++20 16281ad6265SDimitry Andric const_reverse_iterator crend() const noexcept; // constexpr since C++20 1630b57cec5SDimitry Andric 16481ad6265SDimitry Andric size_type size() const noexcept; // constexpr since C++20 16581ad6265SDimitry Andric size_type length() const noexcept; // constexpr since C++20 16681ad6265SDimitry Andric size_type max_size() const noexcept; // constexpr since C++20 16781ad6265SDimitry Andric size_type capacity() const noexcept; // constexpr since C++20 1680b57cec5SDimitry Andric 16981ad6265SDimitry Andric void resize(size_type n, value_type c); // constexpr since C++20 17081ad6265SDimitry Andric void resize(size_type n); // constexpr since C++20 1710b57cec5SDimitry Andric 17204eeddc0SDimitry Andric template<class Operation> 17304eeddc0SDimitry Andric constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23 17404eeddc0SDimitry Andric 17581ad6265SDimitry Andric void reserve(size_type res_arg); // constexpr since C++20 176e8d8bef9SDimitry Andric void reserve(); // deprecated in C++20 17781ad6265SDimitry Andric void shrink_to_fit(); // constexpr since C++20 17881ad6265SDimitry Andric void clear() noexcept; // constexpr since C++20 17981ad6265SDimitry Andric bool empty() const noexcept; // constexpr since C++20 1800b57cec5SDimitry Andric 18181ad6265SDimitry Andric const_reference operator[](size_type pos) const; // constexpr since C++20 18281ad6265SDimitry Andric reference operator[](size_type pos); // constexpr since C++20 1830b57cec5SDimitry Andric 18481ad6265SDimitry Andric const_reference at(size_type n) const; // constexpr since C++20 18581ad6265SDimitry Andric reference at(size_type n); // constexpr since C++20 1860b57cec5SDimitry Andric 18781ad6265SDimitry Andric basic_string& operator+=(const basic_string& str); // constexpr since C++20 1880b57cec5SDimitry Andric template <class T> 18981ad6265SDimitry Andric basic_string& operator+=(const T& t); // C++17, constexpr since C++20 19081ad6265SDimitry Andric basic_string& operator+=(const value_type* s); // constexpr since C++20 19181ad6265SDimitry Andric basic_string& operator+=(value_type c); // constexpr since C++20 19281ad6265SDimitry Andric basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20 1930b57cec5SDimitry Andric 19481ad6265SDimitry Andric basic_string& append(const basic_string& str); // constexpr since C++20 1950b57cec5SDimitry Andric template <class T> 19681ad6265SDimitry Andric basic_string& append(const T& t); // C++17, constexpr since C++20 19781ad6265SDimitry Andric basic_string& append(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 1980b57cec5SDimitry Andric template <class T> 19981ad6265SDimitry Andric basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 20081ad6265SDimitry Andric basic_string& append(const value_type* s, size_type n); // constexpr since C++20 20181ad6265SDimitry Andric basic_string& append(const value_type* s); // constexpr since C++20 20281ad6265SDimitry Andric basic_string& append(size_type n, value_type c); // constexpr since C++20 2030b57cec5SDimitry Andric template<class InputIterator> 20481ad6265SDimitry Andric basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20 205*06c3fb27SDimitry Andric template<container-compatible-range<charT> R> 206*06c3fb27SDimitry Andric constexpr basic_string& append_range(R&& rg); // C++23 20781ad6265SDimitry Andric basic_string& append(initializer_list<value_type>); // constexpr since C++20 2080b57cec5SDimitry Andric 20981ad6265SDimitry Andric void push_back(value_type c); // constexpr since C++20 21081ad6265SDimitry Andric void pop_back(); // constexpr since C++20 21181ad6265SDimitry Andric reference front(); // constexpr since C++20 21281ad6265SDimitry Andric const_reference front() const; // constexpr since C++20 21381ad6265SDimitry Andric reference back(); // constexpr since C++20 21481ad6265SDimitry Andric const_reference back() const; // constexpr since C++20 2150b57cec5SDimitry Andric 21681ad6265SDimitry Andric basic_string& assign(const basic_string& str); // constexpr since C++20 2170b57cec5SDimitry Andric template <class T> 21881ad6265SDimitry Andric basic_string& assign(const T& t); // C++17, constexpr since C++20 21981ad6265SDimitry Andric basic_string& assign(basic_string&& str); // constexpr since C++20 22081ad6265SDimitry Andric basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 2210b57cec5SDimitry Andric template <class T> 22281ad6265SDimitry Andric basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 22381ad6265SDimitry Andric basic_string& assign(const value_type* s, size_type n); // constexpr since C++20 22481ad6265SDimitry Andric basic_string& assign(const value_type* s); // constexpr since C++20 22581ad6265SDimitry Andric basic_string& assign(size_type n, value_type c); // constexpr since C++20 2260b57cec5SDimitry Andric template<class InputIterator> 22781ad6265SDimitry Andric basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20 228*06c3fb27SDimitry Andric template<container-compatible-range<charT> R> 229*06c3fb27SDimitry Andric constexpr basic_string& assign_range(R&& rg); // C++23 23081ad6265SDimitry Andric basic_string& assign(initializer_list<value_type>); // constexpr since C++20 2310b57cec5SDimitry Andric 23281ad6265SDimitry Andric basic_string& insert(size_type pos1, const basic_string& str); // constexpr since C++20 2330b57cec5SDimitry Andric template <class T> 23481ad6265SDimitry Andric basic_string& insert(size_type pos1, const T& t); // constexpr since C++20 2350b57cec5SDimitry Andric basic_string& insert(size_type pos1, const basic_string& str, 23681ad6265SDimitry Andric size_type pos2, size_type n); // constexpr since C++20 2370b57cec5SDimitry Andric template <class T> 23881ad6265SDimitry Andric basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20 23981ad6265SDimitry Andric basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20 24081ad6265SDimitry Andric basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20 24181ad6265SDimitry Andric basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20 24281ad6265SDimitry Andric iterator insert(const_iterator p, value_type c); // constexpr since C++20 24381ad6265SDimitry Andric iterator insert(const_iterator p, size_type n, value_type c); // constexpr since C++20 2440b57cec5SDimitry Andric template<class InputIterator> 24581ad6265SDimitry Andric iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20 246*06c3fb27SDimitry Andric template<container-compatible-range<charT> R> 247*06c3fb27SDimitry Andric constexpr iterator insert_range(const_iterator p, R&& rg); // C++23 24881ad6265SDimitry Andric iterator insert(const_iterator p, initializer_list<value_type>); // constexpr since C++20 2490b57cec5SDimitry Andric 25081ad6265SDimitry Andric basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20 25181ad6265SDimitry Andric iterator erase(const_iterator position); // constexpr since C++20 25281ad6265SDimitry Andric iterator erase(const_iterator first, const_iterator last); // constexpr since C++20 2530b57cec5SDimitry Andric 25481ad6265SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const basic_string& str); // constexpr since C++20 2550b57cec5SDimitry Andric template <class T> 25681ad6265SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17, constexpr since C++20 2570b57cec5SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const basic_string& str, 25881ad6265SDimitry Andric size_type pos2, size_type n2=npos); // C++14, constexpr since C++20 2590b57cec5SDimitry Andric template <class T> 2600b57cec5SDimitry Andric basic_string& replace(size_type pos1, size_type n1, const T& t, 26181ad6265SDimitry Andric size_type pos2, size_type n); // C++17, constexpr since C++20 26281ad6265SDimitry Andric basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20 26381ad6265SDimitry Andric basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20 26481ad6265SDimitry Andric basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20 26581ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); // constexpr since C++20 2660b57cec5SDimitry Andric template <class T> 26781ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20 26881ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20 26981ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20 27081ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); // constexpr since C++20 2710b57cec5SDimitry Andric template<class InputIterator> 27281ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20 273*06c3fb27SDimitry Andric template<container-compatible-range<charT> R> 274*06c3fb27SDimitry Andric constexpr basic_string& replace_with_range(const_iterator i1, const_iterator i2, R&& rg); // C++23 27581ad6265SDimitry Andric basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20 2760b57cec5SDimitry Andric 27781ad6265SDimitry Andric size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20 278bdd1243dSDimitry Andric basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr in C++20, removed in C++23 279bdd1243dSDimitry Andric basic_string substr(size_type pos = 0, size_type n = npos) const&; // since C++23 280bdd1243dSDimitry Andric constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&; // since C++23 2810b57cec5SDimitry Andric void swap(basic_string& str) 2820b57cec5SDimitry Andric noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || 28381ad6265SDimitry Andric allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20 2840b57cec5SDimitry Andric 28581ad6265SDimitry Andric const value_type* c_str() const noexcept; // constexpr since C++20 28681ad6265SDimitry Andric const value_type* data() const noexcept; // constexpr since C++20 28781ad6265SDimitry Andric value_type* data() noexcept; // C++17, constexpr since C++20 2880b57cec5SDimitry Andric 28981ad6265SDimitry Andric allocator_type get_allocator() const noexcept; // constexpr since C++20 2900b57cec5SDimitry Andric 29181ad6265SDimitry Andric size_type find(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 2920b57cec5SDimitry Andric template <class T> 29381ad6265SDimitry Andric size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 29481ad6265SDimitry Andric size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 29581ad6265SDimitry Andric size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 29681ad6265SDimitry Andric size_type find(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 2970b57cec5SDimitry Andric 29881ad6265SDimitry Andric size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 2990b57cec5SDimitry Andric template <class T> 30081ad6265SDimitry Andric size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 30181ad6265SDimitry Andric size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 30281ad6265SDimitry Andric size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 30381ad6265SDimitry Andric size_type rfind(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 3040b57cec5SDimitry Andric 30581ad6265SDimitry Andric size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 3060b57cec5SDimitry Andric template <class T> 30781ad6265SDimitry 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 30881ad6265SDimitry Andric size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 30981ad6265SDimitry Andric size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 31081ad6265SDimitry Andric size_type find_first_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 3110b57cec5SDimitry Andric 31281ad6265SDimitry Andric size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 3130b57cec5SDimitry Andric template <class T> 31481ad6265SDimitry 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 31581ad6265SDimitry Andric size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 31681ad6265SDimitry Andric size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 31781ad6265SDimitry Andric size_type find_last_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 3180b57cec5SDimitry Andric 31981ad6265SDimitry Andric size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 3200b57cec5SDimitry Andric template <class T> 32181ad6265SDimitry 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 32281ad6265SDimitry Andric size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 32381ad6265SDimitry Andric size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 32481ad6265SDimitry Andric size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 3250b57cec5SDimitry Andric 32681ad6265SDimitry Andric size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 3270b57cec5SDimitry Andric template <class T> 32881ad6265SDimitry 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 32981ad6265SDimitry Andric size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 33081ad6265SDimitry Andric size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 33181ad6265SDimitry Andric size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 3320b57cec5SDimitry Andric 33381ad6265SDimitry Andric int compare(const basic_string& str) const noexcept; // constexpr since C++20 3340b57cec5SDimitry Andric template <class T> 33581ad6265SDimitry Andric int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 33681ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const basic_string& str) const; // constexpr since C++20 3370b57cec5SDimitry Andric template <class T> 33881ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const T& t) const; // C++17, constexpr since C++20 3390b57cec5SDimitry Andric int compare(size_type pos1, size_type n1, const basic_string& str, 34081ad6265SDimitry Andric size_type pos2, size_type n2=npos) const; // C++14, constexpr since C++20 3410b57cec5SDimitry Andric template <class T> 3420b57cec5SDimitry Andric int compare(size_type pos1, size_type n1, const T& t, 34381ad6265SDimitry Andric size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20 34481ad6265SDimitry Andric int compare(const value_type* s) const noexcept; // constexpr since C++20 34581ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20 34681ad6265SDimitry Andric int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; // constexpr since C++20 3470b57cec5SDimitry Andric 34881ad6265SDimitry Andric constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 34981ad6265SDimitry Andric constexpr bool starts_with(charT c) const noexcept; // C++20 35081ad6265SDimitry Andric constexpr bool starts_with(const charT* s) const; // C++20 35181ad6265SDimitry Andric constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 35281ad6265SDimitry Andric constexpr bool ends_with(charT c) const noexcept; // C++20 35381ad6265SDimitry Andric constexpr bool ends_with(const charT* s) const; // C++20 354e8d8bef9SDimitry Andric 355*06c3fb27SDimitry Andric constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++23 356*06c3fb27SDimitry Andric constexpr bool contains(charT c) const noexcept; // C++23 357*06c3fb27SDimitry Andric constexpr bool contains(const charT* s) const; // C++23 3580b57cec5SDimitry Andric}; 3590b57cec5SDimitry Andric 3600b57cec5SDimitry Andrictemplate<class InputIterator, 3610b57cec5SDimitry Andric class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 3620b57cec5SDimitry Andricbasic_string(InputIterator, InputIterator, Allocator = Allocator()) 3630b57cec5SDimitry Andric -> basic_string<typename iterator_traits<InputIterator>::value_type, 3640b57cec5SDimitry Andric char_traits<typename iterator_traits<InputIterator>::value_type>, 3650b57cec5SDimitry Andric Allocator>; // C++17 3660b57cec5SDimitry Andric 367*06c3fb27SDimitry Andrictemplate<ranges::input_range R, 368*06c3fb27SDimitry Andric class Allocator = allocator<ranges::range_value_t<R>>> 369*06c3fb27SDimitry Andric basic_string(from_range_t, R&&, Allocator = Allocator()) 370*06c3fb27SDimitry Andric -> basic_string<ranges::range_value_t<R>, char_traits<ranges::range_value_t<R>>, 371*06c3fb27SDimitry Andric Allocator>; // C++23 372*06c3fb27SDimitry Andric 373*06c3fb27SDimitry Andrictemplate<class charT, 374*06c3fb27SDimitry Andric class traits, 375*06c3fb27SDimitry Andric class Allocator = allocator<charT>> 376*06c3fb27SDimitry Andric explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator()) 377*06c3fb27SDimitry Andric -> basic_string<charT, traits, Allocator>; // C++17 378*06c3fb27SDimitry Andric 379*06c3fb27SDimitry Andrictemplate<class charT, 380*06c3fb27SDimitry Andric class traits, 381*06c3fb27SDimitry Andric class Allocator = allocator<charT>> 382*06c3fb27SDimitry Andric basic_string(basic_string_view<charT, traits>, 383*06c3fb27SDimitry Andric typename see below::size_type, typename see below::size_type, 384*06c3fb27SDimitry Andric const Allocator& = Allocator()) 385*06c3fb27SDimitry Andric -> basic_string<charT, traits, Allocator>; // C++17 386*06c3fb27SDimitry Andric 3870b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3880b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 3890b57cec5SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, 39081ad6265SDimitry Andric const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20 3910b57cec5SDimitry Andric 3920b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3930b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 39481ad6265SDimitry Andricoperator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); // constexpr since C++20 3950b57cec5SDimitry Andric 3960b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 3970b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 39881ad6265SDimitry Andricoperator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20 3990b57cec5SDimitry Andric 4000b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4010b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 40281ad6265SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // constexpr since C++20 4030b57cec5SDimitry Andric 4040b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4050b57cec5SDimitry Andricbasic_string<charT, traits, Allocator> 40681ad6265SDimitry Andricoperator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); // 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> 413bdd1243dSDimitry Andricbool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4140b57cec5SDimitry Andric 4150b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 41681ad6265SDimitry Andricbool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* 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, 420bdd1243dSDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4210b57cec5SDimitry Andric 4220b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 423bdd1243dSDimitry Andricbool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4240b57cec5SDimitry Andric 4250b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 426bdd1243dSDimitry Andricbool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4290b57cec5SDimitry Andricbool operator< (const basic_string<charT, traits, Allocator>& lhs, 430bdd1243dSDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4310b57cec5SDimitry Andric 4320b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 433bdd1243dSDimitry Andricbool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 4340b57cec5SDimitry Andric 4350b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 436bdd1243dSDimitry Andricbool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4370b57cec5SDimitry Andric 4380b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4390b57cec5SDimitry Andricbool operator> (const basic_string<charT, traits, Allocator>& lhs, 440bdd1243dSDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4410b57cec5SDimitry Andric 4420b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 443bdd1243dSDimitry Andricbool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 4440b57cec5SDimitry Andric 4450b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 446bdd1243dSDimitry Andricbool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4490b57cec5SDimitry Andricbool operator<=(const basic_string<charT, traits, Allocator>& lhs, 450bdd1243dSDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4510b57cec5SDimitry Andric 4520b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 453bdd1243dSDimitry Andricbool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 4540b57cec5SDimitry Andric 4550b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 456bdd1243dSDimitry Andricbool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4570b57cec5SDimitry Andric 4580b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4590b57cec5SDimitry Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs, 460bdd1243dSDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 4610b57cec5SDimitry Andric 4620b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 463bdd1243dSDimitry Andricbool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 4640b57cec5SDimitry Andric 4650b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 466bdd1243dSDimitry Andricbool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 467bdd1243dSDimitry Andric 468bdd1243dSDimitry Andrictemplate<class charT, class traits, class Allocator> // since C++20 469bdd1243dSDimitry Andricconstexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, 470bdd1243dSDimitry Andric const basic_string<charT, traits, Allocator>& rhs) noexcept; 471bdd1243dSDimitry Andric 472bdd1243dSDimitry Andrictemplate<class charT, class traits, class Allocator> // since C++20 473bdd1243dSDimitry Andricconstexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, 474bdd1243dSDimitry Andric const charT* rhs) noexcept; 4750b57cec5SDimitry Andric 4760b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4770b57cec5SDimitry Andricvoid swap(basic_string<charT, traits, Allocator>& lhs, 4780b57cec5SDimitry Andric basic_string<charT, traits, Allocator>& rhs) 47981ad6265SDimitry Andric noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20 4800b57cec5SDimitry Andric 4810b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4820b57cec5SDimitry Andricbasic_istream<charT, traits>& 4830b57cec5SDimitry Andricoperator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); 4840b57cec5SDimitry Andric 4850b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4860b57cec5SDimitry Andricbasic_ostream<charT, traits>& 4870b57cec5SDimitry Andricoperator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); 4880b57cec5SDimitry Andric 4890b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4900b57cec5SDimitry Andricbasic_istream<charT, traits>& 4910b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, 4920b57cec5SDimitry Andric charT delim); 4930b57cec5SDimitry Andric 4940b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator> 4950b57cec5SDimitry Andricbasic_istream<charT, traits>& 4960b57cec5SDimitry Andricgetline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); 4970b57cec5SDimitry Andric 4980b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class U> 4995ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type 5005ffd83dbSDimitry Andricerase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20 5010b57cec5SDimitry Andrictemplate<class charT, class traits, class Allocator, class Predicate> 5025ffd83dbSDimitry Andrictypename basic_string<charT, traits, Allocator>::size_type 5035ffd83dbSDimitry Andricerase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20 5040b57cec5SDimitry Andric 5050b57cec5SDimitry Andrictypedef basic_string<char> string; 5060b57cec5SDimitry Andrictypedef basic_string<wchar_t> wstring; 507fe6060f1SDimitry Andrictypedef basic_string<char8_t> u8string; // C++20 5080b57cec5SDimitry Andrictypedef basic_string<char16_t> u16string; 5090b57cec5SDimitry Andrictypedef basic_string<char32_t> u32string; 5100b57cec5SDimitry Andric 511e8d8bef9SDimitry Andricint stoi (const string& str, size_t* idx = nullptr, int base = 10); 512e8d8bef9SDimitry Andriclong stol (const string& str, size_t* idx = nullptr, int base = 10); 513e8d8bef9SDimitry Andricunsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10); 514e8d8bef9SDimitry Andriclong long stoll (const string& str, size_t* idx = nullptr, int base = 10); 515e8d8bef9SDimitry Andricunsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10); 5160b57cec5SDimitry Andric 517e8d8bef9SDimitry Andricfloat stof (const string& str, size_t* idx = nullptr); 518e8d8bef9SDimitry Andricdouble stod (const string& str, size_t* idx = nullptr); 519e8d8bef9SDimitry Andriclong double stold(const string& str, size_t* idx = nullptr); 5200b57cec5SDimitry Andric 5210b57cec5SDimitry Andricstring to_string(int val); 5220b57cec5SDimitry Andricstring to_string(unsigned val); 5230b57cec5SDimitry Andricstring to_string(long val); 5240b57cec5SDimitry Andricstring to_string(unsigned long val); 5250b57cec5SDimitry Andricstring to_string(long long val); 5260b57cec5SDimitry Andricstring to_string(unsigned long long val); 5270b57cec5SDimitry Andricstring to_string(float val); 5280b57cec5SDimitry Andricstring to_string(double val); 5290b57cec5SDimitry Andricstring to_string(long double val); 5300b57cec5SDimitry Andric 531e8d8bef9SDimitry Andricint stoi (const wstring& str, size_t* idx = nullptr, int base = 10); 532e8d8bef9SDimitry Andriclong stol (const wstring& str, size_t* idx = nullptr, int base = 10); 533e8d8bef9SDimitry Andricunsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10); 534e8d8bef9SDimitry Andriclong long stoll (const wstring& str, size_t* idx = nullptr, int base = 10); 535e8d8bef9SDimitry Andricunsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10); 5360b57cec5SDimitry Andric 537e8d8bef9SDimitry Andricfloat stof (const wstring& str, size_t* idx = nullptr); 538e8d8bef9SDimitry Andricdouble stod (const wstring& str, size_t* idx = nullptr); 539e8d8bef9SDimitry Andriclong double stold(const wstring& str, size_t* idx = nullptr); 5400b57cec5SDimitry Andric 5410b57cec5SDimitry Andricwstring to_wstring(int val); 5420b57cec5SDimitry Andricwstring to_wstring(unsigned val); 5430b57cec5SDimitry Andricwstring to_wstring(long val); 5440b57cec5SDimitry Andricwstring to_wstring(unsigned long val); 5450b57cec5SDimitry Andricwstring to_wstring(long long val); 5460b57cec5SDimitry Andricwstring to_wstring(unsigned long long val); 5470b57cec5SDimitry Andricwstring to_wstring(float val); 5480b57cec5SDimitry Andricwstring to_wstring(double val); 5490b57cec5SDimitry Andricwstring to_wstring(long double val); 5500b57cec5SDimitry Andric 5510b57cec5SDimitry Andrictemplate <> struct hash<string>; 552fe6060f1SDimitry Andrictemplate <> struct hash<u8string>; // C++20 5530b57cec5SDimitry Andrictemplate <> struct hash<u16string>; 5540b57cec5SDimitry Andrictemplate <> struct hash<u32string>; 5550b57cec5SDimitry Andrictemplate <> struct hash<wstring>; 5560b57cec5SDimitry Andric 55781ad6265SDimitry Andricbasic_string<char> operator""s( const char *str, size_t len ); // C++14, constexpr since C++20 55881ad6265SDimitry Andricbasic_string<wchar_t> operator""s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20 55981ad6265SDimitry Andricconstexpr basic_string<char8_t> operator""s( const char8_t *str, size_t len ); // C++20 56081ad6265SDimitry Andricbasic_string<char16_t> operator""s( const char16_t *str, size_t len ); // C++14, constexpr since C++20 56181ad6265SDimitry Andricbasic_string<char32_t> operator""s( const char32_t *str, size_t len ); // C++14, constexpr since C++20 5620b57cec5SDimitry Andric 5630b57cec5SDimitry Andric} // std 5640b57cec5SDimitry Andric 5650b57cec5SDimitry Andric*/ 5660b57cec5SDimitry Andric 56781ad6265SDimitry Andric#include <__algorithm/max.h> 56881ad6265SDimitry Andric#include <__algorithm/min.h> 56981ad6265SDimitry Andric#include <__algorithm/remove.h> 57081ad6265SDimitry Andric#include <__algorithm/remove_if.h> 57181ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler 5720b57cec5SDimitry Andric#include <__config> 57381ad6265SDimitry Andric#include <__format/enable_insertable.h> 57481ad6265SDimitry Andric#include <__functional/hash.h> 57581ad6265SDimitry Andric#include <__functional/unary_function.h> 576bdd1243dSDimitry Andric#include <__fwd/string.h> 57781ad6265SDimitry Andric#include <__ios/fpos.h> 57881ad6265SDimitry Andric#include <__iterator/distance.h> 57981ad6265SDimitry Andric#include <__iterator/iterator_traits.h> 58081ad6265SDimitry Andric#include <__iterator/reverse_iterator.h> 581fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h> 582*06c3fb27SDimitry Andric#include <__memory/addressof.h> 58381ad6265SDimitry Andric#include <__memory/allocate_at_least.h> 584bdd1243dSDimitry Andric#include <__memory/allocator.h> 585bdd1243dSDimitry Andric#include <__memory/allocator_traits.h> 586bdd1243dSDimitry Andric#include <__memory/compressed_pair.h> 587bdd1243dSDimitry Andric#include <__memory/construct_at.h> 588bdd1243dSDimitry Andric#include <__memory/pointer_traits.h> 589972a253aSDimitry Andric#include <__memory/swap_allocator.h> 590bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h> 591*06c3fb27SDimitry Andric#include <__ranges/access.h> 592*06c3fb27SDimitry Andric#include <__ranges/concepts.h> 593*06c3fb27SDimitry Andric#include <__ranges/container_compatible_range.h> 594*06c3fb27SDimitry Andric#include <__ranges/from_range.h> 595*06c3fb27SDimitry Andric#include <__ranges/size.h> 59681ad6265SDimitry Andric#include <__string/char_traits.h> 59781ad6265SDimitry Andric#include <__string/extern_template_lists.h> 598bdd1243dSDimitry Andric#include <__type_traits/is_allocator.h> 599*06c3fb27SDimitry Andric#include <__type_traits/is_array.h> 600*06c3fb27SDimitry Andric#include <__type_traits/is_convertible.h> 601*06c3fb27SDimitry Andric#include <__type_traits/is_nothrow_default_constructible.h> 602*06c3fb27SDimitry Andric#include <__type_traits/is_nothrow_move_assignable.h> 603*06c3fb27SDimitry Andric#include <__type_traits/is_same.h> 604*06c3fb27SDimitry Andric#include <__type_traits/is_standard_layout.h> 605*06c3fb27SDimitry Andric#include <__type_traits/is_trivial.h> 606bdd1243dSDimitry Andric#include <__type_traits/noexcept_move_assign_container.h> 607*06c3fb27SDimitry Andric#include <__type_traits/remove_cvref.h> 608*06c3fb27SDimitry Andric#include <__type_traits/void_t.h> 60981ad6265SDimitry Andric#include <__utility/auto_cast.h> 610*06c3fb27SDimitry Andric#include <__utility/declval.h> 611*06c3fb27SDimitry Andric#include <__utility/forward.h> 612*06c3fb27SDimitry Andric#include <__utility/is_pointer_in_range.h> 61381ad6265SDimitry Andric#include <__utility/move.h> 61481ad6265SDimitry Andric#include <__utility/swap.h> 61581ad6265SDimitry Andric#include <__utility/unreachable.h> 61681ad6265SDimitry Andric#include <climits> 61781ad6265SDimitry Andric#include <cstdint> 618fe6060f1SDimitry Andric#include <cstdio> // EOF 619fe6060f1SDimitry Andric#include <cstring> 62081ad6265SDimitry Andric#include <limits> 6210b57cec5SDimitry Andric#include <stdexcept> 622fe6060f1SDimitry Andric#include <string_view> 6230b57cec5SDimitry Andric#include <version> 624fe6060f1SDimitry Andric 625349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 626349cc55cSDimitry Andric# include <cwchar> 627349cc55cSDimitry Andric#endif 628349cc55cSDimitry Andric 62981ad6265SDimitry Andric// standard-mandated includes 63081ad6265SDimitry Andric 63181ad6265SDimitry Andric// [iterator.range] 63281ad6265SDimitry Andric#include <__iterator/access.h> 63381ad6265SDimitry Andric#include <__iterator/data.h> 63481ad6265SDimitry Andric#include <__iterator/empty.h> 63581ad6265SDimitry Andric#include <__iterator/reverse_access.h> 63681ad6265SDimitry Andric#include <__iterator/size.h> 63781ad6265SDimitry Andric 63881ad6265SDimitry Andric// [string.syn] 63981ad6265SDimitry Andric#include <compare> 64081ad6265SDimitry Andric#include <initializer_list> 64181ad6265SDimitry Andric 6420b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 6430b57cec5SDimitry Andric# pragma GCC system_header 6440b57cec5SDimitry Andric#endif 6450b57cec5SDimitry Andric 6460b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS 6470b57cec5SDimitry Andric#include <__undef_macros> 6480b57cec5SDimitry Andric 6490b57cec5SDimitry Andric 6500b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 6510b57cec5SDimitry Andric 6520b57cec5SDimitry Andric// basic_string 6530b57cec5SDimitry Andric 6540b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 6550b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 656bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 6570b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, 6580b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __y); 6590b57cec5SDimitry Andric 6600b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 661bdd1243dSDimitry Andric_LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 6620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6630b57cec5SDimitry Andricoperator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); 6640b57cec5SDimitry Andric 6650b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 666bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 6670b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6680b57cec5SDimitry Andricoperator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); 6690b57cec5SDimitry Andric 6700b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 671bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 6720b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6730b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); 6740b57cec5SDimitry Andric 6750b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 676bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 6770b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 6780b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); 6790b57cec5SDimitry Andric 680*06c3fb27SDimitry Andricextern template _LIBCPP_EXPORTED_FROM_ABI string operator+ 681*06c3fb27SDimitry Andric <char, char_traits<char>, allocator<char> >(char const*, string const&); 6820b57cec5SDimitry Andric 6830b57cec5SDimitry Andrictemplate <class _Iter> 684fe6060f1SDimitry Andricstruct __string_is_trivial_iterator : public false_type {}; 685fe6060f1SDimitry Andric 686fe6060f1SDimitry Andrictemplate <class _Tp> 687fe6060f1SDimitry Andricstruct __string_is_trivial_iterator<_Tp*> 688fe6060f1SDimitry Andric : public is_arithmetic<_Tp> {}; 6890b57cec5SDimitry Andric 6900b57cec5SDimitry Andrictemplate <class _Iter> 691fe6060f1SDimitry Andricstruct __string_is_trivial_iterator<__wrap_iter<_Iter> > 692fe6060f1SDimitry Andric : public __string_is_trivial_iterator<_Iter> {}; 6930b57cec5SDimitry Andric 6940b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Tp> 6955ffd83dbSDimitry Andricstruct __can_be_converted_to_string_view : public _BoolConstant< 6965ffd83dbSDimitry Andric is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && 6975ffd83dbSDimitry Andric !is_convertible<const _Tp&, const _CharT*>::value 6985ffd83dbSDimitry Andric > {}; 6990b57cec5SDimitry Andric 70081ad6265SDimitry Andricstruct __uninitialized_size_tag {}; 701*06c3fb27SDimitry Andricstruct __init_with_sentinel_tag {}; 702e8d8bef9SDimitry Andric 7030b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 704bdd1243dSDimitry Andricclass basic_string 7050b57cec5SDimitry Andric{ 7060b57cec5SDimitry Andricpublic: 7070b57cec5SDimitry Andric typedef basic_string __self; 7080b57cec5SDimitry Andric typedef basic_string_view<_CharT, _Traits> __self_view; 7090b57cec5SDimitry Andric typedef _Traits traits_type; 7100b57cec5SDimitry Andric typedef _CharT value_type; 7110b57cec5SDimitry Andric typedef _Allocator allocator_type; 7120b57cec5SDimitry Andric typedef allocator_traits<allocator_type> __alloc_traits; 7130b57cec5SDimitry Andric typedef typename __alloc_traits::size_type size_type; 7140b57cec5SDimitry Andric typedef typename __alloc_traits::difference_type difference_type; 7150b57cec5SDimitry Andric typedef value_type& reference; 7160b57cec5SDimitry Andric typedef const value_type& const_reference; 7170b57cec5SDimitry Andric typedef typename __alloc_traits::pointer pointer; 7180b57cec5SDimitry Andric typedef typename __alloc_traits::const_pointer const_pointer; 7190b57cec5SDimitry Andric 7200b57cec5SDimitry Andric static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); 7210b57cec5SDimitry Andric static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); 7220b57cec5SDimitry Andric static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); 7230b57cec5SDimitry Andric static_assert(( is_same<_CharT, typename traits_type::char_type>::value), 7240b57cec5SDimitry Andric "traits_type::char_type must be the same type as CharT"); 7250b57cec5SDimitry Andric static_assert(( is_same<typename allocator_type::value_type, value_type>::value), 7260b57cec5SDimitry Andric "Allocator::value_type must be same type as value_type"); 7270b57cec5SDimitry Andric 728bdd1243dSDimitry Andric static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, 729bdd1243dSDimitry Andric "[allocator.requirements] states that rebinding an allocator to the same type should result in the " 730bdd1243dSDimitry Andric "original allocator"); 731bdd1243dSDimitry Andric 732bdd1243dSDimitry Andric // TODO: Implement iterator bounds checking without requiring the global database. 7330b57cec5SDimitry Andric typedef __wrap_iter<pointer> iterator; 7340b57cec5SDimitry Andric typedef __wrap_iter<const_pointer> const_iterator; 73581ad6265SDimitry Andric typedef std::reverse_iterator<iterator> reverse_iterator; 73681ad6265SDimitry Andric typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 7370b57cec5SDimitry Andric 7380b57cec5SDimitry Andricprivate: 73981ad6265SDimitry Andric static_assert(CHAR_BIT == 8, "This implementation assumes that one byte contains 8 bits"); 7400b57cec5SDimitry Andric 7410b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 7420b57cec5SDimitry Andric 7430b57cec5SDimitry Andric struct __long 7440b57cec5SDimitry Andric { 7450b57cec5SDimitry Andric pointer __data_; 7460b57cec5SDimitry Andric size_type __size_; 74781ad6265SDimitry Andric size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; 74881ad6265SDimitry Andric size_type __is_long_ : 1; 7490b57cec5SDimitry Andric }; 7500b57cec5SDimitry Andric 7510b57cec5SDimitry Andric enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? 7520b57cec5SDimitry Andric (sizeof(__long) - 1)/sizeof(value_type) : 2}; 7530b57cec5SDimitry Andric 7540b57cec5SDimitry Andric struct __short 7550b57cec5SDimitry Andric { 7560b57cec5SDimitry Andric value_type __data_[__min_cap]; 75781ad6265SDimitry Andric unsigned char __padding_[sizeof(value_type) - 1]; 75881ad6265SDimitry Andric unsigned char __size_ : 7; 75981ad6265SDimitry Andric unsigned char __is_long_ : 1; 7600b57cec5SDimitry Andric }; 7610b57cec5SDimitry Andric 76281ad6265SDimitry Andric// The __endian_factor is required because the field we use to store the size 76381ad6265SDimitry Andric// has one fewer bit than it would if it were not a bitfield. 76481ad6265SDimitry Andric// 76581ad6265SDimitry Andric// If the LSB is used to store the short-flag in the short string representation, 76681ad6265SDimitry Andric// we have to multiply the size by two when it is stored and divide it by two when 76781ad6265SDimitry Andric// it is loaded to make sure that we always store an even number. In the long string 76881ad6265SDimitry Andric// representation, we can ignore this because we can assume that we always allocate 76981ad6265SDimitry Andric// an even amount of value_types. 77081ad6265SDimitry Andric// 77181ad6265SDimitry Andric// If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2. 77281ad6265SDimitry Andric// This does not impact the short string representation, since we never need the MSB 77381ad6265SDimitry Andric// for representing the size of a short string anyway. 77481ad6265SDimitry Andric 77581ad6265SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN 77681ad6265SDimitry Andric static const size_type __endian_factor = 2; 7770b57cec5SDimitry Andric#else 77881ad6265SDimitry Andric static const size_type __endian_factor = 1; 77981ad6265SDimitry Andric#endif 7800b57cec5SDimitry Andric 78181ad6265SDimitry Andric#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 78281ad6265SDimitry Andric 78381ad6265SDimitry Andric#ifdef _LIBCPP_BIG_ENDIAN 78481ad6265SDimitry Andric static const size_type __endian_factor = 1; 78581ad6265SDimitry Andric#else 78681ad6265SDimitry Andric static const size_type __endian_factor = 2; 78781ad6265SDimitry Andric#endif 78881ad6265SDimitry Andric 78981ad6265SDimitry Andric // Attribute 'packed' is used to keep the layout compatible with the 79081ad6265SDimitry Andric // previous definition that did not use bit fields. This is because on 79181ad6265SDimitry Andric // some platforms bit fields have a default size rather than the actual 79281ad6265SDimitry Andric // size used, e.g., it is 4 bytes on AIX. See D128285 for details. 7930b57cec5SDimitry Andric struct __long 7940b57cec5SDimitry Andric { 79581ad6265SDimitry Andric struct _LIBCPP_PACKED { 79681ad6265SDimitry Andric size_type __is_long_ : 1; 79781ad6265SDimitry Andric size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; 79881ad6265SDimitry Andric }; 7990b57cec5SDimitry Andric size_type __size_; 8000b57cec5SDimitry Andric pointer __data_; 8010b57cec5SDimitry Andric }; 8020b57cec5SDimitry Andric 8030b57cec5SDimitry Andric enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? 8040b57cec5SDimitry Andric (sizeof(__long) - 1)/sizeof(value_type) : 2}; 8050b57cec5SDimitry Andric 8060b57cec5SDimitry Andric struct __short 8070b57cec5SDimitry Andric { 80881ad6265SDimitry Andric struct _LIBCPP_PACKED { 80981ad6265SDimitry Andric unsigned char __is_long_ : 1; 81081ad6265SDimitry Andric unsigned char __size_ : 7; 8110b57cec5SDimitry Andric }; 81281ad6265SDimitry Andric char __padding_[sizeof(value_type) - 1]; 8130b57cec5SDimitry Andric value_type __data_[__min_cap]; 8140b57cec5SDimitry Andric }; 8150b57cec5SDimitry Andric 8160b57cec5SDimitry Andric#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT 8170b57cec5SDimitry Andric 81881ad6265SDimitry Andric static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size."); 81981ad6265SDimitry Andric 8200b57cec5SDimitry Andric union __ulx{__long __lx; __short __lxx;}; 8210b57cec5SDimitry Andric 8220b57cec5SDimitry Andric enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; 8230b57cec5SDimitry Andric 8240b57cec5SDimitry Andric struct __raw 8250b57cec5SDimitry Andric { 8260b57cec5SDimitry Andric size_type __words[__n_words]; 8270b57cec5SDimitry Andric }; 8280b57cec5SDimitry Andric 8290b57cec5SDimitry Andric struct __rep 8300b57cec5SDimitry Andric { 8310b57cec5SDimitry Andric union 8320b57cec5SDimitry Andric { 8330b57cec5SDimitry Andric __long __l; 8340b57cec5SDimitry Andric __short __s; 8350b57cec5SDimitry Andric __raw __r; 8360b57cec5SDimitry Andric }; 8370b57cec5SDimitry Andric }; 8380b57cec5SDimitry Andric 8390b57cec5SDimitry Andric __compressed_pair<__rep, allocator_type> __r_; 8400b57cec5SDimitry Andric 84181ad6265SDimitry Andric // Construct a string with the given allocator and enough storage to hold `__size` characters, but 84281ad6265SDimitry Andric // don't initialize the characters. The contents of the string, including the null terminator, must be 84381ad6265SDimitry Andric // initialized separately. 844bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 84581ad6265SDimitry Andric explicit basic_string(__uninitialized_size_tag, size_type __size, const allocator_type& __a) 84681ad6265SDimitry Andric : __r_(__default_init_tag(), __a) { 84781ad6265SDimitry Andric if (__size > max_size()) 84881ad6265SDimitry Andric __throw_length_error(); 84981ad6265SDimitry Andric if (__fits_in_sso(__size)) { 850bdd1243dSDimitry Andric __r_.first() = __rep(); 85181ad6265SDimitry Andric __set_short_size(__size); 85281ad6265SDimitry Andric } else { 85381ad6265SDimitry Andric auto __capacity = __recommend(__size) + 1; 85481ad6265SDimitry Andric auto __allocation = __alloc_traits::allocate(__alloc(), __capacity); 85581ad6265SDimitry Andric __begin_lifetime(__allocation, __capacity); 85681ad6265SDimitry Andric __set_long_cap(__capacity); 85781ad6265SDimitry Andric __set_long_pointer(__allocation); 85881ad6265SDimitry Andric __set_long_size(__size); 85981ad6265SDimitry Andric } 860*06c3fb27SDimitry Andric } 861*06c3fb27SDimitry Andric 862*06c3fb27SDimitry Andric template <class _Iter, class _Sent> 863*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 864*06c3fb27SDimitry Andric basic_string(__init_with_sentinel_tag, _Iter __first, _Sent __last, const allocator_type& __a) 865*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 866*06c3fb27SDimitry Andric __init_with_sentinel(std::move(__first), std::move(__last)); 86781ad6265SDimitry Andric } 86881ad6265SDimitry Andric 869bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iterator(pointer __p) { 870*06c3fb27SDimitry Andric return iterator(__p); 871bdd1243dSDimitry Andric } 872bdd1243dSDimitry Andric 873bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_const_iterator(const_pointer __p) const { 874*06c3fb27SDimitry Andric return const_iterator(__p); 875bdd1243dSDimitry Andric } 876bdd1243dSDimitry Andric 8770b57cec5SDimitry Andricpublic: 878bdd1243dSDimitry Andric _LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1; 8790b57cec5SDimitry Andric 880bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() 881bdd1243dSDimitry Andric _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) 882bdd1243dSDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) { 883bdd1243dSDimitry Andric __default_init(); 884bdd1243dSDimitry Andric } 8850b57cec5SDimitry Andric 886bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const allocator_type& __a) 8870b57cec5SDimitry Andric#if _LIBCPP_STD_VER <= 14 888bdd1243dSDimitry Andric _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) 8890b57cec5SDimitry Andric#else 890bdd1243dSDimitry Andric _NOEXCEPT 8910b57cec5SDimitry Andric#endif 892bdd1243dSDimitry Andric : __r_(__default_init_tag(), __a) { 893bdd1243dSDimitry Andric __default_init(); 894bdd1243dSDimitry Andric } 8950b57cec5SDimitry Andric 896*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str) 897*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) { 898*06c3fb27SDimitry Andric if (!__str.__is_long()) 899*06c3fb27SDimitry Andric __r_.first() = __str.__r_.first(); 900*06c3fb27SDimitry Andric else 901*06c3fb27SDimitry Andric __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); 902*06c3fb27SDimitry Andric } 903*06c3fb27SDimitry Andric 904*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, const allocator_type& __a) 905*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 906*06c3fb27SDimitry Andric if (!__str.__is_long()) 907*06c3fb27SDimitry Andric __r_.first() = __str.__r_.first(); 908*06c3fb27SDimitry Andric else 909*06c3fb27SDimitry Andric __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); 910*06c3fb27SDimitry Andric } 9110b57cec5SDimitry Andric 9120b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 913bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str) 9140b57cec5SDimitry Andric# if _LIBCPP_STD_VER <= 14 915bdd1243dSDimitry Andric _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) 9160b57cec5SDimitry Andric# else 917bdd1243dSDimitry Andric _NOEXCEPT 9180b57cec5SDimitry Andric# endif 919bdd1243dSDimitry Andric : __r_(std::move(__str.__r_)) { 920bdd1243dSDimitry Andric __str.__default_init(); 921bdd1243dSDimitry Andric } 9220b57cec5SDimitry Andric 923bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a) 924bdd1243dSDimitry Andric : __r_(__default_init_tag(), __a) { 925bdd1243dSDimitry Andric if (__str.__is_long() && __a != __str.__alloc()) // copy, not move 926bdd1243dSDimitry Andric __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); 927bdd1243dSDimitry Andric else { 928bdd1243dSDimitry Andric if (__libcpp_is_constant_evaluated()) 929bdd1243dSDimitry Andric __r_.first() = __rep(); 930bdd1243dSDimitry Andric __r_.first() = __str.__r_.first(); 931bdd1243dSDimitry Andric __str.__default_init(); 932bdd1243dSDimitry Andric } 933bdd1243dSDimitry Andric } 9340b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 9350b57cec5SDimitry Andric 936*06c3fb27SDimitry Andric template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> 937bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) 938bdd1243dSDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) { 939*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "basic_string(const char*) detected nullptr"); 9400b57cec5SDimitry Andric __init(__s, traits_type::length(__s)); 9410b57cec5SDimitry Andric } 9420b57cec5SDimitry Andric 943*06c3fb27SDimitry Andric template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> 944*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a) 945*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 946*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); 947*06c3fb27SDimitry Andric __init(__s, traits_type::length(__s)); 948*06c3fb27SDimitry Andric } 9490b57cec5SDimitry Andric 950*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 951fe6060f1SDimitry Andric basic_string(nullptr_t) = delete; 952fe6060f1SDimitry Andric#endif 953fe6060f1SDimitry Andric 954bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) 955bdd1243dSDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) { 956*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); 957bdd1243dSDimitry Andric __init(__s, __n); 958bdd1243dSDimitry Andric } 959bdd1243dSDimitry Andric 960bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 961bdd1243dSDimitry Andric basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) 962bdd1243dSDimitry Andric : __r_(__default_init_tag(), __a) { 963*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, 964*06c3fb27SDimitry Andric "basic_string(const char*, n, allocator) detected nullptr"); 965bdd1243dSDimitry Andric __init(__s, __n); 966bdd1243dSDimitry Andric } 967bdd1243dSDimitry Andric 968bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) 969bdd1243dSDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) { 970bdd1243dSDimitry Andric __init(__n, __c); 971bdd1243dSDimitry Andric } 972bdd1243dSDimitry Andric 973*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 974bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 975bdd1243dSDimitry Andric basic_string(basic_string&& __str, size_type __pos, const _Allocator& __alloc = _Allocator()) 976bdd1243dSDimitry Andric : basic_string(std::move(__str), __pos, npos, __alloc) {} 977bdd1243dSDimitry Andric 978bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 979bdd1243dSDimitry Andric basic_string(basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator()) 980bdd1243dSDimitry Andric : __r_(__default_init_tag(), __alloc) { 981bdd1243dSDimitry Andric if (__pos > __str.size()) 982bdd1243dSDimitry Andric __throw_out_of_range(); 983bdd1243dSDimitry Andric 984bdd1243dSDimitry Andric auto __len = std::min<size_type>(__n, __str.size() - __pos); 985bdd1243dSDimitry Andric if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc()) { 986bdd1243dSDimitry Andric __r_.first() = __str.__r_.first(); 987bdd1243dSDimitry Andric __str.__default_init(); 988bdd1243dSDimitry Andric 989bdd1243dSDimitry Andric _Traits::move(data(), data() + __pos, __len); 990bdd1243dSDimitry Andric __set_size(__len); 991bdd1243dSDimitry Andric _Traits::assign(data()[__len], value_type()); 992bdd1243dSDimitry Andric } else { 993bdd1243dSDimitry Andric // Perform a copy because the allocators are not compatible. 994bdd1243dSDimitry Andric __init(__str.data() + __pos, __len); 995bdd1243dSDimitry Andric } 996bdd1243dSDimitry Andric } 997bdd1243dSDimitry Andric#endif 9980b57cec5SDimitry Andric 999*06c3fb27SDimitry Andric template <__enable_if_t<__is_allocator<_Allocator>::value, int> = 0> 1000*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a) 1001*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 1002*06c3fb27SDimitry Andric __init(__n, __c); 1003*06c3fb27SDimitry Andric } 10040b57cec5SDimitry Andric 1005bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 1006*06c3fb27SDimitry Andric basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator()) 1007*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 1008*06c3fb27SDimitry Andric size_type __str_sz = __str.size(); 1009*06c3fb27SDimitry Andric if (__pos > __str_sz) 1010*06c3fb27SDimitry Andric __throw_out_of_range(); 1011*06c3fb27SDimitry Andric __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); 1012*06c3fb27SDimitry Andric } 10130b57cec5SDimitry Andric 1014bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1015bdd1243dSDimitry Andric basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator()) 1016bdd1243dSDimitry Andric : __r_(__default_init_tag(), __a) { 1017bdd1243dSDimitry Andric size_type __str_sz = __str.size(); 1018bdd1243dSDimitry Andric if (__pos > __str_sz) 1019bdd1243dSDimitry Andric __throw_out_of_range(); 1020bdd1243dSDimitry Andric __init(__str.data() + __pos, __str_sz - __pos); 1021bdd1243dSDimitry Andric } 10220b57cec5SDimitry Andric 1023bdd1243dSDimitry Andric template <class _Tp, 1024*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1025*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1026*06c3fb27SDimitry Andric int> = 0> 1027bdd1243dSDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 1028*06c3fb27SDimitry Andric basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()) 1029*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 1030*06c3fb27SDimitry Andric __self_view __sv0 = __t; 1031*06c3fb27SDimitry Andric __self_view __sv = __sv0.substr(__pos, __n); 1032*06c3fb27SDimitry Andric __init(__sv.data(), __sv.size()); 1033*06c3fb27SDimitry Andric } 10340b57cec5SDimitry Andric 1035bdd1243dSDimitry Andric template <class _Tp, 1036*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1037*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1038*06c3fb27SDimitry Andric int> = 0> 1039*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const _Tp& __t) 1040*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) { 1041*06c3fb27SDimitry Andric __self_view __sv = __t; 1042*06c3fb27SDimitry Andric __init(__sv.data(), __sv.size()); 1043*06c3fb27SDimitry Andric } 1044bdd1243dSDimitry Andric 1045bdd1243dSDimitry Andric template <class _Tp, 1046*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1047*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1048*06c3fb27SDimitry Andric int> = 0> 1049bdd1243dSDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( 1050*06c3fb27SDimitry Andric const _Tp& __t, const allocator_type& __a) 1051*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 1052*06c3fb27SDimitry Andric __self_view __sv = __t; 1053*06c3fb27SDimitry Andric __init(__sv.data(), __sv.size()); 1054*06c3fb27SDimitry Andric } 10550b57cec5SDimitry Andric 1056*06c3fb27SDimitry Andric template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0> 1057bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) 1058bdd1243dSDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) { 1059bdd1243dSDimitry Andric __init(__first, __last); 1060bdd1243dSDimitry Andric } 1061bdd1243dSDimitry Andric 1062*06c3fb27SDimitry Andric template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0> 1063bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1064bdd1243dSDimitry Andric basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) 1065bdd1243dSDimitry Andric : __r_(__default_init_tag(), __a) { 1066bdd1243dSDimitry Andric __init(__first, __last); 1067bdd1243dSDimitry Andric } 1068bdd1243dSDimitry Andric 1069*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1070*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_CharT> _Range> 1071*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 1072*06c3fb27SDimitry Andric basic_string(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type()) 1073*06c3fb27SDimitry Andric : __r_(__default_init_tag(), __a) { 1074*06c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 1075*06c3fb27SDimitry Andric __init_with_size(ranges::begin(__range), ranges::end(__range), ranges::distance(__range)); 1076*06c3fb27SDimitry Andric } else { 1077*06c3fb27SDimitry Andric __init_with_sentinel(ranges::begin(__range), ranges::end(__range)); 1078*06c3fb27SDimitry Andric } 1079*06c3fb27SDimitry Andric } 1080*06c3fb27SDimitry Andric#endif 1081*06c3fb27SDimitry Andric 10820b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1083bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) 1084bdd1243dSDimitry Andric : __r_(__default_init_tag(), __default_init_tag()) { 1085bdd1243dSDimitry Andric __init(__il.begin(), __il.end()); 1086bdd1243dSDimitry Andric } 1087bdd1243dSDimitry Andric 1088bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a) 1089bdd1243dSDimitry Andric : __r_(__default_init_tag(), __a) { 1090bdd1243dSDimitry Andric __init(__il.begin(), __il.end()); 1091bdd1243dSDimitry Andric } 10920b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 10930b57cec5SDimitry Andric 1094*06c3fb27SDimitry Andric inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string() { 1095*06c3fb27SDimitry Andric if (__is_long()) 1096*06c3fb27SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 1097*06c3fb27SDimitry Andric } 10980b57cec5SDimitry Andric 1099bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11000b57cec5SDimitry Andric operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } 11010b57cec5SDimitry Andric 1102bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const basic_string& __str); 11030b57cec5SDimitry Andric 1104*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1105*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, int> = 0> 1106bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) { 110781ad6265SDimitry Andric __self_view __sv = __t; 110881ad6265SDimitry Andric return assign(__sv); 110981ad6265SDimitry Andric } 11100b57cec5SDimitry Andric 11110b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1112bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(basic_string&& __str) 1113bdd1243dSDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { 1114bdd1243dSDimitry Andric __move_assign(__str, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>()); 1115bdd1243dSDimitry Andric return *this; 1116bdd1243dSDimitry Andric } 1117bdd1243dSDimitry Andric 1118bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11190b57cec5SDimitry Andric basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} 11200b57cec5SDimitry Andric#endif 1121bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 112281ad6265SDimitry Andric basic_string& operator=(const value_type* __s) {return assign(__s);} 1123*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1124fe6060f1SDimitry Andric basic_string& operator=(nullptr_t) = delete; 1125fe6060f1SDimitry Andric#endif 1126bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c); 11270b57cec5SDimitry Andric 1128bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11290b57cec5SDimitry Andric iterator begin() _NOEXCEPT 1130bdd1243dSDimitry Andric {return __make_iterator(__get_pointer());} 1131bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11320b57cec5SDimitry Andric const_iterator begin() const _NOEXCEPT 1133bdd1243dSDimitry Andric {return __make_const_iterator(__get_pointer());} 1134bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11350b57cec5SDimitry Andric iterator end() _NOEXCEPT 1136bdd1243dSDimitry Andric {return __make_iterator(__get_pointer() + size());} 1137bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11380b57cec5SDimitry Andric const_iterator end() const _NOEXCEPT 1139bdd1243dSDimitry Andric {return __make_const_iterator(__get_pointer() + size());} 114081ad6265SDimitry Andric 1141bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11420b57cec5SDimitry Andric reverse_iterator rbegin() _NOEXCEPT 11430b57cec5SDimitry Andric {return reverse_iterator(end());} 1144bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11450b57cec5SDimitry Andric const_reverse_iterator rbegin() const _NOEXCEPT 11460b57cec5SDimitry Andric {return const_reverse_iterator(end());} 1147bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11480b57cec5SDimitry Andric reverse_iterator rend() _NOEXCEPT 11490b57cec5SDimitry Andric {return reverse_iterator(begin());} 1150bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11510b57cec5SDimitry Andric const_reverse_iterator rend() const _NOEXCEPT 11520b57cec5SDimitry Andric {return const_reverse_iterator(begin());} 11530b57cec5SDimitry Andric 1154bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11550b57cec5SDimitry Andric const_iterator cbegin() const _NOEXCEPT 11560b57cec5SDimitry Andric {return begin();} 1157bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11580b57cec5SDimitry Andric const_iterator cend() const _NOEXCEPT 11590b57cec5SDimitry Andric {return end();} 1160bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11610b57cec5SDimitry Andric const_reverse_iterator crbegin() const _NOEXCEPT 11620b57cec5SDimitry Andric {return rbegin();} 1163bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 11640b57cec5SDimitry Andric const_reverse_iterator crend() const _NOEXCEPT 11650b57cec5SDimitry Andric {return rend();} 11660b57cec5SDimitry Andric 1167bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT 11680b57cec5SDimitry Andric {return __is_long() ? __get_long_size() : __get_short_size();} 1169bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT {return size();} 1170bdd1243dSDimitry Andric 1171bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT { 1172bdd1243dSDimitry Andric size_type __m = __alloc_traits::max_size(__alloc()); 1173bdd1243dSDimitry Andric if (__m <= std::numeric_limits<size_type>::max() / 2) { 1174bdd1243dSDimitry Andric return __m - __alignment; 1175bdd1243dSDimitry Andric } else { 1176bdd1243dSDimitry Andric bool __uses_lsb = __endian_factor == 2; 1177bdd1243dSDimitry Andric return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment; 1178bdd1243dSDimitry Andric } 1179bdd1243dSDimitry Andric } 1180bdd1243dSDimitry Andric 1181bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT { 118281ad6265SDimitry Andric return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1; 118381ad6265SDimitry Andric } 11840b57cec5SDimitry Andric 1185bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n, value_type __c); 1186bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n) { resize(__n, value_type()); } 11870b57cec5SDimitry Andric 1188bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __requested_capacity); 118904eeddc0SDimitry Andric 1190*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 119104eeddc0SDimitry Andric template <class _Op> 119204eeddc0SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 119304eeddc0SDimitry Andric void resize_and_overwrite(size_type __n, _Op __op) { 119404eeddc0SDimitry Andric __resize_default_init(__n); 119581ad6265SDimitry Andric __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n))); 119604eeddc0SDimitry Andric } 119704eeddc0SDimitry Andric#endif 119804eeddc0SDimitry Andric 1199bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __resize_default_init(size_type __n); 12000b57cec5SDimitry Andric 120181ad6265SDimitry Andric _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); } 1202bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT; 1203bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT; 120481ad6265SDimitry Andric 1205bdd1243dSDimitry Andric _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 12060b57cec5SDimitry Andric bool empty() const _NOEXCEPT {return size() == 0;} 12070b57cec5SDimitry Andric 1208bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __pos) const _NOEXCEPT { 1209*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos <= size(), "string index out of bounds"); 1210bdd1243dSDimitry Andric return *(data() + __pos); 1211bdd1243dSDimitry Andric } 12120b57cec5SDimitry Andric 1213bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __pos) _NOEXCEPT { 1214*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos <= size(), "string index out of bounds"); 1215bdd1243dSDimitry Andric return *(__get_pointer() + __pos); 1216bdd1243dSDimitry Andric } 12170b57cec5SDimitry Andric 1218bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const; 1219bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n); 1220bdd1243dSDimitry Andric 1221bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const basic_string& __str) { 122281ad6265SDimitry Andric return append(__str); 122381ad6265SDimitry Andric } 12240b57cec5SDimitry Andric 1225*06c3fb27SDimitry Andric template <class _Tp, 1226*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1227*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string >::value, 1228*06c3fb27SDimitry Andric int> = 0> 1229*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 123081ad6265SDimitry Andric operator+=(const _Tp& __t) { 123181ad6265SDimitry Andric __self_view __sv = __t; return append(__sv); 123281ad6265SDimitry Andric } 123381ad6265SDimitry Andric 1234bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const value_type* __s) { 123581ad6265SDimitry Andric return append(__s); 123681ad6265SDimitry Andric } 123781ad6265SDimitry Andric 1238bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(value_type __c) { 123981ad6265SDimitry Andric push_back(__c); 124081ad6265SDimitry Andric return *this; 124181ad6265SDimitry Andric } 124281ad6265SDimitry Andric 12430b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1244bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 124581ad6265SDimitry Andric basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); } 12460b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 12470b57cec5SDimitry Andric 1248bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const basic_string& __str) { 1249bdd1243dSDimitry Andric return append(__str.data(), __str.size()); 1250bdd1243dSDimitry Andric } 12510b57cec5SDimitry Andric 1252*06c3fb27SDimitry Andric template <class _Tp, 1253*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1254*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1255*06c3fb27SDimitry Andric int> = 0> 1256*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1257*06c3fb27SDimitry Andric append(const _Tp& __t) { 1258*06c3fb27SDimitry Andric __self_view __sv = __t; 1259*06c3fb27SDimitry Andric return append(__sv.data(), __sv.size()); 1260*06c3fb27SDimitry Andric } 1261*06c3fb27SDimitry Andric 1262bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos); 12630b57cec5SDimitry Andric 1264*06c3fb27SDimitry Andric template <class _Tp, 1265*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1266*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1267*06c3fb27SDimitry Andric int> = 0> 1268bdd1243dSDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 1269*06c3fb27SDimitry Andric 12700b57cec5SDimitry Andric basic_string& 12710b57cec5SDimitry Andric append(const _Tp& __t, size_type __pos, size_type __n = npos); 1272*06c3fb27SDimitry Andric 1273bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n); 1274bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s); 1275bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(size_type __n, value_type __c); 12760b57cec5SDimitry Andric 1277bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 12780b57cec5SDimitry Andric void __append_default_init(size_type __n); 12790b57cec5SDimitry Andric 1280*06c3fb27SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 1281*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 12820b57cec5SDimitry Andric append(_InputIterator __first, _InputIterator __last) { 12830b57cec5SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 12840b57cec5SDimitry Andric append(__temp.data(), __temp.size()); 12850b57cec5SDimitry Andric return *this; 12860b57cec5SDimitry Andric } 1287*06c3fb27SDimitry Andric 1288*06c3fb27SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 1289*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1290fe6060f1SDimitry Andric append(_ForwardIterator __first, _ForwardIterator __last); 12910b57cec5SDimitry Andric 1292*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1293*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_CharT> _Range> 1294*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1295*06c3fb27SDimitry Andric constexpr basic_string& append_range(_Range&& __range) { 1296*06c3fb27SDimitry Andric insert_range(end(), std::forward<_Range>(__range)); 1297*06c3fb27SDimitry Andric return *this; 1298*06c3fb27SDimitry Andric } 1299*06c3fb27SDimitry Andric#endif 1300*06c3fb27SDimitry Andric 13010b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1302bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 13030b57cec5SDimitry Andric basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} 13040b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 13050b57cec5SDimitry Andric 1306bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(value_type __c); 1307bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back(); 1308bdd1243dSDimitry Andric 1309bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() _NOEXCEPT { 1310*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string::front(): string is empty"); 1311bdd1243dSDimitry Andric return *__get_pointer(); 1312bdd1243dSDimitry Andric } 1313bdd1243dSDimitry Andric 1314bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _NOEXCEPT { 1315*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string::front(): string is empty"); 1316bdd1243dSDimitry Andric return *data(); 1317bdd1243dSDimitry Andric } 1318bdd1243dSDimitry Andric 1319bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _NOEXCEPT { 1320*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string::back(): string is empty"); 1321bdd1243dSDimitry Andric return *(__get_pointer() + size() - 1); 1322bdd1243dSDimitry Andric } 1323bdd1243dSDimitry Andric 1324bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const _NOEXCEPT { 1325*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string::back(): string is empty"); 1326bdd1243dSDimitry Andric return *(data() + size() - 1); 1327bdd1243dSDimitry Andric } 13280b57cec5SDimitry Andric 1329*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1330*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1331*06c3fb27SDimitry Andric assign(const _Tp& __t) { 1332*06c3fb27SDimitry Andric __self_view __sv = __t; 1333*06c3fb27SDimitry Andric return assign(__sv.data(), __sv.size()); 1334*06c3fb27SDimitry Andric } 1335*06c3fb27SDimitry Andric 1336bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 13370b57cec5SDimitry Andric basic_string& assign(const basic_string& __str) { return *this = __str; } 13380b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1339bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 13400b57cec5SDimitry Andric basic_string& assign(basic_string&& __str) 13410b57cec5SDimitry Andric _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) 134281ad6265SDimitry Andric {*this = std::move(__str); return *this;} 13430b57cec5SDimitry Andric#endif 1344bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); 1345*06c3fb27SDimitry Andric 1346*06c3fb27SDimitry Andric template <class _Tp, 1347*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1348*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1349*06c3fb27SDimitry Andric int> = 0> 1350*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 13510b57cec5SDimitry Andric assign(const _Tp& __t, size_type __pos, size_type __n = npos); 1352*06c3fb27SDimitry Andric 1353bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s, size_type __n); 1354bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s); 1355bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(size_type __n, value_type __c); 1356*06c3fb27SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 1357*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 13580b57cec5SDimitry Andric assign(_InputIterator __first, _InputIterator __last); 1359*06c3fb27SDimitry Andric 1360*06c3fb27SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 1361*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 13620b57cec5SDimitry Andric assign(_ForwardIterator __first, _ForwardIterator __last); 1363*06c3fb27SDimitry Andric 1364*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1365*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_CharT> _Range> 1366*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1367*06c3fb27SDimitry Andric constexpr basic_string& assign_range(_Range&& __range) { 1368*06c3fb27SDimitry Andric if constexpr (__string_is_trivial_iterator<ranges::iterator_t<_Range>>::value && 1369*06c3fb27SDimitry Andric (ranges::forward_range<_Range> || ranges::sized_range<_Range>)) { 1370*06c3fb27SDimitry Andric size_type __n = static_cast<size_type>(ranges::distance(__range)); 1371*06c3fb27SDimitry Andric __assign_trivial(ranges::begin(__range), ranges::end(__range), __n); 1372*06c3fb27SDimitry Andric 1373*06c3fb27SDimitry Andric } else { 1374*06c3fb27SDimitry Andric __assign_with_sentinel(ranges::begin(__range), ranges::end(__range)); 1375*06c3fb27SDimitry Andric } 1376*06c3fb27SDimitry Andric 1377*06c3fb27SDimitry Andric return *this; 1378*06c3fb27SDimitry Andric } 1379*06c3fb27SDimitry Andric#endif 1380*06c3fb27SDimitry Andric 13810b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1382bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 13830b57cec5SDimitry Andric basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} 13840b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 13850b57cec5SDimitry Andric 1386bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1387bdd1243dSDimitry Andric insert(size_type __pos1, const basic_string& __str) { 1388bdd1243dSDimitry Andric return insert(__pos1, __str.data(), __str.size()); 1389bdd1243dSDimitry Andric } 13900b57cec5SDimitry Andric 1391*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1392*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1393*06c3fb27SDimitry Andric insert(size_type __pos1, const _Tp& __t) { 1394*06c3fb27SDimitry Andric __self_view __sv = __t; 1395*06c3fb27SDimitry Andric return insert(__pos1, __sv.data(), __sv.size()); 1396*06c3fb27SDimitry Andric } 13970b57cec5SDimitry Andric 1398*06c3fb27SDimitry Andric template <class _Tp, 1399*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1400*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1401*06c3fb27SDimitry Andric int> = 0> 1402*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 14030b57cec5SDimitry Andric insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n = npos); 1404*06c3fb27SDimitry Andric 1405*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1406*06c3fb27SDimitry Andric insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n = npos); 1407bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s, size_type __n); 1408bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s); 1409bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c); 1410bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c); 1411bdd1243dSDimitry Andric 1412*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1413*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_CharT> _Range> 1414*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1415*06c3fb27SDimitry Andric constexpr iterator insert_range(const_iterator __position, _Range&& __range) { 1416*06c3fb27SDimitry Andric if constexpr (ranges::forward_range<_Range> || ranges::sized_range<_Range>) { 1417*06c3fb27SDimitry Andric auto __n = static_cast<size_type>(ranges::distance(__range)); 1418*06c3fb27SDimitry Andric return __insert_with_size(__position, ranges::begin(__range), ranges::end(__range), __n); 1419*06c3fb27SDimitry Andric 1420*06c3fb27SDimitry Andric } else { 1421*06c3fb27SDimitry Andric basic_string __temp(from_range, std::forward<_Range>(__range), __alloc()); 1422*06c3fb27SDimitry Andric return insert(__position, __temp.data(), __temp.data() + __temp.size()); 1423*06c3fb27SDimitry Andric } 1424*06c3fb27SDimitry Andric } 1425*06c3fb27SDimitry Andric#endif 1426*06c3fb27SDimitry Andric 1427bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator 1428bdd1243dSDimitry Andric insert(const_iterator __pos, size_type __n, value_type __c) { 1429bdd1243dSDimitry Andric difference_type __p = __pos - begin(); 1430bdd1243dSDimitry Andric insert(static_cast<size_type>(__p), __n, __c); 1431bdd1243dSDimitry Andric return begin() + __p; 1432bdd1243dSDimitry Andric } 1433bdd1243dSDimitry Andric 1434*06c3fb27SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 1435*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator 14360b57cec5SDimitry Andric insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); 1437*06c3fb27SDimitry Andric 1438*06c3fb27SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 1439*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator 14400b57cec5SDimitry Andric insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); 1441*06c3fb27SDimitry Andric 14420b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1443bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 14440b57cec5SDimitry Andric iterator insert(const_iterator __pos, initializer_list<value_type> __il) 14450b57cec5SDimitry Andric {return insert(__pos, __il.begin(), __il.end());} 14460b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 14470b57cec5SDimitry Andric 1448bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos); 1449bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 14500b57cec5SDimitry Andric iterator erase(const_iterator __pos); 1451bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 14520b57cec5SDimitry Andric iterator erase(const_iterator __first, const_iterator __last); 14530b57cec5SDimitry Andric 1454bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1455bdd1243dSDimitry Andric replace(size_type __pos1, size_type __n1, const basic_string& __str) { 1456bdd1243dSDimitry Andric return replace(__pos1, __n1, __str.data(), __str.size()); 1457bdd1243dSDimitry Andric } 14580b57cec5SDimitry Andric 1459*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1460*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1461*06c3fb27SDimitry Andric replace(size_type __pos1, size_type __n1, const _Tp& __t) { 1462*06c3fb27SDimitry Andric __self_view __sv = __t; 1463*06c3fb27SDimitry Andric return replace(__pos1, __n1, __sv.data(), __sv.size()); 1464*06c3fb27SDimitry Andric } 1465*06c3fb27SDimitry Andric 1466*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1467*06c3fb27SDimitry Andric replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2 = npos); 1468*06c3fb27SDimitry Andric 1469*06c3fb27SDimitry Andric template <class _Tp, 1470*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1471*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1472*06c3fb27SDimitry Andric int> = 0> 1473*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 14740b57cec5SDimitry Andric replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2 = npos); 1475*06c3fb27SDimitry Andric 1476*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1477*06c3fb27SDimitry Andric replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2); 1478bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); 1479bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); 1480bdd1243dSDimitry Andric 1481bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1482bdd1243dSDimitry Andric replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) { 1483bdd1243dSDimitry Andric return replace( 1484bdd1243dSDimitry Andric static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __str.data(), __str.size()); 1485bdd1243dSDimitry Andric } 14860b57cec5SDimitry Andric 1487*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1488*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1489*06c3fb27SDimitry Andric replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { 1490*06c3fb27SDimitry Andric __self_view __sv = __t; 1491*06c3fb27SDimitry Andric return replace(__i1 - begin(), __i2 - __i1, __sv); 1492*06c3fb27SDimitry Andric } 14930b57cec5SDimitry Andric 1494bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1495bdd1243dSDimitry Andric replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) { 1496bdd1243dSDimitry Andric return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); 1497bdd1243dSDimitry Andric } 1498bdd1243dSDimitry Andric 1499bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1500bdd1243dSDimitry Andric replace(const_iterator __i1, const_iterator __i2, const value_type* __s) { 1501bdd1243dSDimitry Andric return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); 1502bdd1243dSDimitry Andric } 1503bdd1243dSDimitry Andric 1504bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 1505bdd1243dSDimitry Andric replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) { 1506bdd1243dSDimitry Andric return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); 1507bdd1243dSDimitry Andric } 1508bdd1243dSDimitry Andric 1509*06c3fb27SDimitry Andric template <class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> = 0> 1510*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& 15110b57cec5SDimitry Andric replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); 1512*06c3fb27SDimitry Andric 1513*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 1514*06c3fb27SDimitry Andric template <_ContainerCompatibleRange<_CharT> _Range> 1515*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1516*06c3fb27SDimitry Andric constexpr basic_string& replace_with_range(const_iterator __i1, const_iterator __i2, _Range&& __range) { 1517*06c3fb27SDimitry Andric basic_string __temp(from_range, std::forward<_Range>(__range), __alloc()); 1518*06c3fb27SDimitry Andric return replace(__i1, __i2, __temp); 1519*06c3fb27SDimitry Andric } 1520*06c3fb27SDimitry Andric#endif 1521*06c3fb27SDimitry Andric 15220b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1523bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15240b57cec5SDimitry Andric basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) 15250b57cec5SDimitry Andric {return replace(__i1, __i2, __il.begin(), __il.end());} 15260b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 15270b57cec5SDimitry Andric 1528bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; 15290b57cec5SDimitry Andric 1530bdd1243dSDimitry Andric#if _LIBCPP_STD_VER <= 20 1531bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1532bdd1243dSDimitry Andric basic_string substr(size_type __pos = 0, size_type __n = npos) const { 1533bdd1243dSDimitry Andric return basic_string(*this, __pos, __n); 1534bdd1243dSDimitry Andric } 1535bdd1243dSDimitry Andric#else 1536bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 1537bdd1243dSDimitry Andric basic_string substr(size_type __pos = 0, size_type __n = npos) const& { 1538bdd1243dSDimitry Andric return basic_string(*this, __pos, __n); 1539bdd1243dSDimitry Andric } 1540bdd1243dSDimitry Andric 1541bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr 1542bdd1243dSDimitry Andric basic_string substr(size_type __pos = 0, size_type __n = npos) && { 1543bdd1243dSDimitry Andric return basic_string(std::move(*this), __pos, __n); 1544bdd1243dSDimitry Andric } 1545bdd1243dSDimitry Andric#endif 1546bdd1243dSDimitry Andric 1547bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15480b57cec5SDimitry Andric void swap(basic_string& __str) 15490b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 15500b57cec5SDimitry Andric _NOEXCEPT; 15510b57cec5SDimitry Andric#else 15520b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 15530b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value); 15540b57cec5SDimitry Andric#endif 15550b57cec5SDimitry Andric 1556bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15570b57cec5SDimitry Andric const value_type* c_str() const _NOEXCEPT {return data();} 1558bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 155981ad6265SDimitry Andric const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());} 1560*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 1561bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 156281ad6265SDimitry Andric value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());} 15630b57cec5SDimitry Andric#endif 15640b57cec5SDimitry Andric 1565bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15660b57cec5SDimitry Andric allocator_type get_allocator() const _NOEXCEPT {return __alloc();} 15670b57cec5SDimitry Andric 1568bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15690b57cec5SDimitry Andric size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 15700b57cec5SDimitry Andric 1571*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1572*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type 1573fe6060f1SDimitry Andric find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; 1574*06c3fb27SDimitry Andric 1575*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 1576bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15770b57cec5SDimitry Andric size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; 1578bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; 15790b57cec5SDimitry Andric 1580bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15810b57cec5SDimitry Andric size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 15820b57cec5SDimitry Andric 1583*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1584*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type 1585fe6060f1SDimitry Andric rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; 1586*06c3fb27SDimitry Andric 1587bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 15880b57cec5SDimitry Andric size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 1589bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15900b57cec5SDimitry Andric size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; 1591bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; 15920b57cec5SDimitry Andric 1593bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 15940b57cec5SDimitry Andric size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 15950b57cec5SDimitry Andric 1596*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1597*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type 1598fe6060f1SDimitry Andric find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; 1599*06c3fb27SDimitry Andric 1600bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 16010b57cec5SDimitry Andric size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 1602bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16030b57cec5SDimitry Andric size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; 1604bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16050b57cec5SDimitry Andric size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; 16060b57cec5SDimitry Andric 1607bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16080b57cec5SDimitry Andric size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 16090b57cec5SDimitry Andric 1610*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1611*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type 1612fe6060f1SDimitry Andric find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; 1613*06c3fb27SDimitry Andric 1614bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 16150b57cec5SDimitry Andric size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 1616bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16170b57cec5SDimitry Andric size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; 1618bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16190b57cec5SDimitry Andric size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; 16200b57cec5SDimitry Andric 1621bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16220b57cec5SDimitry Andric size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; 16230b57cec5SDimitry Andric 1624*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1625*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type 1626fe6060f1SDimitry Andric find_first_not_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; 1627*06c3fb27SDimitry Andric 1628bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 16290b57cec5SDimitry Andric size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 1630bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16310b57cec5SDimitry Andric size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; 1632bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16330b57cec5SDimitry Andric size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; 16340b57cec5SDimitry Andric 1635bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16360b57cec5SDimitry Andric size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; 16370b57cec5SDimitry Andric 1638*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1639*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type 1640fe6060f1SDimitry Andric find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; 1641*06c3fb27SDimitry Andric 1642bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 16430b57cec5SDimitry Andric size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; 1644bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16450b57cec5SDimitry Andric size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; 1646bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16470b57cec5SDimitry Andric size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; 16480b57cec5SDimitry Andric 1649bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16500b57cec5SDimitry Andric int compare(const basic_string& __str) const _NOEXCEPT; 16510b57cec5SDimitry Andric 1652*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1653*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 int 1654fe6060f1SDimitry Andric compare(const _Tp& __t) const _NOEXCEPT; 16550b57cec5SDimitry Andric 1656*06c3fb27SDimitry Andric template <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> = 0> 1657*06c3fb27SDimitry Andric _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 int 16580b57cec5SDimitry Andric compare(size_type __pos1, size_type __n1, const _Tp& __t) const; 16590b57cec5SDimitry Andric 1660bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 16610b57cec5SDimitry Andric int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; 1662bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 166381ad6265SDimitry Andric int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, 166481ad6265SDimitry Andric size_type __n2 = npos) const; 16650b57cec5SDimitry Andric 1666*06c3fb27SDimitry Andric template <class _Tp, 1667*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 1668*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string>::value, 1669*06c3fb27SDimitry Andric int> = 0> 1670*06c3fb27SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 int 16710b57cec5SDimitry Andric compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2 = npos) const; 1672*06c3fb27SDimitry Andric 1673bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* __s) const _NOEXCEPT; 1674bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(size_type __pos1, size_type __n1, const value_type* __s) const; 1675bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 16760b57cec5SDimitry Andric int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const; 16770b57cec5SDimitry Andric 1678*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 167981ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1680349cc55cSDimitry Andric bool starts_with(__self_view __sv) const noexcept 16810b57cec5SDimitry Andric { return __self_view(data(), size()).starts_with(__sv); } 16820b57cec5SDimitry Andric 168381ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1684349cc55cSDimitry Andric bool starts_with(value_type __c) const noexcept 16850b57cec5SDimitry Andric { return !empty() && _Traits::eq(front(), __c); } 16860b57cec5SDimitry Andric 168781ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1688349cc55cSDimitry Andric bool starts_with(const value_type* __s) const noexcept 16890b57cec5SDimitry Andric { return starts_with(__self_view(__s)); } 16900b57cec5SDimitry Andric 169181ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1692349cc55cSDimitry Andric bool ends_with(__self_view __sv) const noexcept 16930b57cec5SDimitry Andric { return __self_view(data(), size()).ends_with( __sv); } 16940b57cec5SDimitry Andric 169581ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1696349cc55cSDimitry Andric bool ends_with(value_type __c) const noexcept 16970b57cec5SDimitry Andric { return !empty() && _Traits::eq(back(), __c); } 16980b57cec5SDimitry Andric 169981ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1700349cc55cSDimitry Andric bool ends_with(const value_type* __s) const noexcept 17010b57cec5SDimitry Andric { return ends_with(__self_view(__s)); } 17020b57cec5SDimitry Andric#endif 17030b57cec5SDimitry Andric 1704*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 170581ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1706e8d8bef9SDimitry Andric bool contains(__self_view __sv) const noexcept 1707e8d8bef9SDimitry Andric { return __self_view(data(), size()).contains(__sv); } 1708e8d8bef9SDimitry Andric 170981ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1710e8d8bef9SDimitry Andric bool contains(value_type __c) const noexcept 1711e8d8bef9SDimitry Andric { return __self_view(data(), size()).contains(__c); } 1712e8d8bef9SDimitry Andric 171381ad6265SDimitry Andric constexpr _LIBCPP_HIDE_FROM_ABI 1714e8d8bef9SDimitry Andric bool contains(const value_type* __s) const 1715e8d8bef9SDimitry Andric { return __self_view(data(), size()).contains(__s); } 1716e8d8bef9SDimitry Andric#endif 1717e8d8bef9SDimitry Andric 1718bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; 17190b57cec5SDimitry Andric 1720bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __clear_and_shrink() _NOEXCEPT; 17210b57cec5SDimitry Andric 17220b57cec5SDimitry Andricprivate: 172381ad6265SDimitry Andric template<class _Alloc> 1724bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 172581ad6265SDimitry Andric bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs, 172681ad6265SDimitry Andric const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT; 172781ad6265SDimitry Andric 1728bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __shrink_or_extend(size_type __target_capacity); 172981ad6265SDimitry Andric 1730bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 173181ad6265SDimitry Andric bool __is_long() const _NOEXCEPT { 173281ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 173381ad6265SDimitry Andric return true; 173481ad6265SDimitry Andric return __r_.first().__s.__is_long_; 173581ad6265SDimitry Andric } 173681ad6265SDimitry Andric 1737bdd1243dSDimitry Andric static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __begin_lifetime(pointer __begin, size_type __n) { 1738*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 173981ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 174081ad6265SDimitry Andric for (size_type __i = 0; __i != __n; ++__i) 174181ad6265SDimitry Andric std::construct_at(std::addressof(__begin[__i])); 174281ad6265SDimitry Andric } 174381ad6265SDimitry Andric#else 174481ad6265SDimitry Andric (void)__begin; 174581ad6265SDimitry Andric (void)__n; 1746*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 174781ad6265SDimitry Andric } 174881ad6265SDimitry Andric 1749bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init() { 1750bdd1243dSDimitry Andric __r_.first() = __rep(); 175181ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 175281ad6265SDimitry Andric size_type __sz = __recommend(0) + 1; 175381ad6265SDimitry Andric pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); 175481ad6265SDimitry Andric __begin_lifetime(__ptr, __sz); 175581ad6265SDimitry Andric __set_long_pointer(__ptr); 175681ad6265SDimitry Andric __set_long_cap(__sz); 175781ad6265SDimitry Andric __set_long_size(0); 175881ad6265SDimitry Andric } 175981ad6265SDimitry Andric } 176081ad6265SDimitry Andric 1761bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_constexpr() { 176281ad6265SDimitry Andric if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr) 176381ad6265SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap()); 176481ad6265SDimitry Andric } 176581ad6265SDimitry Andric 176604eeddc0SDimitry Andric _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { 176704eeddc0SDimitry Andric // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly 176804eeddc0SDimitry Andric return !__libcpp_is_constant_evaluated() && (__sz < __min_cap); 176904eeddc0SDimitry Andric } 177004eeddc0SDimitry Andric 1771*06c3fb27SDimitry Andric template <class _Iterator, class _Sentinel> 1772*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 1773*06c3fb27SDimitry Andric void __assign_trivial(_Iterator __first, _Sentinel __last, size_type __n); 1774*06c3fb27SDimitry Andric 1775*06c3fb27SDimitry Andric template <class _Iterator, class _Sentinel> 1776*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 1777*06c3fb27SDimitry Andric void __assign_with_sentinel(_Iterator __first, _Sentinel __last); 1778*06c3fb27SDimitry Andric 1779*06c3fb27SDimitry Andric template <class _ForwardIterator, class _Sentinel> 1780bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 1781*06c3fb27SDimitry Andric iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _Sentinel __last) { 178281ad6265SDimitry Andric size_type __sz = size(); 178381ad6265SDimitry Andric size_type __cap = capacity(); 178481ad6265SDimitry Andric value_type* __p; 178581ad6265SDimitry Andric if (__cap - __sz >= __n) 178681ad6265SDimitry Andric { 178781ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 178881ad6265SDimitry Andric size_type __n_move = __sz - __ip; 178981ad6265SDimitry Andric if (__n_move != 0) 179081ad6265SDimitry Andric traits_type::move(__p + __ip + __n, __p + __ip, __n_move); 179181ad6265SDimitry Andric } 179281ad6265SDimitry Andric else 179381ad6265SDimitry Andric { 1794*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); 179581ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 179681ad6265SDimitry Andric } 179781ad6265SDimitry Andric __sz += __n; 179881ad6265SDimitry Andric __set_size(__sz); 179981ad6265SDimitry Andric traits_type::assign(__p[__sz], value_type()); 180081ad6265SDimitry Andric for (__p += __ip; __first != __last; ++__p, ++__first) 180181ad6265SDimitry Andric traits_type::assign(*__p, *__first); 18020b57cec5SDimitry Andric 180381ad6265SDimitry Andric return begin() + __ip; 180481ad6265SDimitry Andric } 18050b57cec5SDimitry Andric 1806*06c3fb27SDimitry Andric template<class _Iterator, class _Sentinel> 1807*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 1808*06c3fb27SDimitry Andric iterator __insert_with_size(const_iterator __pos, _Iterator __first, _Sentinel __last, size_type __n); 1809*06c3fb27SDimitry Andric 1810bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); } 181181ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); } 18120b57cec5SDimitry Andric 1813bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 181481ad6265SDimitry Andric void __set_short_size(size_type __s) _NOEXCEPT { 1815*06c3fb27SDimitry Andric _LIBCPP_ASSERT_INTERNAL( 1816*06c3fb27SDimitry Andric __s < __min_cap, "__s should never be greater than or equal to the short string capacity"); 181781ad6265SDimitry Andric __r_.first().__s.__size_ = __s; 181881ad6265SDimitry Andric __r_.first().__s.__is_long_ = false; 181981ad6265SDimitry Andric } 18200b57cec5SDimitry Andric 1821bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 182281ad6265SDimitry Andric size_type __get_short_size() const _NOEXCEPT { 1823*06c3fb27SDimitry Andric _LIBCPP_ASSERT_INTERNAL( 1824*06c3fb27SDimitry Andric !__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); 182581ad6265SDimitry Andric return __r_.first().__s.__size_; 182681ad6265SDimitry Andric } 18270b57cec5SDimitry Andric 1828bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18290b57cec5SDimitry Andric void __set_long_size(size_type __s) _NOEXCEPT 18300b57cec5SDimitry Andric {__r_.first().__l.__size_ = __s;} 1831bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18320b57cec5SDimitry Andric size_type __get_long_size() const _NOEXCEPT 18330b57cec5SDimitry Andric {return __r_.first().__l.__size_;} 1834bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18350b57cec5SDimitry Andric void __set_size(size_type __s) _NOEXCEPT 18360b57cec5SDimitry Andric {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} 18370b57cec5SDimitry Andric 1838bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 183981ad6265SDimitry Andric void __set_long_cap(size_type __s) _NOEXCEPT { 184081ad6265SDimitry Andric __r_.first().__l.__cap_ = __s / __endian_factor; 184181ad6265SDimitry Andric __r_.first().__l.__is_long_ = true; 184281ad6265SDimitry Andric } 18430b57cec5SDimitry Andric 1844bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 184581ad6265SDimitry Andric size_type __get_long_cap() const _NOEXCEPT { 184681ad6265SDimitry Andric return __r_.first().__l.__cap_ * __endian_factor; 184781ad6265SDimitry Andric } 184881ad6265SDimitry Andric 1849bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18500b57cec5SDimitry Andric void __set_long_pointer(pointer __p) _NOEXCEPT 18510b57cec5SDimitry Andric {__r_.first().__l.__data_ = __p;} 1852bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18530b57cec5SDimitry Andric pointer __get_long_pointer() _NOEXCEPT 18540b57cec5SDimitry Andric {return __r_.first().__l.__data_;} 1855bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18560b57cec5SDimitry Andric const_pointer __get_long_pointer() const _NOEXCEPT 18570b57cec5SDimitry Andric {return __r_.first().__l.__data_;} 1858bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18590b57cec5SDimitry Andric pointer __get_short_pointer() _NOEXCEPT 18600b57cec5SDimitry Andric {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} 1861bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18620b57cec5SDimitry Andric const_pointer __get_short_pointer() const _NOEXCEPT 18630b57cec5SDimitry Andric {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} 1864bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18650b57cec5SDimitry Andric pointer __get_pointer() _NOEXCEPT 18660b57cec5SDimitry Andric {return __is_long() ? __get_long_pointer() : __get_short_pointer();} 1867bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18680b57cec5SDimitry Andric const_pointer __get_pointer() const _NOEXCEPT 18690b57cec5SDimitry Andric {return __is_long() ? __get_long_pointer() : __get_short_pointer();} 18700b57cec5SDimitry Andric 18710b57cec5SDimitry Andric template <size_type __a> static 1872bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18730b57cec5SDimitry Andric size_type __align_it(size_type __s) _NOEXCEPT 18740b57cec5SDimitry Andric {return (__s + (__a-1)) & ~(__a-1);} 18750b57cec5SDimitry Andric enum {__alignment = 16}; 1876bdd1243dSDimitry Andric static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 18770b57cec5SDimitry Andric size_type __recommend(size_type __s) _NOEXCEPT 18780b57cec5SDimitry Andric { 187981ad6265SDimitry Andric if (__s < __min_cap) { 188081ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 188181ad6265SDimitry Andric return static_cast<size_type>(__min_cap); 188281ad6265SDimitry Andric else 188381ad6265SDimitry Andric return static_cast<size_type>(__min_cap) - 1; 188481ad6265SDimitry Andric } 18850b57cec5SDimitry Andric size_type __guess = __align_it<sizeof(value_type) < __alignment ? 18860b57cec5SDimitry Andric __alignment/sizeof(value_type) : 1 > (__s+1) - 1; 18870b57cec5SDimitry Andric if (__guess == __min_cap) ++__guess; 18880b57cec5SDimitry Andric return __guess; 18890b57cec5SDimitry Andric } 18900b57cec5SDimitry Andric 1891bdd1243dSDimitry Andric inline _LIBCPP_CONSTEXPR_SINCE_CXX20 18920b57cec5SDimitry Andric void __init(const value_type* __s, size_type __sz, size_type __reserve); 1893bdd1243dSDimitry Andric inline _LIBCPP_CONSTEXPR_SINCE_CXX20 18940b57cec5SDimitry Andric void __init(const value_type* __s, size_type __sz); 1895bdd1243dSDimitry Andric inline _LIBCPP_CONSTEXPR_SINCE_CXX20 18960b57cec5SDimitry Andric void __init(size_type __n, value_type __c); 18970b57cec5SDimitry Andric 18985ffd83dbSDimitry Andric // Slow path for the (inlined) copy constructor for 'long' strings. 18995ffd83dbSDimitry Andric // Always externally instantiated and not inlined. 19005ffd83dbSDimitry Andric // Requires that __s is zero terminated. 19015ffd83dbSDimitry Andric // The main reason for this function to exist is because for unstable, we 19025ffd83dbSDimitry Andric // want to allow inlining of the copy constructor. However, we don't want 19035ffd83dbSDimitry Andric // to call the __init() functions as those are marked as inline which may 19045ffd83dbSDimitry Andric // result in over-aggressive inlining by the compiler, where our aim is 19055ffd83dbSDimitry Andric // to only inline the fast path code directly in the ctor. 1906bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init_copy_ctor_external(const value_type* __s, size_type __sz); 19075ffd83dbSDimitry Andric 1908*06c3fb27SDimitry Andric template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0> 1909*06c3fb27SDimitry Andric inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(_InputIterator __first, _InputIterator __last); 19100b57cec5SDimitry Andric 1911*06c3fb27SDimitry Andric template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0> 1912*06c3fb27SDimitry Andric inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init(_ForwardIterator __first, _ForwardIterator __last); 1913*06c3fb27SDimitry Andric 1914*06c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 1915*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1916*06c3fb27SDimitry Andric void __init_with_sentinel(_InputIterator __first, _Sentinel __last); 1917*06c3fb27SDimitry Andric template <class _InputIterator, class _Sentinel> 1918*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 1919*06c3fb27SDimitry Andric void __init_with_size(_InputIterator __first, _Sentinel __last, size_type __sz); 19200b57cec5SDimitry Andric 1921bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 1922*06c3fb27SDimitry Andric#if _LIBCPP_ABI_VERSION >= 2 // We want to use the function in the dylib in ABIv1 1923*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 1924*06c3fb27SDimitry Andric#endif 1925*06c3fb27SDimitry Andric _LIBCPP_DEPRECATED_("use __grow_by_without_replace") 19260b57cec5SDimitry Andric void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 19270b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, size_type __n_add = 0); 1928*06c3fb27SDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 1929*06c3fb27SDimitry Andric void __grow_by_without_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 1930*06c3fb27SDimitry Andric size_type __n_copy, size_type __n_del, size_type __n_add = 0); 1931bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 19320b57cec5SDimitry Andric void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 19330b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, 19340b57cec5SDimitry Andric size_type __n_add, const value_type* __p_new_stuff); 19350b57cec5SDimitry Andric 19365ffd83dbSDimitry Andric // __assign_no_alias is invoked for assignment operations where we 19375ffd83dbSDimitry Andric // have proof that the input does not alias the current instance. 19385ffd83dbSDimitry Andric // For example, operator=(basic_string) performs a 'self' check. 19395ffd83dbSDimitry Andric template <bool __is_short> 1940bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_no_alias(const value_type* __s, size_type __n); 19415ffd83dbSDimitry Andric 1942bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __erase_to_end(size_type __pos) { 1943bdd1243dSDimitry Andric __null_terminate_at(std::__to_address(__get_pointer()), __pos); 1944bdd1243dSDimitry Andric } 19450b57cec5SDimitry Andric 19465ffd83dbSDimitry Andric // __erase_external_with_move is invoked for erase() invocations where 19475ffd83dbSDimitry Andric // `n ~= npos`, likely requiring memory moves on the string data. 1948bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 void __erase_external_with_move(size_type __pos, size_type __n); 19495ffd83dbSDimitry Andric 1950bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 19510b57cec5SDimitry Andric void __copy_assign_alloc(const basic_string& __str) 19520b57cec5SDimitry Andric {__copy_assign_alloc(__str, integral_constant<bool, 19530b57cec5SDimitry Andric __alloc_traits::propagate_on_container_copy_assignment::value>());} 19540b57cec5SDimitry Andric 1955bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 19560b57cec5SDimitry Andric void __copy_assign_alloc(const basic_string& __str, true_type) 19570b57cec5SDimitry Andric { 19580b57cec5SDimitry Andric if (__alloc() == __str.__alloc()) 19590b57cec5SDimitry Andric __alloc() = __str.__alloc(); 19600b57cec5SDimitry Andric else 19610b57cec5SDimitry Andric { 19620b57cec5SDimitry Andric if (!__str.__is_long()) 19630b57cec5SDimitry Andric { 19640b57cec5SDimitry Andric __clear_and_shrink(); 19650b57cec5SDimitry Andric __alloc() = __str.__alloc(); 19660b57cec5SDimitry Andric } 19670b57cec5SDimitry Andric else 19680b57cec5SDimitry Andric { 19690b57cec5SDimitry Andric allocator_type __a = __str.__alloc(); 197081ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap()); 197181ad6265SDimitry Andric __begin_lifetime(__allocation.ptr, __allocation.count); 1972bdd1243dSDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 197381ad6265SDimitry Andric __alloc() = std::move(__a); 197481ad6265SDimitry Andric __set_long_pointer(__allocation.ptr); 197581ad6265SDimitry Andric __set_long_cap(__allocation.count); 19760b57cec5SDimitry Andric __set_long_size(__str.size()); 19770b57cec5SDimitry Andric } 19780b57cec5SDimitry Andric } 19790b57cec5SDimitry Andric } 19800b57cec5SDimitry Andric 1981bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 19820b57cec5SDimitry Andric void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT 19830b57cec5SDimitry Andric {} 19840b57cec5SDimitry Andric 19850b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 1986bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 19870b57cec5SDimitry Andric void __move_assign(basic_string& __str, false_type) 19880b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value); 1989bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 19900b57cec5SDimitry Andric void __move_assign(basic_string& __str, true_type) 1991*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 19920b57cec5SDimitry Andric _NOEXCEPT; 19930b57cec5SDimitry Andric#else 19940b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); 19950b57cec5SDimitry Andric#endif 19960b57cec5SDimitry Andric#endif 19970b57cec5SDimitry Andric 1998bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 19990b57cec5SDimitry Andric void 20000b57cec5SDimitry Andric __move_assign_alloc(basic_string& __str) 20010b57cec5SDimitry Andric _NOEXCEPT_( 20020b57cec5SDimitry Andric !__alloc_traits::propagate_on_container_move_assignment::value || 20030b57cec5SDimitry Andric is_nothrow_move_assignable<allocator_type>::value) 20040b57cec5SDimitry Andric {__move_assign_alloc(__str, integral_constant<bool, 20050b57cec5SDimitry Andric __alloc_traits::propagate_on_container_move_assignment::value>());} 20060b57cec5SDimitry Andric 2007bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 20080b57cec5SDimitry Andric void __move_assign_alloc(basic_string& __c, true_type) 20090b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 20100b57cec5SDimitry Andric { 201181ad6265SDimitry Andric __alloc() = std::move(__c.__alloc()); 20120b57cec5SDimitry Andric } 20130b57cec5SDimitry Andric 2014bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 20150b57cec5SDimitry Andric void __move_assign_alloc(basic_string&, false_type) 20160b57cec5SDimitry Andric _NOEXCEPT 20170b57cec5SDimitry Andric {} 20180b57cec5SDimitry Andric 2019bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s); 2020bdd1243dSDimitry Andric _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s, size_type __n); 20215ffd83dbSDimitry Andric 20225ffd83dbSDimitry Andric // Assigns the value in __s, guaranteed to be __n < __min_cap in length. 20235ffd83dbSDimitry Andric inline basic_string& __assign_short(const value_type* __s, size_type __n) { 20245ffd83dbSDimitry Andric pointer __p = __is_long() 20255ffd83dbSDimitry Andric ? (__set_long_size(__n), __get_long_pointer()) 20265ffd83dbSDimitry Andric : (__set_short_size(__n), __get_short_pointer()); 202781ad6265SDimitry Andric traits_type::move(std::__to_address(__p), __s, __n); 20285ffd83dbSDimitry Andric traits_type::assign(__p[__n], value_type()); 20295ffd83dbSDimitry Andric return *this; 20305ffd83dbSDimitry Andric } 20315ffd83dbSDimitry Andric 2032bdd1243dSDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 203381ad6265SDimitry Andric basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { 20340eae32dcSDimitry Andric __set_size(__newsz); 20350eae32dcSDimitry Andric traits_type::assign(__p[__newsz], value_type()); 20360eae32dcSDimitry Andric return *this; 20370eae32dcSDimitry Andric } 20380eae32dcSDimitry Andric 2039fe6060f1SDimitry Andric template <class _Tp> 2040*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __addr_in_range(const _Tp& __v) const { 2041*06c3fb27SDimitry Andric return std::__is_pointer_in_range(data(), data() + size() + 1, std::addressof(__v)); 2042fe6060f1SDimitry Andric } 2043fe6060f1SDimitry Andric 204469ade1e0SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 204569ade1e0SDimitry Andric void __throw_length_error() const { 204681ad6265SDimitry Andric std::__throw_length_error("basic_string"); 204769ade1e0SDimitry Andric } 204869ade1e0SDimitry Andric 204969ade1e0SDimitry Andric _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI 205069ade1e0SDimitry Andric void __throw_out_of_range() const { 205181ad6265SDimitry Andric std::__throw_out_of_range("basic_string"); 205269ade1e0SDimitry Andric } 205369ade1e0SDimitry Andric 2054bdd1243dSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const basic_string&); 2055bdd1243dSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const value_type*, const basic_string&); 2056bdd1243dSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(value_type, const basic_string&); 2057bdd1243dSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const value_type*); 2058bdd1243dSDimitry Andric friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, value_type); 20590b57cec5SDimitry Andric}; 20600b57cec5SDimitry Andric 20615ffd83dbSDimitry Andric// These declarations must appear before any functions are implicitly used 20625ffd83dbSDimitry Andric// so that they have the correct visibility specifier. 206381ad6265SDimitry Andric#define _LIBCPP_DECLARE(...) extern template __VA_ARGS__; 20645ffd83dbSDimitry Andric#ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION 206581ad6265SDimitry Andric _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) 2066349cc55cSDimitry Andric# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 206781ad6265SDimitry Andric _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) 2068349cc55cSDimitry Andric# endif 20695ffd83dbSDimitry Andric#else 207081ad6265SDimitry Andric _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) 2071349cc55cSDimitry Andric# ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 207281ad6265SDimitry Andric _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) 20735ffd83dbSDimitry Andric# endif 2074349cc55cSDimitry Andric#endif 207581ad6265SDimitry Andric#undef _LIBCPP_DECLARE 20765ffd83dbSDimitry Andric 20775ffd83dbSDimitry Andric 2078349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17 20790b57cec5SDimitry Andrictemplate<class _InputIterator, 2080fe6060f1SDimitry Andric class _CharT = __iter_value_type<_InputIterator>, 20810b57cec5SDimitry Andric class _Allocator = allocator<_CharT>, 2082*06c3fb27SDimitry Andric class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>, 2083349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value> 20840b57cec5SDimitry Andric > 20850b57cec5SDimitry Andricbasic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) 20860b57cec5SDimitry Andric -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; 20870b57cec5SDimitry Andric 20880b57cec5SDimitry Andrictemplate<class _CharT, 20890b57cec5SDimitry Andric class _Traits, 20900b57cec5SDimitry Andric class _Allocator = allocator<_CharT>, 2091349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value> 20920b57cec5SDimitry Andric > 20930b57cec5SDimitry Andricexplicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) 20940b57cec5SDimitry Andric -> basic_string<_CharT, _Traits, _Allocator>; 20950b57cec5SDimitry Andric 20960b57cec5SDimitry Andrictemplate<class _CharT, 20970b57cec5SDimitry Andric class _Traits, 20980b57cec5SDimitry Andric class _Allocator = allocator<_CharT>, 2099349cc55cSDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value>, 21000b57cec5SDimitry Andric class _Sz = typename allocator_traits<_Allocator>::size_type 21010b57cec5SDimitry Andric > 21020b57cec5SDimitry Andricbasic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) 21030b57cec5SDimitry Andric -> basic_string<_CharT, _Traits, _Allocator>; 21040b57cec5SDimitry Andric#endif 21050b57cec5SDimitry Andric 2106*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23 2107*06c3fb27SDimitry Andrictemplate <ranges::input_range _Range, 2108*06c3fb27SDimitry Andric class _Allocator = allocator<ranges::range_value_t<_Range>>, 2109*06c3fb27SDimitry Andric class = enable_if_t<__is_allocator<_Allocator>::value> 2110*06c3fb27SDimitry Andric > 2111*06c3fb27SDimitry Andricbasic_string(from_range_t, _Range&&, _Allocator = _Allocator()) 2112*06c3fb27SDimitry Andric -> basic_string<ranges::range_value_t<_Range>, char_traits<ranges::range_value_t<_Range>>, _Allocator>; 2113*06c3fb27SDimitry Andric#endif 21140b57cec5SDimitry Andric 21150b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2116bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 21170b57cec5SDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, 21180b57cec5SDimitry Andric size_type __sz, 21190b57cec5SDimitry Andric size_type __reserve) 21200b57cec5SDimitry Andric{ 212181ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 2122bdd1243dSDimitry Andric __r_.first() = __rep(); 21230b57cec5SDimitry Andric if (__reserve > max_size()) 212404eeddc0SDimitry Andric __throw_length_error(); 21250b57cec5SDimitry Andric pointer __p; 212604eeddc0SDimitry Andric if (__fits_in_sso(__reserve)) 21270b57cec5SDimitry Andric { 21280b57cec5SDimitry Andric __set_short_size(__sz); 21290b57cec5SDimitry Andric __p = __get_short_pointer(); 21300b57cec5SDimitry Andric } 21310b57cec5SDimitry Andric else 21320b57cec5SDimitry Andric { 213381ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1); 213481ad6265SDimitry Andric __p = __allocation.ptr; 213581ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 21360b57cec5SDimitry Andric __set_long_pointer(__p); 213781ad6265SDimitry Andric __set_long_cap(__allocation.count); 21380b57cec5SDimitry Andric __set_long_size(__sz); 21390b57cec5SDimitry Andric } 214081ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __sz); 21410b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 21420b57cec5SDimitry Andric} 21430b57cec5SDimitry Andric 21440b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2145bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 21460b57cec5SDimitry Andricvoid 21470b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) 21480b57cec5SDimitry Andric{ 214981ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 2150bdd1243dSDimitry Andric __r_.first() = __rep(); 21510b57cec5SDimitry Andric if (__sz > max_size()) 215204eeddc0SDimitry Andric __throw_length_error(); 21530b57cec5SDimitry Andric pointer __p; 215404eeddc0SDimitry Andric if (__fits_in_sso(__sz)) 21550b57cec5SDimitry Andric { 21560b57cec5SDimitry Andric __set_short_size(__sz); 21570b57cec5SDimitry Andric __p = __get_short_pointer(); 21580b57cec5SDimitry Andric } 21590b57cec5SDimitry Andric else 21600b57cec5SDimitry Andric { 216181ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); 216281ad6265SDimitry Andric __p = __allocation.ptr; 216381ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 21640b57cec5SDimitry Andric __set_long_pointer(__p); 216581ad6265SDimitry Andric __set_long_cap(__allocation.count); 21660b57cec5SDimitry Andric __set_long_size(__sz); 21670b57cec5SDimitry Andric } 216881ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __sz); 21690b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 21700b57cec5SDimitry Andric} 21710b57cec5SDimitry Andric 21720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2173bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 21745ffd83dbSDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( 21755ffd83dbSDimitry Andric const value_type* __s, size_type __sz) { 217681ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 2177bdd1243dSDimitry Andric __r_.first() = __rep(); 2178bdd1243dSDimitry Andric 21795ffd83dbSDimitry Andric pointer __p; 218004eeddc0SDimitry Andric if (__fits_in_sso(__sz)) { 21815ffd83dbSDimitry Andric __p = __get_short_pointer(); 21825ffd83dbSDimitry Andric __set_short_size(__sz); 21835ffd83dbSDimitry Andric } else { 21845ffd83dbSDimitry Andric if (__sz > max_size()) 218504eeddc0SDimitry Andric __throw_length_error(); 218681ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); 218781ad6265SDimitry Andric __p = __allocation.ptr; 218881ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 21895ffd83dbSDimitry Andric __set_long_pointer(__p); 219081ad6265SDimitry Andric __set_long_cap(__allocation.count); 21915ffd83dbSDimitry Andric __set_long_size(__sz); 21925ffd83dbSDimitry Andric } 219381ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __sz + 1); 21945ffd83dbSDimitry Andric} 21955ffd83dbSDimitry Andric 21960b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2197bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 21980b57cec5SDimitry Andricvoid 21990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) 22000b57cec5SDimitry Andric{ 220181ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 2202bdd1243dSDimitry Andric __r_.first() = __rep(); 2203bdd1243dSDimitry Andric 22040b57cec5SDimitry Andric if (__n > max_size()) 220504eeddc0SDimitry Andric __throw_length_error(); 22060b57cec5SDimitry Andric pointer __p; 220704eeddc0SDimitry Andric if (__fits_in_sso(__n)) 22080b57cec5SDimitry Andric { 22090b57cec5SDimitry Andric __set_short_size(__n); 22100b57cec5SDimitry Andric __p = __get_short_pointer(); 22110b57cec5SDimitry Andric } 22120b57cec5SDimitry Andric else 22130b57cec5SDimitry Andric { 221481ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1); 221581ad6265SDimitry Andric __p = __allocation.ptr; 221681ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 22170b57cec5SDimitry Andric __set_long_pointer(__p); 221881ad6265SDimitry Andric __set_long_cap(__allocation.count); 22190b57cec5SDimitry Andric __set_long_size(__n); 22200b57cec5SDimitry Andric } 222181ad6265SDimitry Andric traits_type::assign(std::__to_address(__p), __n, __c); 22220b57cec5SDimitry Andric traits_type::assign(__p[__n], value_type()); 22230b57cec5SDimitry Andric} 22240b57cec5SDimitry Andric 22250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2226*06c3fb27SDimitry Andrictemplate <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2227bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2228*06c3fb27SDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) 22290b57cec5SDimitry Andric{ 2230*06c3fb27SDimitry Andric __init_with_sentinel(std::move(__first), std::move(__last)); 22310b57cec5SDimitry Andric} 22320b57cec5SDimitry Andric 22330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2234*06c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 2235*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 2236*06c3fb27SDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init_with_sentinel(_InputIterator __first, _Sentinel __last) { 223781ad6265SDimitry Andric __default_init(); 2238*06c3fb27SDimitry Andric 2239*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 22400b57cec5SDimitry Andric try 22410b57cec5SDimitry Andric { 2242*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 22430b57cec5SDimitry Andric for (; __first != __last; ++__first) 22440b57cec5SDimitry Andric push_back(*__first); 2245*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 22460b57cec5SDimitry Andric } 22470b57cec5SDimitry Andric catch (...) 22480b57cec5SDimitry Andric { 22490b57cec5SDimitry Andric if (__is_long()) 22500b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 22510b57cec5SDimitry Andric throw; 22520b57cec5SDimitry Andric } 2253*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 22540b57cec5SDimitry Andric} 22550b57cec5SDimitry Andric 22560b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2257*06c3fb27SDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2258*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 void 22590b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) 22600b57cec5SDimitry Andric{ 2261*06c3fb27SDimitry Andric size_type __sz = static_cast<size_type>(std::distance(__first, __last)); 2262*06c3fb27SDimitry Andric __init_with_size(__first, __last, __sz); 2263*06c3fb27SDimitry Andric} 2264*06c3fb27SDimitry Andric 2265*06c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2266*06c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 2267*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 2268*06c3fb27SDimitry Andricvoid basic_string<_CharT, _Traits, _Allocator>::__init_with_size( 2269*06c3fb27SDimitry Andric _InputIterator __first, _Sentinel __last, size_type __sz) { 227081ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) 2271bdd1243dSDimitry Andric __r_.first() = __rep(); 2272*06c3fb27SDimitry Andric 22730b57cec5SDimitry Andric if (__sz > max_size()) 227404eeddc0SDimitry Andric __throw_length_error(); 2275*06c3fb27SDimitry Andric 22760b57cec5SDimitry Andric pointer __p; 227704eeddc0SDimitry Andric if (__fits_in_sso(__sz)) 22780b57cec5SDimitry Andric { 22790b57cec5SDimitry Andric __set_short_size(__sz); 22800b57cec5SDimitry Andric __p = __get_short_pointer(); 2281*06c3fb27SDimitry Andric 22820b57cec5SDimitry Andric } 22830b57cec5SDimitry Andric else 22840b57cec5SDimitry Andric { 228581ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); 228681ad6265SDimitry Andric __p = __allocation.ptr; 228781ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 22880b57cec5SDimitry Andric __set_long_pointer(__p); 228981ad6265SDimitry Andric __set_long_cap(__allocation.count); 22900b57cec5SDimitry Andric __set_long_size(__sz); 22910b57cec5SDimitry Andric } 2292fe6060f1SDimitry Andric 2293*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2294fe6060f1SDimitry Andric try 2295fe6060f1SDimitry Andric { 2296*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 22970b57cec5SDimitry Andric for (; __first != __last; ++__first, (void) ++__p) 22980b57cec5SDimitry Andric traits_type::assign(*__p, *__first); 22990b57cec5SDimitry Andric traits_type::assign(*__p, value_type()); 2300*06c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS 2301fe6060f1SDimitry Andric } 2302fe6060f1SDimitry Andric catch (...) 2303fe6060f1SDimitry Andric { 2304fe6060f1SDimitry Andric if (__is_long()) 2305fe6060f1SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); 2306fe6060f1SDimitry Andric throw; 2307fe6060f1SDimitry Andric } 2308*06c3fb27SDimitry Andric#endif // _LIBCPP_HAS_NO_EXCEPTIONS 23090b57cec5SDimitry Andric} 23100b57cec5SDimitry Andric 23110b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2312bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 23130b57cec5SDimitry Andricvoid 23140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace 23150b57cec5SDimitry Andric (size_type __old_cap, size_type __delta_cap, size_type __old_sz, 23160b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff) 23170b57cec5SDimitry Andric{ 23180b57cec5SDimitry Andric size_type __ms = max_size(); 23190b57cec5SDimitry Andric if (__delta_cap > __ms - __old_cap - 1) 232004eeddc0SDimitry Andric __throw_length_error(); 23210b57cec5SDimitry Andric pointer __old_p = __get_pointer(); 23220b57cec5SDimitry Andric size_type __cap = __old_cap < __ms / 2 - __alignment ? 232381ad6265SDimitry Andric __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : 23240b57cec5SDimitry Andric __ms - 1; 232581ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); 232681ad6265SDimitry Andric pointer __p = __allocation.ptr; 232781ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 23280b57cec5SDimitry Andric if (__n_copy != 0) 232981ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), 233081ad6265SDimitry Andric std::__to_address(__old_p), __n_copy); 23310b57cec5SDimitry Andric if (__n_add != 0) 233281ad6265SDimitry Andric traits_type::copy(std::__to_address(__p) + __n_copy, __p_new_stuff, __n_add); 23330b57cec5SDimitry Andric size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 23340b57cec5SDimitry Andric if (__sec_cp_sz != 0) 233581ad6265SDimitry Andric traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, 233681ad6265SDimitry Andric std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); 233781ad6265SDimitry Andric if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated()) 23380b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); 23390b57cec5SDimitry Andric __set_long_pointer(__p); 234081ad6265SDimitry Andric __set_long_cap(__allocation.count); 23410b57cec5SDimitry Andric __old_sz = __n_copy + __n_add + __sec_cp_sz; 23420b57cec5SDimitry Andric __set_long_size(__old_sz); 23430b57cec5SDimitry Andric traits_type::assign(__p[__old_sz], value_type()); 23440b57cec5SDimitry Andric} 23450b57cec5SDimitry Andric 2346*06c3fb27SDimitry Andric// __grow_by is deprecated because it does not set the size. It may not update the size when the size is changed, and it 2347*06c3fb27SDimitry Andric// may also not set the size at all when the string was short initially. This leads to unpredictable size value. It is 2348*06c3fb27SDimitry Andric// not removed or changed to avoid breaking the ABI. 23490b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 23500b57cec5SDimitry Andricvoid 2351bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2352*06c3fb27SDimitry Andric#if _LIBCPP_ABI_VERSION >= 2 // We want to use the function in the dylib in ABIv1 2353*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI 2354*06c3fb27SDimitry Andric#endif 2355*06c3fb27SDimitry Andric _LIBCPP_DEPRECATED_("use __grow_by_without_replace") 23560b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, 23570b57cec5SDimitry Andric size_type __n_copy, size_type __n_del, size_type __n_add) 23580b57cec5SDimitry Andric{ 23590b57cec5SDimitry Andric size_type __ms = max_size(); 23600b57cec5SDimitry Andric if (__delta_cap > __ms - __old_cap) 236104eeddc0SDimitry Andric __throw_length_error(); 23620b57cec5SDimitry Andric pointer __old_p = __get_pointer(); 23630b57cec5SDimitry Andric size_type __cap = __old_cap < __ms / 2 - __alignment ? 236481ad6265SDimitry Andric __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : 23650b57cec5SDimitry Andric __ms - 1; 236681ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); 236781ad6265SDimitry Andric pointer __p = __allocation.ptr; 236881ad6265SDimitry Andric __begin_lifetime(__p, __allocation.count); 23690b57cec5SDimitry Andric if (__n_copy != 0) 237081ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), 237181ad6265SDimitry Andric std::__to_address(__old_p), __n_copy); 23720b57cec5SDimitry Andric size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; 23730b57cec5SDimitry Andric if (__sec_cp_sz != 0) 237481ad6265SDimitry Andric traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, 237581ad6265SDimitry Andric std::__to_address(__old_p) + __n_copy + __n_del, 23760b57cec5SDimitry Andric __sec_cp_sz); 237781ad6265SDimitry Andric if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap) 23780b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1); 23790b57cec5SDimitry Andric __set_long_pointer(__p); 238081ad6265SDimitry Andric __set_long_cap(__allocation.count); 23810b57cec5SDimitry Andric} 23820b57cec5SDimitry Andric 2383*06c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2384*06c3fb27SDimitry Andricvoid _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 2385*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__grow_by_without_replace( 2386*06c3fb27SDimitry Andric size_type __old_cap, 2387*06c3fb27SDimitry Andric size_type __delta_cap, 2388*06c3fb27SDimitry Andric size_type __old_sz, 2389*06c3fb27SDimitry Andric size_type __n_copy, 2390*06c3fb27SDimitry Andric size_type __n_del, 2391*06c3fb27SDimitry Andric size_type __n_add) { 2392*06c3fb27SDimitry Andric _LIBCPP_SUPPRESS_DEPRECATED_PUSH 2393*06c3fb27SDimitry Andric __grow_by(__old_cap, __delta_cap, __old_sz, __n_copy, __n_del, __n_add); 2394*06c3fb27SDimitry Andric _LIBCPP_SUPPRESS_DEPRECATED_POP 2395*06c3fb27SDimitry Andric __set_long_size(__old_sz - __n_del + __n_add); 2396*06c3fb27SDimitry Andric} 2397*06c3fb27SDimitry Andric 23980b57cec5SDimitry Andric// assign 23990b57cec5SDimitry Andric 24000b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 24015ffd83dbSDimitry Andrictemplate <bool __is_short> 2402bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 24030b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24045ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_no_alias( 24055ffd83dbSDimitry Andric const value_type* __s, size_type __n) { 240681ad6265SDimitry Andric size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap(); 24075ffd83dbSDimitry Andric if (__n < __cap) { 24085ffd83dbSDimitry Andric pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer(); 24095ffd83dbSDimitry Andric __is_short ? __set_short_size(__n) : __set_long_size(__n); 241081ad6265SDimitry Andric traits_type::copy(std::__to_address(__p), __s, __n); 24115ffd83dbSDimitry Andric traits_type::assign(__p[__n], value_type()); 24125ffd83dbSDimitry Andric } else { 24135ffd83dbSDimitry Andric size_type __sz = __is_short ? __get_short_size() : __get_long_size(); 24145ffd83dbSDimitry Andric __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s); 24155ffd83dbSDimitry Andric } 24165ffd83dbSDimitry Andric return *this; 24175ffd83dbSDimitry Andric} 24185ffd83dbSDimitry Andric 24195ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2420bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 24215ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24225ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external( 24235ffd83dbSDimitry Andric const value_type* __s, size_type __n) { 24240b57cec5SDimitry Andric size_type __cap = capacity(); 24255ffd83dbSDimitry Andric if (__cap >= __n) { 242681ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 24270b57cec5SDimitry Andric traits_type::move(__p, __s, __n); 24280eae32dcSDimitry Andric return __null_terminate_at(__p, __n); 24295ffd83dbSDimitry Andric } else { 24300b57cec5SDimitry Andric size_type __sz = size(); 24310b57cec5SDimitry Andric __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); 24320b57cec5SDimitry Andric return *this; 24330b57cec5SDimitry Andric } 24340eae32dcSDimitry Andric} 24350b57cec5SDimitry Andric 24360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2437bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 24380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24395ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) 24405ffd83dbSDimitry Andric{ 2441*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::assign received nullptr"); 244204eeddc0SDimitry Andric return (__builtin_constant_p(__n) && __fits_in_sso(__n)) 24435ffd83dbSDimitry Andric ? __assign_short(__s, __n) 24445ffd83dbSDimitry Andric : __assign_external(__s, __n); 24455ffd83dbSDimitry Andric} 24465ffd83dbSDimitry Andric 24475ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2448bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 24495ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24500b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) 24510b57cec5SDimitry Andric{ 24520b57cec5SDimitry Andric size_type __cap = capacity(); 24530b57cec5SDimitry Andric if (__cap < __n) 24540b57cec5SDimitry Andric { 24550b57cec5SDimitry Andric size_type __sz = size(); 2456*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __n - __cap, __sz, 0, __sz); 24570b57cec5SDimitry Andric } 245881ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 24590b57cec5SDimitry Andric traits_type::assign(__p, __n, __c); 24600eae32dcSDimitry Andric return __null_terminate_at(__p, __n); 24610b57cec5SDimitry Andric} 24620b57cec5SDimitry Andric 24630b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2464bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 24650b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24660b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) 24670b57cec5SDimitry Andric{ 24680b57cec5SDimitry Andric pointer __p; 24690b57cec5SDimitry Andric if (__is_long()) 24700b57cec5SDimitry Andric { 24710b57cec5SDimitry Andric __p = __get_long_pointer(); 24720b57cec5SDimitry Andric __set_long_size(1); 24730b57cec5SDimitry Andric } 24740b57cec5SDimitry Andric else 24750b57cec5SDimitry Andric { 24760b57cec5SDimitry Andric __p = __get_short_pointer(); 24770b57cec5SDimitry Andric __set_short_size(1); 24780b57cec5SDimitry Andric } 24790b57cec5SDimitry Andric traits_type::assign(*__p, __c); 24800b57cec5SDimitry Andric traits_type::assign(*++__p, value_type()); 24810b57cec5SDimitry Andric return *this; 24820b57cec5SDimitry Andric} 24830b57cec5SDimitry Andric 24840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2485bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 24860b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 24870b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) 24880b57cec5SDimitry Andric{ 2489*06c3fb27SDimitry Andric if (this != std::addressof(__str)) { 24900b57cec5SDimitry Andric __copy_assign_alloc(__str); 24915ffd83dbSDimitry Andric if (!__is_long()) { 24925ffd83dbSDimitry Andric if (!__str.__is_long()) { 2493bdd1243dSDimitry Andric __r_.first() = __str.__r_.first(); 24945ffd83dbSDimitry Andric } else { 24955ffd83dbSDimitry Andric return __assign_no_alias<true>(__str.data(), __str.size()); 24965ffd83dbSDimitry Andric } 24975ffd83dbSDimitry Andric } else { 24985ffd83dbSDimitry Andric return __assign_no_alias<false>(__str.data(), __str.size()); 24995ffd83dbSDimitry Andric } 25000b57cec5SDimitry Andric } 25010b57cec5SDimitry Andric return *this; 25020b57cec5SDimitry Andric} 25030b57cec5SDimitry Andric 25040b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 25050b57cec5SDimitry Andric 25060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2507bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 25080b57cec5SDimitry Andricvoid 25090b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) 25100b57cec5SDimitry Andric _NOEXCEPT_(__alloc_traits::is_always_equal::value) 25110b57cec5SDimitry Andric{ 25120b57cec5SDimitry Andric if (__alloc() != __str.__alloc()) 25130b57cec5SDimitry Andric assign(__str); 25140b57cec5SDimitry Andric else 25150b57cec5SDimitry Andric __move_assign(__str, true_type()); 25160b57cec5SDimitry Andric} 25170b57cec5SDimitry Andric 25180b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2519bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 25200b57cec5SDimitry Andricvoid 25210b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) 2522*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17 25230b57cec5SDimitry Andric _NOEXCEPT 25240b57cec5SDimitry Andric#else 25250b57cec5SDimitry Andric _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) 25260b57cec5SDimitry Andric#endif 25270b57cec5SDimitry Andric{ 2528480093f4SDimitry Andric if (__is_long()) { 2529480093f4SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), 2530480093f4SDimitry Andric __get_long_cap()); 2531480093f4SDimitry Andric#if _LIBCPP_STD_VER <= 14 2532480093f4SDimitry Andric if (!is_nothrow_move_assignable<allocator_type>::value) { 2533480093f4SDimitry Andric __set_short_size(0); 2534480093f4SDimitry Andric traits_type::assign(__get_short_pointer()[0], value_type()); 2535480093f4SDimitry Andric } 2536480093f4SDimitry Andric#endif 2537480093f4SDimitry Andric } 25380b57cec5SDimitry Andric __move_assign_alloc(__str); 2539480093f4SDimitry Andric __r_.first() = __str.__r_.first(); 254081ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 254181ad6265SDimitry Andric __str.__default_init(); 254281ad6265SDimitry Andric } else { 2543480093f4SDimitry Andric __str.__set_short_size(0); 2544480093f4SDimitry Andric traits_type::assign(__str.__get_short_pointer()[0], value_type()); 25450b57cec5SDimitry Andric } 254681ad6265SDimitry Andric} 25470b57cec5SDimitry Andric 25480b57cec5SDimitry Andric#endif 25490b57cec5SDimitry Andric 25500b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2551*06c3fb27SDimitry Andrictemplate<class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2552*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 25530b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) 25540b57cec5SDimitry Andric{ 2555*06c3fb27SDimitry Andric __assign_with_sentinel(__first, __last); 25560b57cec5SDimitry Andric return *this; 25570b57cec5SDimitry Andric} 25580b57cec5SDimitry Andric 25590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2560*06c3fb27SDimitry Andrictemplate <class _InputIterator, class _Sentinel> 2561*06c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 2562*06c3fb27SDimitry Andricvoid 2563*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_with_sentinel(_InputIterator __first, _Sentinel __last) { 2564*06c3fb27SDimitry Andric const basic_string __temp(__init_with_sentinel_tag(), std::move(__first), std::move(__last), __alloc()); 2565*06c3fb27SDimitry Andric assign(__temp.data(), __temp.size()); 2566*06c3fb27SDimitry Andric} 2567*06c3fb27SDimitry Andric 2568*06c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2569*06c3fb27SDimitry Andrictemplate<class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2570*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 25710b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) 25720b57cec5SDimitry Andric{ 2573*06c3fb27SDimitry Andric if (__string_is_trivial_iterator<_ForwardIterator>::value) { 2574*06c3fb27SDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 2575*06c3fb27SDimitry Andric __assign_trivial(__first, __last, __n); 2576*06c3fb27SDimitry Andric } else { 2577*06c3fb27SDimitry Andric __assign_with_sentinel(__first, __last); 2578*06c3fb27SDimitry Andric } 2579fe6060f1SDimitry Andric 2580*06c3fb27SDimitry Andric return *this; 2581*06c3fb27SDimitry Andric} 2582*06c3fb27SDimitry Andric 2583*06c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2584*06c3fb27SDimitry Andrictemplate <class _Iterator, class _Sentinel> 2585*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 2586*06c3fb27SDimitry Andricvoid 2587*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_trivial(_Iterator __first, _Sentinel __last, size_type __n) { 2588*06c3fb27SDimitry Andric _LIBCPP_ASSERT_INTERNAL( 2589*06c3fb27SDimitry Andric __string_is_trivial_iterator<_Iterator>::value, "The iterator type given to `__assign_trivial` must be trivial"); 2590*06c3fb27SDimitry Andric 2591*06c3fb27SDimitry Andric size_type __cap = capacity(); 2592*06c3fb27SDimitry Andric if (__cap < __n) { 2593*06c3fb27SDimitry Andric // Unlike `append` functions, if the input range points into the string itself, there is no case that the input 2594*06c3fb27SDimitry Andric // range could get invalidated by reallocation: 2595*06c3fb27SDimitry Andric // 1. If the input range is a subset of the string itself, its size cannot exceed the capacity of the string, 2596*06c3fb27SDimitry Andric // thus no reallocation would happen. 2597*06c3fb27SDimitry Andric // 2. In the exotic case where the input range is the byte representation of the string itself, the string 2598*06c3fb27SDimitry Andric // object itself stays valid even if reallocation happens. 25990b57cec5SDimitry Andric size_type __sz = size(); 2600*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __n - __cap, __sz, 0, __sz); 26010b57cec5SDimitry Andric } 26020b57cec5SDimitry Andric pointer __p = __get_pointer(); 2603349cc55cSDimitry Andric for (; __first != __last; ++__p, (void) ++__first) 26040b57cec5SDimitry Andric traits_type::assign(*__p, *__first); 26050b57cec5SDimitry Andric traits_type::assign(*__p, value_type()); 26060b57cec5SDimitry Andric __set_size(__n); 26070b57cec5SDimitry Andric} 26080b57cec5SDimitry Andric 26090b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2610bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26110b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) 26130b57cec5SDimitry Andric{ 26140b57cec5SDimitry Andric size_type __sz = __str.size(); 26150b57cec5SDimitry Andric if (__pos > __sz) 261604eeddc0SDimitry Andric __throw_out_of_range(); 261781ad6265SDimitry Andric return assign(__str.data() + __pos, std::min(__n, __sz - __pos)); 26180b57cec5SDimitry Andric} 26190b57cec5SDimitry Andric 26200b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2621*06c3fb27SDimitry Andrictemplate <class _Tp, 2622*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 2623*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 2624*06c3fb27SDimitry Andric int> > 2625*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 2626*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const _Tp& __t, size_type __pos, size_type __n) { 26270b57cec5SDimitry Andric __self_view __sv = __t; 26280b57cec5SDimitry Andric size_type __sz = __sv.size(); 26290b57cec5SDimitry Andric if (__pos > __sz) 263004eeddc0SDimitry Andric __throw_out_of_range(); 263181ad6265SDimitry Andric return assign(__sv.data() + __pos, std::min(__n, __sz - __pos)); 26320b57cec5SDimitry Andric} 26330b57cec5SDimitry Andric 26340b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2635bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26360b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26375ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) { 26385ffd83dbSDimitry Andric return __assign_external(__s, traits_type::length(__s)); 26395ffd83dbSDimitry Andric} 26405ffd83dbSDimitry Andric 26415ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2642bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26435ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26440b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) 26450b57cec5SDimitry Andric{ 2646*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::assign received nullptr"); 2647349cc55cSDimitry Andric return __builtin_constant_p(*__s) 264804eeddc0SDimitry Andric ? (__fits_in_sso(traits_type::length(__s)) 26495ffd83dbSDimitry Andric ? __assign_short(__s, traits_type::length(__s)) 26505ffd83dbSDimitry Andric : __assign_external(__s, traits_type::length(__s))) 26515ffd83dbSDimitry Andric : __assign_external(__s); 26520b57cec5SDimitry Andric} 26530b57cec5SDimitry Andric// append 26540b57cec5SDimitry Andric 26550b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2656bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26570b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26580b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) 26590b57cec5SDimitry Andric{ 2660*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::append received nullptr"); 26610b57cec5SDimitry Andric size_type __cap = capacity(); 26620b57cec5SDimitry Andric size_type __sz = size(); 26630b57cec5SDimitry Andric if (__cap - __sz >= __n) 26640b57cec5SDimitry Andric { 26650b57cec5SDimitry Andric if (__n) 26660b57cec5SDimitry Andric { 266781ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 26680b57cec5SDimitry Andric traits_type::copy(__p + __sz, __s, __n); 26690b57cec5SDimitry Andric __sz += __n; 26700b57cec5SDimitry Andric __set_size(__sz); 26710b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 26720b57cec5SDimitry Andric } 26730b57cec5SDimitry Andric } 26740b57cec5SDimitry Andric else 26750b57cec5SDimitry Andric __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); 26760b57cec5SDimitry Andric return *this; 26770b57cec5SDimitry Andric} 26780b57cec5SDimitry Andric 26790b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2680bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 26810b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 26820b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) 26830b57cec5SDimitry Andric{ 26840b57cec5SDimitry Andric if (__n) 26850b57cec5SDimitry Andric { 26860b57cec5SDimitry Andric size_type __cap = capacity(); 26870b57cec5SDimitry Andric size_type __sz = size(); 26880b57cec5SDimitry Andric if (__cap - __sz < __n) 2689*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0); 26900b57cec5SDimitry Andric pointer __p = __get_pointer(); 269181ad6265SDimitry Andric traits_type::assign(std::__to_address(__p) + __sz, __n, __c); 26920b57cec5SDimitry Andric __sz += __n; 26930b57cec5SDimitry Andric __set_size(__sz); 26940b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 26950b57cec5SDimitry Andric } 26960b57cec5SDimitry Andric return *this; 26970b57cec5SDimitry Andric} 26980b57cec5SDimitry Andric 26990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2700bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void 27010b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) 27020b57cec5SDimitry Andric{ 27030b57cec5SDimitry Andric if (__n) 27040b57cec5SDimitry Andric { 27050b57cec5SDimitry Andric size_type __cap = capacity(); 27060b57cec5SDimitry Andric size_type __sz = size(); 27070b57cec5SDimitry Andric if (__cap - __sz < __n) 2708*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0); 27090b57cec5SDimitry Andric pointer __p = __get_pointer(); 27100b57cec5SDimitry Andric __sz += __n; 27110b57cec5SDimitry Andric __set_size(__sz); 27120b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 27130b57cec5SDimitry Andric } 27140b57cec5SDimitry Andric} 27150b57cec5SDimitry Andric 27160b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2717bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 27180b57cec5SDimitry Andricvoid 27190b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) 27200b57cec5SDimitry Andric{ 27210b57cec5SDimitry Andric bool __is_short = !__is_long(); 27220b57cec5SDimitry Andric size_type __cap; 27230b57cec5SDimitry Andric size_type __sz; 27240b57cec5SDimitry Andric if (__is_short) 27250b57cec5SDimitry Andric { 27260b57cec5SDimitry Andric __cap = __min_cap - 1; 27270b57cec5SDimitry Andric __sz = __get_short_size(); 27280b57cec5SDimitry Andric } 27290b57cec5SDimitry Andric else 27300b57cec5SDimitry Andric { 27310b57cec5SDimitry Andric __cap = __get_long_cap() - 1; 27320b57cec5SDimitry Andric __sz = __get_long_size(); 27330b57cec5SDimitry Andric } 27340b57cec5SDimitry Andric if (__sz == __cap) 27350b57cec5SDimitry Andric { 2736*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, 1, __sz, __sz, 0); 2737349cc55cSDimitry Andric __is_short = false; // the string is always long after __grow_by 27380b57cec5SDimitry Andric } 273981ad6265SDimitry Andric pointer __p = __get_pointer(); 27400b57cec5SDimitry Andric if (__is_short) 27410b57cec5SDimitry Andric { 27420b57cec5SDimitry Andric __p = __get_short_pointer() + __sz; 27430b57cec5SDimitry Andric __set_short_size(__sz+1); 27440b57cec5SDimitry Andric } 27450b57cec5SDimitry Andric else 27460b57cec5SDimitry Andric { 27470b57cec5SDimitry Andric __p = __get_long_pointer() + __sz; 27480b57cec5SDimitry Andric __set_long_size(__sz+1); 27490b57cec5SDimitry Andric } 27500b57cec5SDimitry Andric traits_type::assign(*__p, __c); 27510b57cec5SDimitry Andric traits_type::assign(*++__p, value_type()); 27520b57cec5SDimitry Andric} 27530b57cec5SDimitry Andric 27540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2755*06c3fb27SDimitry Andrictemplate<class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2756*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 2757fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append( 27580b57cec5SDimitry Andric _ForwardIterator __first, _ForwardIterator __last) 27590b57cec5SDimitry Andric{ 27600b57cec5SDimitry Andric size_type __sz = size(); 27610b57cec5SDimitry Andric size_type __cap = capacity(); 276281ad6265SDimitry Andric size_type __n = static_cast<size_type>(std::distance(__first, __last)); 27630b57cec5SDimitry Andric if (__n) 27640b57cec5SDimitry Andric { 2765fe6060f1SDimitry Andric if (__string_is_trivial_iterator<_ForwardIterator>::value && 2766fe6060f1SDimitry Andric !__addr_in_range(*__first)) 27670b57cec5SDimitry Andric { 27680b57cec5SDimitry Andric if (__cap - __sz < __n) 2769*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __sz, 0); 27700b57cec5SDimitry Andric pointer __p = __get_pointer() + __sz; 2771349cc55cSDimitry Andric for (; __first != __last; ++__p, (void) ++__first) 27720b57cec5SDimitry Andric traits_type::assign(*__p, *__first); 27730b57cec5SDimitry Andric traits_type::assign(*__p, value_type()); 27740b57cec5SDimitry Andric __set_size(__sz + __n); 27750b57cec5SDimitry Andric } 2776fe6060f1SDimitry Andric else 2777fe6060f1SDimitry Andric { 2778fe6060f1SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 2779fe6060f1SDimitry Andric append(__temp.data(), __temp.size()); 2780fe6060f1SDimitry Andric } 27810b57cec5SDimitry Andric } 27820b57cec5SDimitry Andric return *this; 27830b57cec5SDimitry Andric} 27840b57cec5SDimitry Andric 27850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2786bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 27870b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 27880b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) 27890b57cec5SDimitry Andric{ 27900b57cec5SDimitry Andric size_type __sz = __str.size(); 27910b57cec5SDimitry Andric if (__pos > __sz) 279204eeddc0SDimitry Andric __throw_out_of_range(); 279381ad6265SDimitry Andric return append(__str.data() + __pos, std::min(__n, __sz - __pos)); 27940b57cec5SDimitry Andric} 27950b57cec5SDimitry Andric 27960b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2797*06c3fb27SDimitry Andrictemplate <class _Tp, 2798*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 2799*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 2800*06c3fb27SDimitry Andric int> > 2801*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 2802*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const _Tp& __t, size_type __pos, size_type __n) { 28030b57cec5SDimitry Andric __self_view __sv = __t; 28040b57cec5SDimitry Andric size_type __sz = __sv.size(); 28050b57cec5SDimitry Andric if (__pos > __sz) 280604eeddc0SDimitry Andric __throw_out_of_range(); 280781ad6265SDimitry Andric return append(__sv.data() + __pos, std::min(__n, __sz - __pos)); 28080b57cec5SDimitry Andric} 28090b57cec5SDimitry Andric 28100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2811bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 28120b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) 28140b57cec5SDimitry Andric{ 2815*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::append received nullptr"); 28160b57cec5SDimitry Andric return append(__s, traits_type::length(__s)); 28170b57cec5SDimitry Andric} 28180b57cec5SDimitry Andric 28190b57cec5SDimitry Andric// insert 28200b57cec5SDimitry Andric 28210b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2822bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 28230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28240b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) 28250b57cec5SDimitry Andric{ 2826*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::insert received nullptr"); 28270b57cec5SDimitry Andric size_type __sz = size(); 28280b57cec5SDimitry Andric if (__pos > __sz) 282904eeddc0SDimitry Andric __throw_out_of_range(); 28300b57cec5SDimitry Andric size_type __cap = capacity(); 283181ad6265SDimitry Andric if (__libcpp_is_constant_evaluated()) { 283281ad6265SDimitry Andric if (__cap - __sz >= __n) 283381ad6265SDimitry Andric __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s); 283481ad6265SDimitry Andric else 283581ad6265SDimitry Andric __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); 283681ad6265SDimitry Andric return *this; 283781ad6265SDimitry Andric } 28380b57cec5SDimitry Andric if (__cap - __sz >= __n) 28390b57cec5SDimitry Andric { 28400b57cec5SDimitry Andric if (__n) 28410b57cec5SDimitry Andric { 284281ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 28430b57cec5SDimitry Andric size_type __n_move = __sz - __pos; 28440b57cec5SDimitry Andric if (__n_move != 0) 28450b57cec5SDimitry Andric { 28460b57cec5SDimitry Andric if (__p + __pos <= __s && __s < __p + __sz) 28470b57cec5SDimitry Andric __s += __n; 28480b57cec5SDimitry Andric traits_type::move(__p + __pos + __n, __p + __pos, __n_move); 28490b57cec5SDimitry Andric } 28500b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n); 28510b57cec5SDimitry Andric __sz += __n; 28520b57cec5SDimitry Andric __set_size(__sz); 28530b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 28540b57cec5SDimitry Andric } 28550b57cec5SDimitry Andric } 28560b57cec5SDimitry Andric else 28570b57cec5SDimitry Andric __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); 28580b57cec5SDimitry Andric return *this; 28590b57cec5SDimitry Andric} 28600b57cec5SDimitry Andric 28610b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2862bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 28630b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 28640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) 28650b57cec5SDimitry Andric{ 28660b57cec5SDimitry Andric size_type __sz = size(); 28670b57cec5SDimitry Andric if (__pos > __sz) 286804eeddc0SDimitry Andric __throw_out_of_range(); 28690b57cec5SDimitry Andric if (__n) 28700b57cec5SDimitry Andric { 28710b57cec5SDimitry Andric size_type __cap = capacity(); 28720b57cec5SDimitry Andric value_type* __p; 28730b57cec5SDimitry Andric if (__cap - __sz >= __n) 28740b57cec5SDimitry Andric { 287581ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 28760b57cec5SDimitry Andric size_type __n_move = __sz - __pos; 28770b57cec5SDimitry Andric if (__n_move != 0) 28780b57cec5SDimitry Andric traits_type::move(__p + __pos + __n, __p + __pos, __n_move); 28790b57cec5SDimitry Andric } 28800b57cec5SDimitry Andric else 28810b57cec5SDimitry Andric { 2882*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); 288381ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 28840b57cec5SDimitry Andric } 28850b57cec5SDimitry Andric traits_type::assign(__p + __pos, __n, __c); 28860b57cec5SDimitry Andric __sz += __n; 28870b57cec5SDimitry Andric __set_size(__sz); 28880b57cec5SDimitry Andric traits_type::assign(__p[__sz], value_type()); 28890b57cec5SDimitry Andric } 28900b57cec5SDimitry Andric return *this; 28910b57cec5SDimitry Andric} 28920b57cec5SDimitry Andric 28930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2894*06c3fb27SDimitry Andrictemplate<class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> > 2895*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::iterator 28960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) 28970b57cec5SDimitry Andric{ 28980b57cec5SDimitry Andric const basic_string __temp(__first, __last, __alloc()); 28990b57cec5SDimitry Andric return insert(__pos, __temp.data(), __temp.data() + __temp.size()); 29000b57cec5SDimitry Andric} 29010b57cec5SDimitry Andric 29020b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2903*06c3fb27SDimitry Andrictemplate<class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> > 2904*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::iterator 29050b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) 29060b57cec5SDimitry Andric{ 2907*06c3fb27SDimitry Andric auto __n = static_cast<size_type>(std::distance(__first, __last)); 2908*06c3fb27SDimitry Andric return __insert_with_size(__pos, __first, __last, __n); 2909*06c3fb27SDimitry Andric} 29100eae32dcSDimitry Andric 2911*06c3fb27SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2912*06c3fb27SDimitry Andrictemplate<class _Iterator, class _Sentinel> 2913*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 2914*06c3fb27SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 2915*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__insert_with_size( 2916*06c3fb27SDimitry Andric const_iterator __pos, _Iterator __first, _Sentinel __last, size_type __n) { 29170b57cec5SDimitry Andric size_type __ip = static_cast<size_type>(__pos - begin()); 291881ad6265SDimitry Andric if (__n == 0) 291981ad6265SDimitry Andric return begin() + __ip; 292081ad6265SDimitry Andric 2921*06c3fb27SDimitry Andric if (__string_is_trivial_iterator<_Iterator>::value && !__addr_in_range(*__first)) 29220b57cec5SDimitry Andric { 292381ad6265SDimitry Andric return __insert_from_safe_copy(__n, __ip, __first, __last); 29240b57cec5SDimitry Andric } 2925fe6060f1SDimitry Andric else 2926fe6060f1SDimitry Andric { 2927*06c3fb27SDimitry Andric const basic_string __temp(__init_with_sentinel_tag(), __first, __last, __alloc()); 292881ad6265SDimitry Andric return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end()); 2929fe6060f1SDimitry Andric } 2930fe6060f1SDimitry Andric} 29310b57cec5SDimitry Andric 29320b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2933bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 29340b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 29350b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, 29360b57cec5SDimitry Andric size_type __pos2, size_type __n) 29370b57cec5SDimitry Andric{ 29380b57cec5SDimitry Andric size_type __str_sz = __str.size(); 29390b57cec5SDimitry Andric if (__pos2 > __str_sz) 294004eeddc0SDimitry Andric __throw_out_of_range(); 294181ad6265SDimitry Andric return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2)); 29420b57cec5SDimitry Andric} 29430b57cec5SDimitry Andric 29440b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2945*06c3fb27SDimitry Andrictemplate <class _Tp, 2946*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 2947*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 2948*06c3fb27SDimitry Andric int> > 2949*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 2950*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n) { 29510b57cec5SDimitry Andric __self_view __sv = __t; 29520b57cec5SDimitry Andric size_type __str_sz = __sv.size(); 29530b57cec5SDimitry Andric if (__pos2 > __str_sz) 295404eeddc0SDimitry Andric __throw_out_of_range(); 295581ad6265SDimitry Andric return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2)); 29560b57cec5SDimitry Andric} 29570b57cec5SDimitry Andric 29580b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2959bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 29600b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 29610b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) 29620b57cec5SDimitry Andric{ 2963*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::insert received nullptr"); 29640b57cec5SDimitry Andric return insert(__pos, __s, traits_type::length(__s)); 29650b57cec5SDimitry Andric} 29660b57cec5SDimitry Andric 29670b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2968bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 29690b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 29700b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) 29710b57cec5SDimitry Andric{ 29720b57cec5SDimitry Andric size_type __ip = static_cast<size_type>(__pos - begin()); 29730b57cec5SDimitry Andric size_type __sz = size(); 29740b57cec5SDimitry Andric size_type __cap = capacity(); 29750b57cec5SDimitry Andric value_type* __p; 29760b57cec5SDimitry Andric if (__cap == __sz) 29770b57cec5SDimitry Andric { 2978*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, 1, __sz, __ip, 0, 1); 297981ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 29800b57cec5SDimitry Andric } 29810b57cec5SDimitry Andric else 29820b57cec5SDimitry Andric { 298381ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 29840b57cec5SDimitry Andric size_type __n_move = __sz - __ip; 29850b57cec5SDimitry Andric if (__n_move != 0) 29860b57cec5SDimitry Andric traits_type::move(__p + __ip + 1, __p + __ip, __n_move); 29870b57cec5SDimitry Andric } 29880b57cec5SDimitry Andric traits_type::assign(__p[__ip], __c); 29890b57cec5SDimitry Andric traits_type::assign(__p[++__sz], value_type()); 29900b57cec5SDimitry Andric __set_size(__sz); 29910b57cec5SDimitry Andric return begin() + static_cast<difference_type>(__ip); 29920b57cec5SDimitry Andric} 29930b57cec5SDimitry Andric 29940b57cec5SDimitry Andric// replace 29950b57cec5SDimitry Andric 29960b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 2997bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 29980b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 29990b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) 30000b57cec5SDimitry Andric _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK 30010b57cec5SDimitry Andric{ 3002*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); 30030b57cec5SDimitry Andric size_type __sz = size(); 30040b57cec5SDimitry Andric if (__pos > __sz) 300504eeddc0SDimitry Andric __throw_out_of_range(); 300681ad6265SDimitry Andric __n1 = std::min(__n1, __sz - __pos); 30070b57cec5SDimitry Andric size_type __cap = capacity(); 30080b57cec5SDimitry Andric if (__cap - __sz + __n1 >= __n2) 30090b57cec5SDimitry Andric { 301081ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 30110b57cec5SDimitry Andric if (__n1 != __n2) 30120b57cec5SDimitry Andric { 30130b57cec5SDimitry Andric size_type __n_move = __sz - __pos - __n1; 30140b57cec5SDimitry Andric if (__n_move != 0) 30150b57cec5SDimitry Andric { 30160b57cec5SDimitry Andric if (__n1 > __n2) 30170b57cec5SDimitry Andric { 30180b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n2); 30190b57cec5SDimitry Andric traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 30200eae32dcSDimitry Andric return __null_terminate_at(__p, __sz + (__n2 - __n1)); 30210b57cec5SDimitry Andric } 3022*06c3fb27SDimitry Andric if (std::__is_pointer_in_range(__p + __pos + 1, __p + __sz, __s)) 30230b57cec5SDimitry Andric { 30240b57cec5SDimitry Andric if (__p + __pos + __n1 <= __s) 30250b57cec5SDimitry Andric __s += __n2 - __n1; 30260b57cec5SDimitry Andric else // __p + __pos < __s < __p + __pos + __n1 30270b57cec5SDimitry Andric { 30280b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n1); 30290b57cec5SDimitry Andric __pos += __n1; 30300b57cec5SDimitry Andric __s += __n2; 30310b57cec5SDimitry Andric __n2 -= __n1; 30320b57cec5SDimitry Andric __n1 = 0; 30330b57cec5SDimitry Andric } 30340b57cec5SDimitry Andric } 30350b57cec5SDimitry Andric traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 30360b57cec5SDimitry Andric } 30370b57cec5SDimitry Andric } 30380b57cec5SDimitry Andric traits_type::move(__p + __pos, __s, __n2); 30390eae32dcSDimitry Andric return __null_terminate_at(__p, __sz + (__n2 - __n1)); 30400b57cec5SDimitry Andric } 30410b57cec5SDimitry Andric else 30420b57cec5SDimitry Andric __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); 30430b57cec5SDimitry Andric return *this; 30440b57cec5SDimitry Andric} 30450b57cec5SDimitry Andric 30460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3047bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 30480b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 30490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) 30500b57cec5SDimitry Andric{ 30510b57cec5SDimitry Andric size_type __sz = size(); 30520b57cec5SDimitry Andric if (__pos > __sz) 305304eeddc0SDimitry Andric __throw_out_of_range(); 305481ad6265SDimitry Andric __n1 = std::min(__n1, __sz - __pos); 30550b57cec5SDimitry Andric size_type __cap = capacity(); 30560b57cec5SDimitry Andric value_type* __p; 30570b57cec5SDimitry Andric if (__cap - __sz + __n1 >= __n2) 30580b57cec5SDimitry Andric { 305981ad6265SDimitry Andric __p = std::__to_address(__get_pointer()); 30600b57cec5SDimitry Andric if (__n1 != __n2) 30610b57cec5SDimitry Andric { 30620b57cec5SDimitry Andric size_type __n_move = __sz - __pos - __n1; 30630b57cec5SDimitry Andric if (__n_move != 0) 30640b57cec5SDimitry Andric traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); 30650b57cec5SDimitry Andric } 30660b57cec5SDimitry Andric } 30670b57cec5SDimitry Andric else 30680b57cec5SDimitry Andric { 3069*06c3fb27SDimitry Andric __grow_by_without_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); 307081ad6265SDimitry Andric __p = std::__to_address(__get_long_pointer()); 30710b57cec5SDimitry Andric } 30720b57cec5SDimitry Andric traits_type::assign(__p + __pos, __n2, __c); 30730eae32dcSDimitry Andric return __null_terminate_at(__p, __sz - (__n1 - __n2)); 30740b57cec5SDimitry Andric} 30750b57cec5SDimitry Andric 30760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3077*06c3fb27SDimitry Andrictemplate<class _InputIterator, __enable_if_t<__has_input_iterator_category<_InputIterator>::value, int> > 3078*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 30790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, 30800b57cec5SDimitry Andric _InputIterator __j1, _InputIterator __j2) 30810b57cec5SDimitry Andric{ 30820b57cec5SDimitry Andric const basic_string __temp(__j1, __j2, __alloc()); 308304eeddc0SDimitry Andric return replace(__i1, __i2, __temp); 30840b57cec5SDimitry Andric} 30850b57cec5SDimitry Andric 30860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3087bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 30880b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 30890b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, 30900b57cec5SDimitry Andric size_type __pos2, size_type __n2) 30910b57cec5SDimitry Andric{ 30920b57cec5SDimitry Andric size_type __str_sz = __str.size(); 30930b57cec5SDimitry Andric if (__pos2 > __str_sz) 309404eeddc0SDimitry Andric __throw_out_of_range(); 309581ad6265SDimitry Andric return replace(__pos1, __n1, __str.data() + __pos2, std::min(__n2, __str_sz - __pos2)); 30960b57cec5SDimitry Andric} 30970b57cec5SDimitry Andric 30980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3099*06c3fb27SDimitry Andrictemplate <class _Tp, 3100*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 3101*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 3102*06c3fb27SDimitry Andric int> > 3103*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>& 3104*06c3fb27SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace( 3105*06c3fb27SDimitry Andric size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2) { 31060b57cec5SDimitry Andric __self_view __sv = __t; 31070b57cec5SDimitry Andric size_type __str_sz = __sv.size(); 31080b57cec5SDimitry Andric if (__pos2 > __str_sz) 310904eeddc0SDimitry Andric __throw_out_of_range(); 311081ad6265SDimitry Andric return replace(__pos1, __n1, __sv.data() + __pos2, std::min(__n2, __str_sz - __pos2)); 31110b57cec5SDimitry Andric} 31120b57cec5SDimitry Andric 31130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3114bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 31150b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 31160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) 31170b57cec5SDimitry Andric{ 3118*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::replace received nullptr"); 31190b57cec5SDimitry Andric return replace(__pos, __n1, __s, traits_type::length(__s)); 31200b57cec5SDimitry Andric} 31210b57cec5SDimitry Andric 31220b57cec5SDimitry Andric// erase 31230b57cec5SDimitry Andric 31245ffd83dbSDimitry Andric// 'externally instantiated' erase() implementation, called when __n != npos. 31255ffd83dbSDimitry Andric// Does not check __pos against size() 31260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3127bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 31285ffd83dbSDimitry Andricvoid 31295ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( 31305ffd83dbSDimitry Andric size_type __pos, size_type __n) 31310b57cec5SDimitry Andric{ 31320b57cec5SDimitry Andric if (__n) 31330b57cec5SDimitry Andric { 31345ffd83dbSDimitry Andric size_type __sz = size(); 313581ad6265SDimitry Andric value_type* __p = std::__to_address(__get_pointer()); 313681ad6265SDimitry Andric __n = std::min(__n, __sz - __pos); 31370b57cec5SDimitry Andric size_type __n_move = __sz - __pos - __n; 31380b57cec5SDimitry Andric if (__n_move != 0) 31390b57cec5SDimitry Andric traits_type::move(__p + __pos, __p + __pos + __n, __n_move); 31400eae32dcSDimitry Andric __null_terminate_at(__p, __sz - __n); 31410b57cec5SDimitry Andric } 31425ffd83dbSDimitry Andric} 31435ffd83dbSDimitry Andric 31445ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3145bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 31465ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>& 31475ffd83dbSDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, 31485ffd83dbSDimitry Andric size_type __n) { 314904eeddc0SDimitry Andric if (__pos > size()) 315004eeddc0SDimitry Andric __throw_out_of_range(); 31515ffd83dbSDimitry Andric if (__n == npos) { 31525ffd83dbSDimitry Andric __erase_to_end(__pos); 31535ffd83dbSDimitry Andric } else { 31545ffd83dbSDimitry Andric __erase_external_with_move(__pos, __n); 31555ffd83dbSDimitry Andric } 31560b57cec5SDimitry Andric return *this; 31570b57cec5SDimitry Andric} 31580b57cec5SDimitry Andric 31590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3160bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 31610b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 31620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) 31630b57cec5SDimitry Andric{ 3164*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS( 3165*06c3fb27SDimitry Andric __pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); 31660b57cec5SDimitry Andric iterator __b = begin(); 31670b57cec5SDimitry Andric size_type __r = static_cast<size_type>(__pos - __b); 31680b57cec5SDimitry Andric erase(__r, 1); 31690b57cec5SDimitry Andric return __b + static_cast<difference_type>(__r); 31700b57cec5SDimitry Andric} 31710b57cec5SDimitry Andric 31720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3173bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 31740b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::iterator 31750b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) 31760b57cec5SDimitry Andric{ 3177*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_INPUT_RANGE(__first <= __last, "string::erase(first, last) called with invalid range"); 31780b57cec5SDimitry Andric iterator __b = begin(); 31790b57cec5SDimitry Andric size_type __r = static_cast<size_type>(__first - __b); 31800b57cec5SDimitry Andric erase(__r, static_cast<size_type>(__last - __first)); 31810b57cec5SDimitry Andric return __b + static_cast<difference_type>(__r); 31820b57cec5SDimitry Andric} 31830b57cec5SDimitry Andric 31840b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3185bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 31860b57cec5SDimitry Andricvoid 31870b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::pop_back() 31880b57cec5SDimitry Andric{ 3189*06c3fb27SDimitry Andric _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string::pop_back(): string is already empty"); 31900eae32dcSDimitry Andric __erase_to_end(size() - 1); 31910b57cec5SDimitry Andric} 31920b57cec5SDimitry Andric 31930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3194bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 31950b57cec5SDimitry Andricvoid 31960b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT 31970b57cec5SDimitry Andric{ 31980b57cec5SDimitry Andric if (__is_long()) 31990b57cec5SDimitry Andric { 32000b57cec5SDimitry Andric traits_type::assign(*__get_long_pointer(), value_type()); 32010b57cec5SDimitry Andric __set_long_size(0); 32020b57cec5SDimitry Andric } 32030b57cec5SDimitry Andric else 32040b57cec5SDimitry Andric { 32050b57cec5SDimitry Andric traits_type::assign(*__get_short_pointer(), value_type()); 32060b57cec5SDimitry Andric __set_short_size(0); 32070b57cec5SDimitry Andric } 32080b57cec5SDimitry Andric} 32090b57cec5SDimitry Andric 32100b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3211bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 32120b57cec5SDimitry Andricvoid 32130b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) 32140b57cec5SDimitry Andric{ 32150b57cec5SDimitry Andric size_type __sz = size(); 32160b57cec5SDimitry Andric if (__n > __sz) 32170b57cec5SDimitry Andric append(__n - __sz, __c); 32180b57cec5SDimitry Andric else 32190b57cec5SDimitry Andric __erase_to_end(__n); 32200b57cec5SDimitry Andric} 32210b57cec5SDimitry Andric 32220b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3223bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 inline void 32240b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) 32250b57cec5SDimitry Andric{ 32260b57cec5SDimitry Andric size_type __sz = size(); 32270b57cec5SDimitry Andric if (__n > __sz) { 32280b57cec5SDimitry Andric __append_default_init(__n - __sz); 32290b57cec5SDimitry Andric } else 32300b57cec5SDimitry Andric __erase_to_end(__n); 32310b57cec5SDimitry Andric} 32320b57cec5SDimitry Andric 32330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3234bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 32350b57cec5SDimitry Andricvoid 3236e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) 32370b57cec5SDimitry Andric{ 3238e8d8bef9SDimitry Andric if (__requested_capacity > max_size()) 323904eeddc0SDimitry Andric __throw_length_error(); 3240e8d8bef9SDimitry Andric 324104eeddc0SDimitry Andric // Make sure reserve(n) never shrinks. This is technically only required in C++20 324204eeddc0SDimitry Andric // and later (since P0966R1), however we provide consistent behavior in all Standard 324304eeddc0SDimitry Andric // modes because this function is instantiated in the shared library. 324404eeddc0SDimitry Andric if (__requested_capacity <= capacity()) 324504eeddc0SDimitry Andric return; 3246e8d8bef9SDimitry Andric 324781ad6265SDimitry Andric size_type __target_capacity = std::max(__requested_capacity, size()); 3248e8d8bef9SDimitry Andric __target_capacity = __recommend(__target_capacity); 3249e8d8bef9SDimitry Andric if (__target_capacity == capacity()) return; 3250e8d8bef9SDimitry Andric 3251e8d8bef9SDimitry Andric __shrink_or_extend(__target_capacity); 3252e8d8bef9SDimitry Andric} 3253e8d8bef9SDimitry Andric 3254e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3255bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 3256e8d8bef9SDimitry Andricvoid 3257e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT 3258e8d8bef9SDimitry Andric{ 3259e8d8bef9SDimitry Andric size_type __target_capacity = __recommend(size()); 3260e8d8bef9SDimitry Andric if (__target_capacity == capacity()) return; 3261e8d8bef9SDimitry Andric 3262e8d8bef9SDimitry Andric __shrink_or_extend(__target_capacity); 3263e8d8bef9SDimitry Andric} 3264e8d8bef9SDimitry Andric 3265e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3266bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 3267e8d8bef9SDimitry Andricvoid 3268e8d8bef9SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) 3269e8d8bef9SDimitry Andric{ 32700b57cec5SDimitry Andric size_type __cap = capacity(); 32710b57cec5SDimitry Andric size_type __sz = size(); 3272e8d8bef9SDimitry Andric 32730b57cec5SDimitry Andric pointer __new_data, __p; 32740b57cec5SDimitry Andric bool __was_long, __now_long; 327581ad6265SDimitry Andric if (__fits_in_sso(__target_capacity)) 32760b57cec5SDimitry Andric { 32770b57cec5SDimitry Andric __was_long = true; 32780b57cec5SDimitry Andric __now_long = false; 32790b57cec5SDimitry Andric __new_data = __get_short_pointer(); 32800b57cec5SDimitry Andric __p = __get_long_pointer(); 32810b57cec5SDimitry Andric } 32820b57cec5SDimitry Andric else 32830b57cec5SDimitry Andric { 328481ad6265SDimitry Andric if (__target_capacity > __cap) { 328581ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); 328681ad6265SDimitry Andric __new_data = __allocation.ptr; 328781ad6265SDimitry Andric __target_capacity = __allocation.count - 1; 328881ad6265SDimitry Andric } 32890b57cec5SDimitry Andric else 32900b57cec5SDimitry Andric { 3291*06c3fb27SDimitry Andric #ifndef _LIBCPP_HAS_NO_EXCEPTIONS 32920b57cec5SDimitry Andric try 32930b57cec5SDimitry Andric { 3294*06c3fb27SDimitry Andric #endif // _LIBCPP_HAS_NO_EXCEPTIONS 329581ad6265SDimitry Andric auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); 329681ad6265SDimitry Andric __new_data = __allocation.ptr; 329781ad6265SDimitry Andric __target_capacity = __allocation.count - 1; 3298*06c3fb27SDimitry Andric #ifndef _LIBCPP_HAS_NO_EXCEPTIONS 32990b57cec5SDimitry Andric } 33000b57cec5SDimitry Andric catch (...) 33010b57cec5SDimitry Andric { 33020b57cec5SDimitry Andric return; 33030b57cec5SDimitry Andric } 3304*06c3fb27SDimitry Andric #else // _LIBCPP_HAS_NO_EXCEPTIONS 33050b57cec5SDimitry Andric if (__new_data == nullptr) 33060b57cec5SDimitry Andric return; 3307*06c3fb27SDimitry Andric #endif // _LIBCPP_HAS_NO_EXCEPTIONS 33080b57cec5SDimitry Andric } 330981ad6265SDimitry Andric __begin_lifetime(__new_data, __target_capacity + 1); 33100b57cec5SDimitry Andric __now_long = true; 33110b57cec5SDimitry Andric __was_long = __is_long(); 33120b57cec5SDimitry Andric __p = __get_pointer(); 33130b57cec5SDimitry Andric } 331481ad6265SDimitry Andric traits_type::copy(std::__to_address(__new_data), 331581ad6265SDimitry Andric std::__to_address(__p), size()+1); 33160b57cec5SDimitry Andric if (__was_long) 33170b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __p, __cap+1); 33180b57cec5SDimitry Andric if (__now_long) 33190b57cec5SDimitry Andric { 3320e8d8bef9SDimitry Andric __set_long_cap(__target_capacity+1); 33210b57cec5SDimitry Andric __set_long_size(__sz); 33220b57cec5SDimitry Andric __set_long_pointer(__new_data); 33230b57cec5SDimitry Andric } 33240b57cec5SDimitry Andric else 33250b57cec5SDimitry Andric __set_short_size(__sz); 33260b57cec5SDimitry Andric} 33270b57cec5SDimitry Andric 33280b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3329bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 33300b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::const_reference 33310b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const 33320b57cec5SDimitry Andric{ 33330b57cec5SDimitry Andric if (__n >= size()) 333404eeddc0SDimitry Andric __throw_out_of_range(); 33350b57cec5SDimitry Andric return (*this)[__n]; 33360b57cec5SDimitry Andric} 33370b57cec5SDimitry Andric 33380b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3339bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 33400b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::reference 33410b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::at(size_type __n) 33420b57cec5SDimitry Andric{ 33430b57cec5SDimitry Andric if (__n >= size()) 334404eeddc0SDimitry Andric __throw_out_of_range(); 33450b57cec5SDimitry Andric return (*this)[__n]; 33460b57cec5SDimitry Andric} 33470b57cec5SDimitry Andric 33480b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3349bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 33500b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 33510b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const 33520b57cec5SDimitry Andric{ 33530b57cec5SDimitry Andric size_type __sz = size(); 33540b57cec5SDimitry Andric if (__pos > __sz) 335504eeddc0SDimitry Andric __throw_out_of_range(); 335681ad6265SDimitry Andric size_type __rlen = std::min(__n, __sz - __pos); 33570b57cec5SDimitry Andric traits_type::copy(__s, data() + __pos, __rlen); 33580b57cec5SDimitry Andric return __rlen; 33590b57cec5SDimitry Andric} 33600b57cec5SDimitry Andric 33610b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3362bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 33630b57cec5SDimitry Andricvoid 33640b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) 33650b57cec5SDimitry Andric#if _LIBCPP_STD_VER >= 14 33660b57cec5SDimitry Andric _NOEXCEPT 33670b57cec5SDimitry Andric#else 33680b57cec5SDimitry Andric _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || 33690b57cec5SDimitry Andric __is_nothrow_swappable<allocator_type>::value) 33700b57cec5SDimitry Andric#endif 33710b57cec5SDimitry Andric{ 3372*06c3fb27SDimitry Andric _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR( 33730b57cec5SDimitry Andric __alloc_traits::propagate_on_container_swap::value || 33740b57cec5SDimitry Andric __alloc_traits::is_always_equal::value || 33750b57cec5SDimitry Andric __alloc() == __str.__alloc(), "swapping non-equal allocators"); 337681ad6265SDimitry Andric std::swap(__r_.first(), __str.__r_.first()); 337781ad6265SDimitry Andric std::__swap_allocator(__alloc(), __str.__alloc()); 33780b57cec5SDimitry Andric} 33790b57cec5SDimitry Andric 33800b57cec5SDimitry Andric// find 33810b57cec5SDimitry Andric 33820b57cec5SDimitry Andrictemplate <class _Traits> 33830b57cec5SDimitry Andricstruct _LIBCPP_HIDDEN __traits_eq 33840b57cec5SDimitry Andric{ 33850b57cec5SDimitry Andric typedef typename _Traits::char_type char_type; 338681ad6265SDimitry Andric _LIBCPP_HIDE_FROM_ABI 33870b57cec5SDimitry Andric bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT 33880b57cec5SDimitry Andric {return _Traits::eq(__x, __y);} 33890b57cec5SDimitry Andric}; 33900b57cec5SDimitry Andric 33910b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3392bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 33930b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 33940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, 33950b57cec5SDimitry Andric size_type __pos, 33960b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 33970b57cec5SDimitry Andric{ 3398*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find(): received nullptr"); 3399bdd1243dSDimitry Andric return std::__str_find<value_type, size_type, traits_type, npos> 34000b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 34010b57cec5SDimitry Andric} 34020b57cec5SDimitry Andric 34030b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3404bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 34050b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 34060b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, 34070b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 34080b57cec5SDimitry Andric{ 3409bdd1243dSDimitry Andric return std::__str_find<value_type, size_type, traits_type, npos> 34100b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 34110b57cec5SDimitry Andric} 34120b57cec5SDimitry Andric 34130b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3414*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3415*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type 34160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, 3417fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 34180b57cec5SDimitry Andric{ 34190b57cec5SDimitry Andric __self_view __sv = __t; 3420bdd1243dSDimitry Andric return std::__str_find<value_type, size_type, traits_type, npos> 34210b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 34220b57cec5SDimitry Andric} 34230b57cec5SDimitry Andric 34240b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3425bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 34260b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 34270b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, 34280b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 34290b57cec5SDimitry Andric{ 3430*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find(): received nullptr"); 3431bdd1243dSDimitry Andric return std::__str_find<value_type, size_type, traits_type, npos> 34320b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 34330b57cec5SDimitry Andric} 34340b57cec5SDimitry Andric 34350b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3436bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 34370b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 34380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find(value_type __c, 34390b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 34400b57cec5SDimitry Andric{ 3441bdd1243dSDimitry Andric return std::__str_find<value_type, size_type, traits_type, npos> 34420b57cec5SDimitry Andric (data(), size(), __c, __pos); 34430b57cec5SDimitry Andric} 34440b57cec5SDimitry Andric 34450b57cec5SDimitry Andric// rfind 34460b57cec5SDimitry Andric 34470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3448bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 34490b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 34500b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, 34510b57cec5SDimitry Andric size_type __pos, 34520b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 34530b57cec5SDimitry Andric{ 3454*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); 3455bdd1243dSDimitry Andric return std::__str_rfind<value_type, size_type, traits_type, npos> 34560b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 34570b57cec5SDimitry Andric} 34580b57cec5SDimitry Andric 34590b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3460bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 34610b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 34620b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, 34630b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 34640b57cec5SDimitry Andric{ 3465bdd1243dSDimitry Andric return std::__str_rfind<value_type, size_type, traits_type, npos> 34660b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 34670b57cec5SDimitry Andric} 34680b57cec5SDimitry Andric 34690b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3470*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3471*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type 34720b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, 3473fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 34740b57cec5SDimitry Andric{ 34750b57cec5SDimitry Andric __self_view __sv = __t; 3476bdd1243dSDimitry Andric return std::__str_rfind<value_type, size_type, traits_type, npos> 34770b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 34780b57cec5SDimitry Andric} 34790b57cec5SDimitry Andric 34800b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3481bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 34820b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 34830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, 34840b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 34850b57cec5SDimitry Andric{ 3486*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::rfind(): received nullptr"); 3487bdd1243dSDimitry Andric return std::__str_rfind<value_type, size_type, traits_type, npos> 34880b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 34890b57cec5SDimitry Andric} 34900b57cec5SDimitry Andric 34910b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3492bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 34930b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 34940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, 34950b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 34960b57cec5SDimitry Andric{ 3497bdd1243dSDimitry Andric return std::__str_rfind<value_type, size_type, traits_type, npos> 34980b57cec5SDimitry Andric (data(), size(), __c, __pos); 34990b57cec5SDimitry Andric} 35000b57cec5SDimitry Andric 35010b57cec5SDimitry Andric// find_first_of 35020b57cec5SDimitry Andric 35030b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3504bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 35050b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35060b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, 35070b57cec5SDimitry Andric size_type __pos, 35080b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 35090b57cec5SDimitry Andric{ 3510*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); 3511bdd1243dSDimitry Andric return std::__str_find_first_of<value_type, size_type, traits_type, npos> 35120b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 35130b57cec5SDimitry Andric} 35140b57cec5SDimitry Andric 35150b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3516bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 35170b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35180b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, 35190b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 35200b57cec5SDimitry Andric{ 3521bdd1243dSDimitry Andric return std::__str_find_first_of<value_type, size_type, traits_type, npos> 35220b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 35230b57cec5SDimitry Andric} 35240b57cec5SDimitry Andric 35250b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3526*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3527*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type 35280b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, 3529fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 35300b57cec5SDimitry Andric{ 35310b57cec5SDimitry Andric __self_view __sv = __t; 3532bdd1243dSDimitry Andric return std::__str_find_first_of<value_type, size_type, traits_type, npos> 35330b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 35340b57cec5SDimitry Andric} 35350b57cec5SDimitry Andric 35360b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3537bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 35380b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35390b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, 35400b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 35410b57cec5SDimitry Andric{ 3542*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_first_of(): received nullptr"); 3543bdd1243dSDimitry Andric return std::__str_find_first_of<value_type, size_type, traits_type, npos> 35440b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 35450b57cec5SDimitry Andric} 35460b57cec5SDimitry Andric 35470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3548bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 35490b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35500b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, 35510b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 35520b57cec5SDimitry Andric{ 35530b57cec5SDimitry Andric return find(__c, __pos); 35540b57cec5SDimitry Andric} 35550b57cec5SDimitry Andric 35560b57cec5SDimitry Andric// find_last_of 35570b57cec5SDimitry Andric 35580b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3559bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 35600b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35610b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, 35620b57cec5SDimitry Andric size_type __pos, 35630b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 35640b57cec5SDimitry Andric{ 3565*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); 3566bdd1243dSDimitry Andric return std::__str_find_last_of<value_type, size_type, traits_type, npos> 35670b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 35680b57cec5SDimitry Andric} 35690b57cec5SDimitry Andric 35700b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3571bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 35720b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35730b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, 35740b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 35750b57cec5SDimitry Andric{ 3576bdd1243dSDimitry Andric return std::__str_find_last_of<value_type, size_type, traits_type, npos> 35770b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 35780b57cec5SDimitry Andric} 35790b57cec5SDimitry Andric 35800b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3581*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3582*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type 35830b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, 3584fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 35850b57cec5SDimitry Andric{ 35860b57cec5SDimitry Andric __self_view __sv = __t; 3587bdd1243dSDimitry Andric return std::__str_find_last_of<value_type, size_type, traits_type, npos> 35880b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 35890b57cec5SDimitry Andric} 35900b57cec5SDimitry Andric 35910b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3592bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 35930b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 35940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, 35950b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 35960b57cec5SDimitry Andric{ 3597*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_last_of(): received nullptr"); 3598bdd1243dSDimitry Andric return std::__str_find_last_of<value_type, size_type, traits_type, npos> 35990b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 36000b57cec5SDimitry Andric} 36010b57cec5SDimitry Andric 36020b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3603bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 36040b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36050b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, 36060b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36070b57cec5SDimitry Andric{ 36080b57cec5SDimitry Andric return rfind(__c, __pos); 36090b57cec5SDimitry Andric} 36100b57cec5SDimitry Andric 36110b57cec5SDimitry Andric// find_first_not_of 36120b57cec5SDimitry Andric 36130b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3614bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 36150b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, 36170b57cec5SDimitry Andric size_type __pos, 36180b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 36190b57cec5SDimitry Andric{ 3620*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); 3621bdd1243dSDimitry Andric return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 36220b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 36230b57cec5SDimitry Andric} 36240b57cec5SDimitry Andric 36250b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3626bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 36270b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36280b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, 36290b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36300b57cec5SDimitry Andric{ 3631bdd1243dSDimitry Andric return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 36320b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 36330b57cec5SDimitry Andric} 36340b57cec5SDimitry Andric 36350b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3636*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3637*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type 36380b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, 3639fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 36400b57cec5SDimitry Andric{ 36410b57cec5SDimitry Andric __self_view __sv = __t; 3642bdd1243dSDimitry Andric return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 36430b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 36440b57cec5SDimitry Andric} 36450b57cec5SDimitry Andric 36460b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3647bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 36480b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36490b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, 36500b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36510b57cec5SDimitry Andric{ 3652*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_first_not_of(): received nullptr"); 3653bdd1243dSDimitry Andric return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 36540b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 36550b57cec5SDimitry Andric} 36560b57cec5SDimitry Andric 36570b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3658bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 36590b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36600b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, 36610b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36620b57cec5SDimitry Andric{ 3663bdd1243dSDimitry Andric return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 36640b57cec5SDimitry Andric (data(), size(), __c, __pos); 36650b57cec5SDimitry Andric} 36660b57cec5SDimitry Andric 36670b57cec5SDimitry Andric// find_last_not_of 36680b57cec5SDimitry Andric 36690b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3670bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 36710b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36720b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, 36730b57cec5SDimitry Andric size_type __pos, 36740b57cec5SDimitry Andric size_type __n) const _NOEXCEPT 36750b57cec5SDimitry Andric{ 3676*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); 3677bdd1243dSDimitry Andric return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 36780b57cec5SDimitry Andric (data(), size(), __s, __pos, __n); 36790b57cec5SDimitry Andric} 36800b57cec5SDimitry Andric 36810b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3682bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 36830b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 36840b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, 36850b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 36860b57cec5SDimitry Andric{ 3687bdd1243dSDimitry Andric return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 36880b57cec5SDimitry Andric (data(), size(), __str.data(), __pos, __str.size()); 36890b57cec5SDimitry Andric} 36900b57cec5SDimitry Andric 36910b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3692*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3693*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 typename basic_string<_CharT, _Traits, _Allocator>::size_type 36940b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, 3695fe6060f1SDimitry Andric size_type __pos) const _NOEXCEPT 36960b57cec5SDimitry Andric{ 36970b57cec5SDimitry Andric __self_view __sv = __t; 3698bdd1243dSDimitry Andric return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 36990b57cec5SDimitry Andric (data(), size(), __sv.data(), __pos, __sv.size()); 37000b57cec5SDimitry Andric} 37010b57cec5SDimitry Andric 37020b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3703bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 37040b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37050b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, 37060b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 37070b57cec5SDimitry Andric{ 3708*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::find_last_not_of(): received nullptr"); 3709bdd1243dSDimitry Andric return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 37100b57cec5SDimitry Andric (data(), size(), __s, __pos, traits_type::length(__s)); 37110b57cec5SDimitry Andric} 37120b57cec5SDimitry Andric 37130b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3714bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 37150b57cec5SDimitry Andrictypename basic_string<_CharT, _Traits, _Allocator>::size_type 37160b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, 37170b57cec5SDimitry Andric size_type __pos) const _NOEXCEPT 37180b57cec5SDimitry Andric{ 3719bdd1243dSDimitry Andric return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 37200b57cec5SDimitry Andric (data(), size(), __c, __pos); 37210b57cec5SDimitry Andric} 37220b57cec5SDimitry Andric 37230b57cec5SDimitry Andric// compare 37240b57cec5SDimitry Andric 37250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3726*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3727*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 int 3728fe6060f1SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT 37290b57cec5SDimitry Andric{ 37300b57cec5SDimitry Andric __self_view __sv = __t; 37310b57cec5SDimitry Andric size_t __lhs_sz = size(); 37320b57cec5SDimitry Andric size_t __rhs_sz = __sv.size(); 37330b57cec5SDimitry Andric int __result = traits_type::compare(data(), __sv.data(), 373481ad6265SDimitry Andric std::min(__lhs_sz, __rhs_sz)); 37350b57cec5SDimitry Andric if (__result != 0) 37360b57cec5SDimitry Andric return __result; 37370b57cec5SDimitry Andric if (__lhs_sz < __rhs_sz) 37380b57cec5SDimitry Andric return -1; 37390b57cec5SDimitry Andric if (__lhs_sz > __rhs_sz) 37400b57cec5SDimitry Andric return 1; 37410b57cec5SDimitry Andric return 0; 37420b57cec5SDimitry Andric} 37430b57cec5SDimitry Andric 37440b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3745bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 37460b57cec5SDimitry Andricint 37470b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT 37480b57cec5SDimitry Andric{ 37490b57cec5SDimitry Andric return compare(__self_view(__str)); 37500b57cec5SDimitry Andric} 37510b57cec5SDimitry Andric 37520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3753bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 37540b57cec5SDimitry Andricint 37550b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 37560b57cec5SDimitry Andric size_type __n1, 37570b57cec5SDimitry Andric const value_type* __s, 37580b57cec5SDimitry Andric size_type __n2) const 37590b57cec5SDimitry Andric{ 3760*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); 37610b57cec5SDimitry Andric size_type __sz = size(); 37620b57cec5SDimitry Andric if (__pos1 > __sz || __n2 == npos) 376304eeddc0SDimitry Andric __throw_out_of_range(); 376481ad6265SDimitry Andric size_type __rlen = std::min(__n1, __sz - __pos1); 376581ad6265SDimitry Andric int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2)); 37660b57cec5SDimitry Andric if (__r == 0) 37670b57cec5SDimitry Andric { 37680b57cec5SDimitry Andric if (__rlen < __n2) 37690b57cec5SDimitry Andric __r = -1; 37700b57cec5SDimitry Andric else if (__rlen > __n2) 37710b57cec5SDimitry Andric __r = 1; 37720b57cec5SDimitry Andric } 37730b57cec5SDimitry Andric return __r; 37740b57cec5SDimitry Andric} 37750b57cec5SDimitry Andric 37760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3777*06c3fb27SDimitry Andrictemplate <class _Tp, __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, int> > 3778*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 int 37790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 37800b57cec5SDimitry Andric size_type __n1, 37810b57cec5SDimitry Andric const _Tp& __t) const 37820b57cec5SDimitry Andric{ 37830b57cec5SDimitry Andric __self_view __sv = __t; 37840b57cec5SDimitry Andric return compare(__pos1, __n1, __sv.data(), __sv.size()); 37850b57cec5SDimitry Andric} 37860b57cec5SDimitry Andric 37870b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3788bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 37890b57cec5SDimitry Andricint 37900b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 37910b57cec5SDimitry Andric size_type __n1, 37920b57cec5SDimitry Andric const basic_string& __str) const 37930b57cec5SDimitry Andric{ 37940b57cec5SDimitry Andric return compare(__pos1, __n1, __str.data(), __str.size()); 37950b57cec5SDimitry Andric} 37960b57cec5SDimitry Andric 37970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3798*06c3fb27SDimitry Andrictemplate <class _Tp, 3799*06c3fb27SDimitry Andric __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && 3800*06c3fb27SDimitry Andric !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, 3801*06c3fb27SDimitry Andric int> > 3802*06c3fb27SDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 int basic_string<_CharT, _Traits, _Allocator>::compare( 3803*06c3fb27SDimitry Andric size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2) const { 38040b57cec5SDimitry Andric __self_view __sv = __t; 38050b57cec5SDimitry Andric return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); 38060b57cec5SDimitry Andric} 38070b57cec5SDimitry Andric 38080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3809bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 38100b57cec5SDimitry Andricint 38110b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 38120b57cec5SDimitry Andric size_type __n1, 38130b57cec5SDimitry Andric const basic_string& __str, 38140b57cec5SDimitry Andric size_type __pos2, 38150b57cec5SDimitry Andric size_type __n2) const 38160b57cec5SDimitry Andric{ 38170b57cec5SDimitry Andric return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); 38180b57cec5SDimitry Andric} 38190b57cec5SDimitry Andric 38200b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3821bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 38220b57cec5SDimitry Andricint 38230b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT 38240b57cec5SDimitry Andric{ 3825*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::compare(): received nullptr"); 38260b57cec5SDimitry Andric return compare(0, npos, __s, traits_type::length(__s)); 38270b57cec5SDimitry Andric} 38280b57cec5SDimitry Andric 38290b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3830bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX20 38310b57cec5SDimitry Andricint 38320b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, 38330b57cec5SDimitry Andric size_type __n1, 38340b57cec5SDimitry Andric const value_type* __s) const 38350b57cec5SDimitry Andric{ 3836*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string::compare(): received nullptr"); 38370b57cec5SDimitry Andric return compare(__pos1, __n1, __s, traits_type::length(__s)); 38380b57cec5SDimitry Andric} 38390b57cec5SDimitry Andric 38400b57cec5SDimitry Andric// __invariants 38410b57cec5SDimitry Andric 38420b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3843bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 38440b57cec5SDimitry Andricbool 38450b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__invariants() const 38460b57cec5SDimitry Andric{ 38470b57cec5SDimitry Andric if (size() > capacity()) 38480b57cec5SDimitry Andric return false; 38490b57cec5SDimitry Andric if (capacity() < __min_cap - 1) 38500b57cec5SDimitry Andric return false; 3851e8d8bef9SDimitry Andric if (data() == nullptr) 38520b57cec5SDimitry Andric return false; 3853*06c3fb27SDimitry Andric if (!_Traits::eq(data()[size()], value_type())) 38540b57cec5SDimitry Andric return false; 38550b57cec5SDimitry Andric return true; 38560b57cec5SDimitry Andric} 38570b57cec5SDimitry Andric 38580b57cec5SDimitry Andric// __clear_and_shrink 38590b57cec5SDimitry Andric 38600b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3861bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 38620b57cec5SDimitry Andricvoid 38630b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT 38640b57cec5SDimitry Andric{ 38650b57cec5SDimitry Andric clear(); 38660b57cec5SDimitry Andric if(__is_long()) 38670b57cec5SDimitry Andric { 38680b57cec5SDimitry Andric __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); 3869bdd1243dSDimitry Andric __default_init(); 38700b57cec5SDimitry Andric } 38710b57cec5SDimitry Andric} 38720b57cec5SDimitry Andric 38730b57cec5SDimitry Andric// operator== 38740b57cec5SDimitry Andric 38750b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3876bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 38770b57cec5SDimitry Andricbool 38780b57cec5SDimitry Andricoperator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 38790b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 38800b57cec5SDimitry Andric{ 3881*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 3882bdd1243dSDimitry Andric return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); 3883bdd1243dSDimitry Andric#else 38840b57cec5SDimitry Andric size_t __lhs_sz = __lhs.size(); 38850b57cec5SDimitry Andric return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), 38860b57cec5SDimitry Andric __rhs.data(), 38870b57cec5SDimitry Andric __lhs_sz) == 0; 3888bdd1243dSDimitry Andric#endif 38890b57cec5SDimitry Andric} 38900b57cec5SDimitry Andric 38910b57cec5SDimitry Andrictemplate<class _Allocator> 3892bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 38930b57cec5SDimitry Andricbool 38940b57cec5SDimitry Andricoperator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, 38950b57cec5SDimitry Andric const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT 38960b57cec5SDimitry Andric{ 38970b57cec5SDimitry Andric size_t __lhs_sz = __lhs.size(); 38980b57cec5SDimitry Andric if (__lhs_sz != __rhs.size()) 38990b57cec5SDimitry Andric return false; 39000b57cec5SDimitry Andric const char* __lp = __lhs.data(); 39010b57cec5SDimitry Andric const char* __rp = __rhs.data(); 39020b57cec5SDimitry Andric if (__lhs.__is_long()) 39030b57cec5SDimitry Andric return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; 39040b57cec5SDimitry Andric for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) 39050b57cec5SDimitry Andric if (*__lp != *__rp) 39060b57cec5SDimitry Andric return false; 39070b57cec5SDimitry Andric return true; 39080b57cec5SDimitry Andric} 39090b57cec5SDimitry Andric 3910bdd1243dSDimitry Andric#if _LIBCPP_STD_VER <= 17 39110b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3912bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 39130b57cec5SDimitry Andricbool 39140b57cec5SDimitry Andricoperator==(const _CharT* __lhs, 39150b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 39160b57cec5SDimitry Andric{ 39170b57cec5SDimitry Andric typedef basic_string<_CharT, _Traits, _Allocator> _String; 3918*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); 39190b57cec5SDimitry Andric size_t __lhs_len = _Traits::length(__lhs); 39200b57cec5SDimitry Andric if (__lhs_len != __rhs.size()) return false; 39210b57cec5SDimitry Andric return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; 39220b57cec5SDimitry Andric} 3923bdd1243dSDimitry Andric#endif // _LIBCPP_STD_VER <= 17 39240b57cec5SDimitry Andric 39250b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3926bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI 39270b57cec5SDimitry Andricbool 39280b57cec5SDimitry Andricoperator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 39290b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 39300b57cec5SDimitry Andric{ 3931*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 3932bdd1243dSDimitry Andric return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); 3933bdd1243dSDimitry Andric#else 39340b57cec5SDimitry Andric typedef basic_string<_CharT, _Traits, _Allocator> _String; 3935*06c3fb27SDimitry Andric _LIBCPP_ASSERT_UNCATEGORIZED(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); 39360b57cec5SDimitry Andric size_t __rhs_len = _Traits::length(__rhs); 39370b57cec5SDimitry Andric if (__rhs_len != __lhs.size()) return false; 39380b57cec5SDimitry Andric return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; 3939bdd1243dSDimitry Andric#endif 3940bdd1243dSDimitry Andric} 3941bdd1243dSDimitry Andric 3942*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 3943bdd1243dSDimitry Andric 3944bdd1243dSDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3945bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>( 3946bdd1243dSDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __lhs, 3947bdd1243dSDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) noexcept { 3948bdd1243dSDimitry Andric return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); 39490b57cec5SDimitry Andric} 39500b57cec5SDimitry Andric 39510b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator> 3952bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr auto 3953bdd1243dSDimitry Andricoperator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) { 3954bdd1243dSDimitry Andric return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); 3955bdd1243dSDimitry Andric} 3956bdd1243dSDimitry Andric 3957*06c3fb27SDimitry Andric#else // _LIBCPP_STD_VER >= 20 3958bdd1243dSDimitry Andric 3959bdd1243dSDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3960bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 39610b57cec5SDimitry Andricbool 39620b57cec5SDimitry Andricoperator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, 39630b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 39640b57cec5SDimitry Andric{ 39650b57cec5SDimitry Andric return !(__lhs == __rhs); 39660b57cec5SDimitry Andric} 39670b57cec5SDimitry Andric 39680b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3969bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 39700b57cec5SDimitry Andricbool 39710b57cec5SDimitry Andricoperator!=(const _CharT* __lhs, 39720b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 39730b57cec5SDimitry Andric{ 39740b57cec5SDimitry Andric return !(__lhs == __rhs); 39750b57cec5SDimitry Andric} 39760b57cec5SDimitry Andric 39770b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3978bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 39790b57cec5SDimitry Andricbool 39800b57cec5SDimitry Andricoperator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 39810b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 39820b57cec5SDimitry Andric{ 39830b57cec5SDimitry Andric return !(__lhs == __rhs); 39840b57cec5SDimitry Andric} 39850b57cec5SDimitry Andric 39860b57cec5SDimitry Andric// operator< 39870b57cec5SDimitry Andric 39880b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3989bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 39900b57cec5SDimitry Andricbool 39910b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 39920b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 39930b57cec5SDimitry Andric{ 39940b57cec5SDimitry Andric return __lhs.compare(__rhs) < 0; 39950b57cec5SDimitry Andric} 39960b57cec5SDimitry Andric 39970b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 3998bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 39990b57cec5SDimitry Andricbool 40000b57cec5SDimitry Andricoperator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 40010b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 40020b57cec5SDimitry Andric{ 40030b57cec5SDimitry Andric return __lhs.compare(__rhs) < 0; 40040b57cec5SDimitry Andric} 40050b57cec5SDimitry Andric 40060b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4007bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40080b57cec5SDimitry Andricbool 40090b57cec5SDimitry Andricoperator< (const _CharT* __lhs, 40100b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 40110b57cec5SDimitry Andric{ 40120b57cec5SDimitry Andric return __rhs.compare(__lhs) > 0; 40130b57cec5SDimitry Andric} 40140b57cec5SDimitry Andric 40150b57cec5SDimitry Andric// operator> 40160b57cec5SDimitry Andric 40170b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4018bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40190b57cec5SDimitry Andricbool 40200b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 40210b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 40220b57cec5SDimitry Andric{ 40230b57cec5SDimitry Andric return __rhs < __lhs; 40240b57cec5SDimitry Andric} 40250b57cec5SDimitry Andric 40260b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4027bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40280b57cec5SDimitry Andricbool 40290b57cec5SDimitry Andricoperator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, 40300b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 40310b57cec5SDimitry Andric{ 40320b57cec5SDimitry Andric return __rhs < __lhs; 40330b57cec5SDimitry Andric} 40340b57cec5SDimitry Andric 40350b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4036bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40370b57cec5SDimitry Andricbool 40380b57cec5SDimitry Andricoperator> (const _CharT* __lhs, 40390b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 40400b57cec5SDimitry Andric{ 40410b57cec5SDimitry Andric return __rhs < __lhs; 40420b57cec5SDimitry Andric} 40430b57cec5SDimitry Andric 40440b57cec5SDimitry Andric// operator<= 40450b57cec5SDimitry Andric 40460b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4047bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40480b57cec5SDimitry Andricbool 40490b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 40500b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 40510b57cec5SDimitry Andric{ 40520b57cec5SDimitry Andric return !(__rhs < __lhs); 40530b57cec5SDimitry Andric} 40540b57cec5SDimitry Andric 40550b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4056bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40570b57cec5SDimitry Andricbool 40580b57cec5SDimitry Andricoperator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 40590b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 40600b57cec5SDimitry Andric{ 40610b57cec5SDimitry Andric return !(__rhs < __lhs); 40620b57cec5SDimitry Andric} 40630b57cec5SDimitry Andric 40640b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4065bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40660b57cec5SDimitry Andricbool 40670b57cec5SDimitry Andricoperator<=(const _CharT* __lhs, 40680b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 40690b57cec5SDimitry Andric{ 40700b57cec5SDimitry Andric return !(__rhs < __lhs); 40710b57cec5SDimitry Andric} 40720b57cec5SDimitry Andric 40730b57cec5SDimitry Andric// operator>= 40740b57cec5SDimitry Andric 40750b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4076bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40770b57cec5SDimitry Andricbool 40780b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 40790b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 40800b57cec5SDimitry Andric{ 40810b57cec5SDimitry Andric return !(__lhs < __rhs); 40820b57cec5SDimitry Andric} 40830b57cec5SDimitry Andric 40840b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4085bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40860b57cec5SDimitry Andricbool 40870b57cec5SDimitry Andricoperator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 40880b57cec5SDimitry Andric const _CharT* __rhs) _NOEXCEPT 40890b57cec5SDimitry Andric{ 40900b57cec5SDimitry Andric return !(__lhs < __rhs); 40910b57cec5SDimitry Andric} 40920b57cec5SDimitry Andric 40930b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4094bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 40950b57cec5SDimitry Andricbool 40960b57cec5SDimitry Andricoperator>=(const _CharT* __lhs, 40970b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT 40980b57cec5SDimitry Andric{ 40990b57cec5SDimitry Andric return !(__lhs < __rhs); 41000b57cec5SDimitry Andric} 4101*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20 41020b57cec5SDimitry Andric 41030b57cec5SDimitry Andric// operator + 41040b57cec5SDimitry Andric 41050b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4106bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 41070b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 41080b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, 41090b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __rhs) 41100b57cec5SDimitry Andric{ 411181ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 411281ad6265SDimitry Andric auto __lhs_sz = __lhs.size(); 411381ad6265SDimitry Andric auto __rhs_sz = __rhs.size(); 411481ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 411581ad6265SDimitry Andric __lhs_sz + __rhs_sz, 411681ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); 411781ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 411881ad6265SDimitry Andric _Traits::copy(__ptr, __lhs.data(), __lhs_sz); 411981ad6265SDimitry Andric _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); 412081ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); 41210b57cec5SDimitry Andric return __r; 41220b57cec5SDimitry Andric} 41230b57cec5SDimitry Andric 41240b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4125bdd1243dSDimitry Andric_LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 41260b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 41270b57cec5SDimitry Andricoperator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) 41280b57cec5SDimitry Andric{ 412981ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 413081ad6265SDimitry Andric auto __lhs_sz = _Traits::length(__lhs); 413181ad6265SDimitry Andric auto __rhs_sz = __rhs.size(); 413281ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 413381ad6265SDimitry Andric __lhs_sz + __rhs_sz, 413481ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); 413581ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 413681ad6265SDimitry Andric _Traits::copy(__ptr, __lhs, __lhs_sz); 413781ad6265SDimitry Andric _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); 413881ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); 41390b57cec5SDimitry Andric return __r; 41400b57cec5SDimitry Andric} 41410b57cec5SDimitry Andric 41420b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4143bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 41440b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 41450b57cec5SDimitry Andricoperator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) 41460b57cec5SDimitry Andric{ 414781ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 414881ad6265SDimitry Andric typename _String::size_type __rhs_sz = __rhs.size(); 414981ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 415081ad6265SDimitry Andric __rhs_sz + 1, 415181ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); 415281ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 415381ad6265SDimitry Andric _Traits::assign(__ptr, 1, __lhs); 415481ad6265SDimitry Andric _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz); 415581ad6265SDimitry Andric _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT()); 41560b57cec5SDimitry Andric return __r; 41570b57cec5SDimitry Andric} 41580b57cec5SDimitry Andric 41590b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4160bdd1243dSDimitry Andricinline _LIBCPP_CONSTEXPR_SINCE_CXX20 41610b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 41620b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) 41630b57cec5SDimitry Andric{ 416481ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 416581ad6265SDimitry Andric typename _String::size_type __lhs_sz = __lhs.size(); 416681ad6265SDimitry Andric typename _String::size_type __rhs_sz = _Traits::length(__rhs); 416781ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 416881ad6265SDimitry Andric __lhs_sz + __rhs_sz, 416981ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); 417081ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 417181ad6265SDimitry Andric _Traits::copy(__ptr, __lhs.data(), __lhs_sz); 417281ad6265SDimitry Andric _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz); 417381ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); 41740b57cec5SDimitry Andric return __r; 41750b57cec5SDimitry Andric} 41760b57cec5SDimitry Andric 41770b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4178bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 41790b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 41800b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) 41810b57cec5SDimitry Andric{ 418281ad6265SDimitry Andric using _String = basic_string<_CharT, _Traits, _Allocator>; 418381ad6265SDimitry Andric typename _String::size_type __lhs_sz = __lhs.size(); 418481ad6265SDimitry Andric _String __r(__uninitialized_size_tag(), 418581ad6265SDimitry Andric __lhs_sz + 1, 418681ad6265SDimitry Andric _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); 418781ad6265SDimitry Andric auto __ptr = std::__to_address(__r.__get_pointer()); 418881ad6265SDimitry Andric _Traits::copy(__ptr, __lhs.data(), __lhs_sz); 418981ad6265SDimitry Andric _Traits::assign(__ptr + __lhs_sz, 1, __rhs); 419081ad6265SDimitry Andric _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT()); 41910b57cec5SDimitry Andric return __r; 41920b57cec5SDimitry Andric} 41930b57cec5SDimitry Andric 41940b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG 41950b57cec5SDimitry Andric 41960b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4197bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 41980b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 41990b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) 42000b57cec5SDimitry Andric{ 420181ad6265SDimitry Andric return std::move(__lhs.append(__rhs)); 42020b57cec5SDimitry Andric} 42030b57cec5SDimitry Andric 42040b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4205bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 42060b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 42070b57cec5SDimitry Andricoperator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) 42080b57cec5SDimitry Andric{ 420981ad6265SDimitry Andric return std::move(__rhs.insert(0, __lhs)); 42100b57cec5SDimitry Andric} 42110b57cec5SDimitry Andric 42120b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4213bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 42140b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 42150b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) 42160b57cec5SDimitry Andric{ 421781ad6265SDimitry Andric return std::move(__lhs.append(__rhs)); 42180b57cec5SDimitry Andric} 42190b57cec5SDimitry Andric 42200b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4221bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 42220b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 42230b57cec5SDimitry Andricoperator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) 42240b57cec5SDimitry Andric{ 422581ad6265SDimitry Andric return std::move(__rhs.insert(0, __lhs)); 42260b57cec5SDimitry Andric} 42270b57cec5SDimitry Andric 42280b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4229bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 42300b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 42310b57cec5SDimitry Andricoperator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) 42320b57cec5SDimitry Andric{ 42330b57cec5SDimitry Andric __rhs.insert(__rhs.begin(), __lhs); 423481ad6265SDimitry Andric return std::move(__rhs); 42350b57cec5SDimitry Andric} 42360b57cec5SDimitry Andric 42370b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4238bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 42390b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 42400b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) 42410b57cec5SDimitry Andric{ 424281ad6265SDimitry Andric return std::move(__lhs.append(__rhs)); 42430b57cec5SDimitry Andric} 42440b57cec5SDimitry Andric 42450b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4246bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 42470b57cec5SDimitry Andricbasic_string<_CharT, _Traits, _Allocator> 42480b57cec5SDimitry Andricoperator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) 42490b57cec5SDimitry Andric{ 42500b57cec5SDimitry Andric __lhs.push_back(__rhs); 425181ad6265SDimitry Andric return std::move(__lhs); 42520b57cec5SDimitry Andric} 42530b57cec5SDimitry Andric 42540b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG 42550b57cec5SDimitry Andric 42560b57cec5SDimitry Andric// swap 42570b57cec5SDimitry Andric 42580b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4259bdd1243dSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 42600b57cec5SDimitry Andricvoid 42610b57cec5SDimitry Andricswap(basic_string<_CharT, _Traits, _Allocator>& __lhs, 42620b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __rhs) 42630b57cec5SDimitry Andric _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) 42640b57cec5SDimitry Andric{ 42650b57cec5SDimitry Andric __lhs.swap(__rhs); 42660b57cec5SDimitry Andric} 42670b57cec5SDimitry Andric 4268*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); 4269*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); 4270*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); 4271*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); 4272*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10); 42730b57cec5SDimitry Andric 4274*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI float stof (const string& __str, size_t* __idx = nullptr); 4275*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI double stod (const string& __str, size_t* __idx = nullptr); 4276*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI long double stold(const string& __str, size_t* __idx = nullptr); 42770b57cec5SDimitry Andric 4278*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(int __val); 4279*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(unsigned __val); 4280*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(long __val); 4281*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(unsigned long __val); 4282*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(long long __val); 4283*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(unsigned long long __val); 4284*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(float __val); 4285*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(double __val); 4286*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string to_string(long double __val); 42870b57cec5SDimitry Andric 4288349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 4289*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4290*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4291*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4292*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); 4293*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10); 42940b57cec5SDimitry Andric 4295*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI float stof (const wstring& __str, size_t* __idx = nullptr); 4296*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI double stod (const wstring& __str, size_t* __idx = nullptr); 4297*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI long double stold(const wstring& __str, size_t* __idx = nullptr); 42980b57cec5SDimitry Andric 4299*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(int __val); 4300*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(unsigned __val); 4301*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(long __val); 4302*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(unsigned long __val); 4303*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(long long __val); 4304*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(unsigned long long __val); 4305*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(float __val); 4306*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(double __val); 4307*06c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI wstring to_wstring(long double __val); 4308349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS 43090b57cec5SDimitry Andric 43100b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4311fe6060f1SDimitry Andric_LIBCPP_TEMPLATE_DATA_VIS 43120b57cec5SDimitry Andricconst typename basic_string<_CharT, _Traits, _Allocator>::size_type 43130b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>::npos; 43140b57cec5SDimitry Andric 43150b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator> 4316*06c3fb27SDimitry Andricstruct __string_hash : public __unary_function<basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t> { 4317*06c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI size_t 4318*06c3fb27SDimitry Andric operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT { 4319*06c3fb27SDimitry Andric return std::__do_string_hash(__val.data(), __val.data() + __val.size()); 4320*06c3fb27SDimitry Andric } 43210b57cec5SDimitry Andric}; 43220b57cec5SDimitry Andric 4323bdd1243dSDimitry Andrictemplate <class _Allocator> 4324bdd1243dSDimitry Andricstruct hash<basic_string<char, char_traits<char>, _Allocator> > : __string_hash<char, _Allocator> {}; 4325bdd1243dSDimitry Andric 4326bdd1243dSDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 4327bdd1243dSDimitry Andrictemplate <class _Allocator> 4328bdd1243dSDimitry Andricstruct hash<basic_string<char8_t, char_traits<char8_t>, _Allocator> > : __string_hash<char8_t, _Allocator> {}; 4329bdd1243dSDimitry Andric#endif 4330bdd1243dSDimitry Andric 4331bdd1243dSDimitry Andrictemplate <class _Allocator> 4332bdd1243dSDimitry Andricstruct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __string_hash<char16_t, _Allocator> {}; 4333bdd1243dSDimitry Andric 4334bdd1243dSDimitry Andrictemplate <class _Allocator> 4335bdd1243dSDimitry Andricstruct hash<basic_string<char32_t, char_traits<char32_t>, _Allocator> > : __string_hash<char32_t, _Allocator> {}; 4336bdd1243dSDimitry Andric 4337bdd1243dSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 4338bdd1243dSDimitry Andrictemplate <class _Allocator> 4339bdd1243dSDimitry Andricstruct hash<basic_string<wchar_t, char_traits<wchar_t>, _Allocator> > : __string_hash<wchar_t, _Allocator> {}; 4340bdd1243dSDimitry Andric#endif 4341bdd1243dSDimitry Andric 43420b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4343bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& 43440b57cec5SDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, 43450b57cec5SDimitry Andric const basic_string<_CharT, _Traits, _Allocator>& __str); 43460b57cec5SDimitry Andric 43470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4348bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 43490b57cec5SDimitry Andricoperator>>(basic_istream<_CharT, _Traits>& __is, 43500b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str); 43510b57cec5SDimitry Andric 43520b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 4353bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& 43540b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is, 43550b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); 43560b57cec5SDimitry Andric 43570b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 435881ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 43590b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 43600b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>& __is, 43610b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str); 43620b57cec5SDimitry Andric 43630b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 436481ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 43650b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 43660b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is, 43670b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); 43680b57cec5SDimitry Andric 43690b57cec5SDimitry Andrictemplate<class _CharT, class _Traits, class _Allocator> 437081ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 43710b57cec5SDimitry Andricbasic_istream<_CharT, _Traits>& 43720b57cec5SDimitry Andricgetline(basic_istream<_CharT, _Traits>&& __is, 43730b57cec5SDimitry Andric basic_string<_CharT, _Traits, _Allocator>& __str); 43740b57cec5SDimitry Andric 4375*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 43760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Up> 437781ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 43785ffd83dbSDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 43795ffd83dbSDimitry Andric erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) { 43805ffd83dbSDimitry Andric auto __old_size = __str.size(); 438181ad6265SDimitry Andric __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end()); 43825ffd83dbSDimitry Andric return __old_size - __str.size(); 43835ffd83dbSDimitry Andric} 43840b57cec5SDimitry Andric 43850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits, class _Allocator, class _Predicate> 438681ad6265SDimitry Andricinline _LIBCPP_HIDE_FROM_ABI 43875ffd83dbSDimitry Andric typename basic_string<_CharT, _Traits, _Allocator>::size_type 43885ffd83dbSDimitry Andric erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, 43895ffd83dbSDimitry Andric _Predicate __pred) { 43905ffd83dbSDimitry Andric auto __old_size = __str.size(); 439181ad6265SDimitry Andric __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), 43925ffd83dbSDimitry Andric __str.end()); 43935ffd83dbSDimitry Andric return __old_size - __str.size(); 43945ffd83dbSDimitry Andric} 43950b57cec5SDimitry Andric#endif 43960b57cec5SDimitry Andric 4397*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14 43980b57cec5SDimitry Andric// Literal suffixes for basic_string [basic.string.literals] 43990b57cec5SDimitry Andricinline namespace literals 44000b57cec5SDimitry Andric{ 44010b57cec5SDimitry Andric inline namespace string_literals 44020b57cec5SDimitry Andric { 4403bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 44040b57cec5SDimitry Andric basic_string<char> operator""s( const char *__str, size_t __len ) 44050b57cec5SDimitry Andric { 44060b57cec5SDimitry Andric return basic_string<char> (__str, __len); 44070b57cec5SDimitry Andric } 44080b57cec5SDimitry Andric 4409349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 4410bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 44110b57cec5SDimitry Andric basic_string<wchar_t> operator""s( const wchar_t *__str, size_t __len ) 44120b57cec5SDimitry Andric { 44130b57cec5SDimitry Andric return basic_string<wchar_t> (__str, __len); 44140b57cec5SDimitry Andric } 4415349cc55cSDimitry Andric#endif 44160b57cec5SDimitry Andric 4417fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T 441881ad6265SDimitry Andric inline _LIBCPP_HIDE_FROM_ABI constexpr 4419bdd1243dSDimitry Andric basic_string<char8_t> operator""s(const char8_t *__str, size_t __len) 44200b57cec5SDimitry Andric { 44210b57cec5SDimitry Andric return basic_string<char8_t> (__str, __len); 44220b57cec5SDimitry Andric } 44230b57cec5SDimitry Andric#endif 44240b57cec5SDimitry Andric 4425bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 44260b57cec5SDimitry Andric basic_string<char16_t> operator""s( const char16_t *__str, size_t __len ) 44270b57cec5SDimitry Andric { 44280b57cec5SDimitry Andric return basic_string<char16_t> (__str, __len); 44290b57cec5SDimitry Andric } 44300b57cec5SDimitry Andric 4431bdd1243dSDimitry Andric inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 44320b57cec5SDimitry Andric basic_string<char32_t> operator""s( const char32_t *__str, size_t __len ) 44330b57cec5SDimitry Andric { 44340b57cec5SDimitry Andric return basic_string<char32_t> (__str, __len); 44350b57cec5SDimitry Andric } 44360eae32dcSDimitry Andric } // namespace string_literals 44370eae32dcSDimitry Andric} // namespace literals 443881ad6265SDimitry Andric 4439*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20 444081ad6265SDimitry Andrictemplate <> 444181ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true; 444281ad6265SDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 444381ad6265SDimitry Andrictemplate <> 444481ad6265SDimitry Andricinline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true; 444581ad6265SDimitry Andric#endif 444681ad6265SDimitry Andric#endif 444781ad6265SDimitry Andric 44480b57cec5SDimitry Andric#endif 44490b57cec5SDimitry Andric 44500b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 44510b57cec5SDimitry Andric 44520b57cec5SDimitry Andric_LIBCPP_POP_MACROS 44530b57cec5SDimitry Andric 4454bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 4455bdd1243dSDimitry Andric# include <algorithm> 4456bdd1243dSDimitry Andric# include <concepts> 4457*06c3fb27SDimitry Andric# include <cstdlib> 4458bdd1243dSDimitry Andric# include <iterator> 4459bdd1243dSDimitry Andric# include <new> 4460*06c3fb27SDimitry Andric# include <type_traits> 4461bdd1243dSDimitry Andric# include <typeinfo> 4462bdd1243dSDimitry Andric# include <utility> 4463bdd1243dSDimitry Andric#endif 4464bdd1243dSDimitry Andric 44650b57cec5SDimitry Andric#endif // _LIBCPP_STRING 4466