Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | 7642bb1 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_STRING |
| 11 | #define _LIBCPP_STRING |
| 12 | |
| 13 | /* |
| 14 | string synopsis |
| 15 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 16 | #include <compare> |
| 17 | #include <initializer_list> |
| 18 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | namespace std |
| 20 | { |
| 21 | |
| 22 | template <class stateT> |
| 23 | class fpos |
| 24 | { |
| 25 | private: |
| 26 | stateT st; |
| 27 | public: |
| 28 | fpos(streamoff = streamoff()); |
| 29 | |
| 30 | operator streamoff() const; |
| 31 | |
| 32 | stateT state() const; |
| 33 | void state(stateT); |
| 34 | |
| 35 | fpos& operator+=(streamoff); |
| 36 | fpos operator+ (streamoff) const; |
| 37 | fpos& operator-=(streamoff); |
| 38 | fpos operator- (streamoff) const; |
| 39 | }; |
| 40 | |
| 41 | template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); |
| 42 | |
| 43 | template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); |
| 44 | template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); |
| 45 | |
| 46 | template <class charT> |
| 47 | struct char_traits |
| 48 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 49 | using char_type = charT; |
| 50 | using int_type = ...; |
| 51 | using off_type = streamoff; |
| 52 | using pos_type = streampos; |
| 53 | using state_type = mbstate_t; |
| 54 | using comparison_category = strong_ordering; // Since C++20 only for the specializations |
| 55 | // char, wchar_t, char8_t, char16_t, and char32_t. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 57 | static void assign(char_type& c1, const char_type& c2) noexcept; |
Howard Hinnant | 270c00e | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 58 | static constexpr bool eq(char_type c1, char_type c2) noexcept; |
| 59 | static constexpr bool lt(char_type c1, char_type c2) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | |
| 61 | static int compare(const char_type* s1, const char_type* s2, size_t n); |
| 62 | static size_t length(const char_type* s); |
| 63 | static const char_type* find(const char_type* s, size_t n, const char_type& a); |
| 64 | static char_type* move(char_type* s1, const char_type* s2, size_t n); |
| 65 | static char_type* copy(char_type* s1, const char_type* s2, size_t n); |
| 66 | static char_type* assign(char_type* s, size_t n, char_type a); |
| 67 | |
Howard Hinnant | 270c00e | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 68 | static constexpr int_type not_eof(int_type c) noexcept; |
| 69 | static constexpr char_type to_char_type(int_type c) noexcept; |
| 70 | static constexpr int_type to_int_type(char_type c) noexcept; |
| 71 | static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; |
| 72 | static constexpr int_type eof() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | template <> struct char_traits<char>; |
| 76 | template <> struct char_traits<wchar_t>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 77 | template <> struct char_traits<char8_t>; // C++20 |
| 78 | template <> struct char_traits<char16_t>; |
| 79 | template <> struct char_traits<char32_t>; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 81 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | class basic_string |
| 83 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 84 | public: |
| 85 | // types: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | typedef traits traits_type; |
| 87 | typedef typename traits_type::char_type value_type; |
| 88 | typedef Allocator allocator_type; |
| 89 | typedef typename allocator_type::size_type size_type; |
| 90 | typedef typename allocator_type::difference_type difference_type; |
| 91 | typedef typename allocator_type::reference reference; |
| 92 | typedef typename allocator_type::const_reference const_reference; |
| 93 | typedef typename allocator_type::pointer pointer; |
| 94 | typedef typename allocator_type::const_pointer const_pointer; |
| 95 | typedef implementation-defined iterator; |
| 96 | typedef implementation-defined const_iterator; |
| 97 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 98 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 99 | |
| 100 | static const size_type npos = -1; |
| 101 | |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 102 | basic_string() |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 103 | noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20 |
| 104 | explicit basic_string(const allocator_type& a); // constexpr since C++20 |
| 105 | basic_string(const basic_string& str); // constexpr since C++20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 106 | basic_string(basic_string&& str) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 107 | noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 108 | basic_string(const basic_string& str, size_type pos, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 109 | const allocator_type& a = allocator_type()); // constexpr since C++20 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 110 | basic_string(const basic_string& str, size_type pos, size_type n, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 111 | const Allocator& a = Allocator()); // constexpr since C++20 |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 112 | constexpr basic_string( |
| 113 | basic_string&& str, size_type pos, const Allocator& a = Allocator()); // since C++23 |
| 114 | constexpr basic_string( |
| 115 | basic_string&& str, size_type pos, size_type n, const Allocator& a = Allocator()); // since C++23 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 116 | template<class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 117 | basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17, constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 118 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 119 | explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20 |
| 120 | basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 121 | basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); // constexpr since C++20 |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 122 | basic_string(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 123 | basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 | template<class InputIterator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 125 | basic_string(InputIterator begin, InputIterator end, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 126 | const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 127 | basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20 |
| 128 | basic_string(const basic_string&, const Allocator&); // constexpr since C++20 |
| 129 | basic_string(basic_string&&, const Allocator&); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 130 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 131 | ~basic_string(); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 133 | operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 134 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 135 | basic_string& operator=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 136 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 137 | basic_string& operator=(const T& t); // C++17, constexpr since C++20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 138 | basic_string& operator=(basic_string&& str) |
| 139 | noexcept( |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 140 | allocator_type::propagate_on_container_move_assignment::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 141 | allocator_type::is_always_equal::value ); // C++17, constexpr since C++20 |
| 142 | basic_string& operator=(const value_type* s); // constexpr since C++20 |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 143 | basic_string& operator=(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 144 | basic_string& operator=(value_type c); // constexpr since C++20 |
| 145 | basic_string& operator=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 146 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 147 | iterator begin() noexcept; // constexpr since C++20 |
| 148 | const_iterator begin() const noexcept; // constexpr since C++20 |
| 149 | iterator end() noexcept; // constexpr since C++20 |
| 150 | const_iterator end() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 152 | reverse_iterator rbegin() noexcept; // constexpr since C++20 |
| 153 | const_reverse_iterator rbegin() const noexcept; // constexpr since C++20 |
| 154 | reverse_iterator rend() noexcept; // constexpr since C++20 |
| 155 | const_reverse_iterator rend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 157 | const_iterator cbegin() const noexcept; // constexpr since C++20 |
| 158 | const_iterator cend() const noexcept; // constexpr since C++20 |
| 159 | const_reverse_iterator crbegin() const noexcept; // constexpr since C++20 |
| 160 | const_reverse_iterator crend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 161 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 162 | size_type size() const noexcept; // constexpr since C++20 |
| 163 | size_type length() const noexcept; // constexpr since C++20 |
| 164 | size_type max_size() const noexcept; // constexpr since C++20 |
| 165 | size_type capacity() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 167 | void resize(size_type n, value_type c); // constexpr since C++20 |
| 168 | void resize(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 170 | template<class Operation> |
| 171 | constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23 |
| 172 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 173 | void reserve(size_type res_arg); // constexpr since C++20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 174 | void reserve(); // deprecated in C++20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 175 | void shrink_to_fit(); // constexpr since C++20 |
| 176 | void clear() noexcept; // constexpr since C++20 |
| 177 | bool empty() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 178 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 179 | const_reference operator[](size_type pos) const; // constexpr since C++20 |
| 180 | reference operator[](size_type pos); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 181 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 182 | const_reference at(size_type n) const; // constexpr since C++20 |
| 183 | reference at(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 185 | basic_string& operator+=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 186 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 187 | basic_string& operator+=(const T& t); // C++17, constexpr since C++20 |
| 188 | basic_string& operator+=(const value_type* s); // constexpr since C++20 |
| 189 | basic_string& operator+=(value_type c); // constexpr since C++20 |
| 190 | basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 191 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 192 | basic_string& append(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 193 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 194 | basic_string& append(const T& t); // C++17, constexpr since C++20 |
| 195 | basic_string& append(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 196 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 197 | basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 198 | basic_string& append(const value_type* s, size_type n); // constexpr since C++20 |
| 199 | basic_string& append(const value_type* s); // constexpr since C++20 |
| 200 | basic_string& append(size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 201 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 202 | basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20 |
| 203 | basic_string& append(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 204 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 205 | void push_back(value_type c); // constexpr since C++20 |
| 206 | void pop_back(); // constexpr since C++20 |
| 207 | reference front(); // constexpr since C++20 |
| 208 | const_reference front() const; // constexpr since C++20 |
| 209 | reference back(); // constexpr since C++20 |
| 210 | const_reference back() const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 212 | basic_string& assign(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 213 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 214 | basic_string& assign(const T& t); // C++17, constexpr since C++20 |
| 215 | basic_string& assign(basic_string&& str); // constexpr since C++20 |
| 216 | basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 217 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 218 | basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 219 | basic_string& assign(const value_type* s, size_type n); // constexpr since C++20 |
| 220 | basic_string& assign(const value_type* s); // constexpr since C++20 |
| 221 | basic_string& assign(size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 222 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 223 | basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20 |
| 224 | basic_string& assign(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 225 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 226 | basic_string& insert(size_type pos1, const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 227 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 228 | basic_string& insert(size_type pos1, const T& t); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 229 | basic_string& insert(size_type pos1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 230 | size_type pos2, size_type n); // constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 231 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 232 | basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 233 | basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20 |
| 234 | basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20 |
| 235 | basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20 |
| 236 | iterator insert(const_iterator p, value_type c); // constexpr since C++20 |
| 237 | iterator insert(const_iterator p, size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 238 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 239 | iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20 |
| 240 | iterator insert(const_iterator p, initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 242 | basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20 |
| 243 | iterator erase(const_iterator position); // constexpr since C++20 |
| 244 | iterator erase(const_iterator first, const_iterator last); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 246 | basic_string& replace(size_type pos1, size_type n1, const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 247 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 248 | basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17, constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 249 | basic_string& replace(size_type pos1, size_type n1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 250 | size_type pos2, size_type n2=npos); // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 251 | template <class T> |
| 252 | basic_string& replace(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 253 | size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 254 | basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20 |
| 255 | basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20 |
| 256 | basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20 |
| 257 | basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 258 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 259 | basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20 |
| 260 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20 |
| 261 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20 |
| 262 | basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 263 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 264 | basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20 |
| 265 | basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 266 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 267 | size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20 |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 268 | basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr in C++20, removed in C++23 |
| 269 | basic_string substr(size_type pos = 0, size_type n = npos) const&; // since C++23 |
| 270 | constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&; // since C++23 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 271 | void swap(basic_string& str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 272 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 273 | allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 275 | const value_type* c_str() const noexcept; // constexpr since C++20 |
| 276 | const value_type* data() const noexcept; // constexpr since C++20 |
| 277 | value_type* data() noexcept; // C++17, constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 279 | allocator_type get_allocator() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 281 | size_type find(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 282 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 283 | size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 284 | size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 285 | size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 286 | size_type find(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 288 | size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 289 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 290 | size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 291 | size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 292 | size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 293 | size_type rfind(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 295 | size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 296 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 297 | size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 298 | size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 299 | size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 300 | size_type find_first_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 302 | size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 303 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 304 | 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 |
| 305 | size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 306 | size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 307 | size_type find_last_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 308 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 309 | size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 310 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 311 | 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 |
| 312 | size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 313 | size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 314 | size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 315 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 316 | size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 317 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 318 | 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 |
| 319 | size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 320 | size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 321 | size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 322 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 323 | int compare(const basic_string& str) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 324 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 325 | int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 326 | int compare(size_type pos1, size_type n1, const basic_string& str) const; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 327 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 328 | int compare(size_type pos1, size_type n1, const T& t) const; // C++17, constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 329 | int compare(size_type pos1, size_type n1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 330 | size_type pos2, size_type n2=npos) const; // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 331 | template <class T> |
| 332 | int compare(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 333 | size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20 |
| 334 | int compare(const value_type* s) const noexcept; // constexpr since C++20 |
| 335 | int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20 |
| 336 | int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 337 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 338 | constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 339 | constexpr bool starts_with(charT c) const noexcept; // C++20 |
| 340 | constexpr bool starts_with(const charT* s) const; // C++20 |
| 341 | constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 342 | constexpr bool ends_with(charT c) const noexcept; // C++20 |
| 343 | constexpr bool ends_with(const charT* s) const; // C++20 |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 344 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 345 | constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b |
| 346 | constexpr bool contains(charT c) const noexcept; // C++2b |
| 347 | constexpr bool contains(const charT* s) const; // C++2b |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | }; |
| 349 | |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 350 | template<class InputIterator, |
| 351 | class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> |
| 352 | basic_string(InputIterator, InputIterator, Allocator = Allocator()) |
| 353 | -> basic_string<typename iterator_traits<InputIterator>::value_type, |
| 354 | char_traits<typename iterator_traits<InputIterator>::value_type>, |
| 355 | Allocator>; // C++17 |
| 356 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 357 | template<class charT, class traits, class Allocator> |
| 358 | basic_string<charT, traits, Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 359 | operator+(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 360 | const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 361 | |
| 362 | template<class charT, class traits, class Allocator> |
| 363 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 364 | operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | |
| 366 | template<class charT, class traits, class Allocator> |
| 367 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 368 | operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | |
| 370 | template<class charT, class traits, class Allocator> |
| 371 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 372 | operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | |
| 374 | template<class charT, class traits, class Allocator> |
| 375 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 376 | operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | |
| 378 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 379 | bool operator==(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 380 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 381 | |
| 382 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 383 | bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | |
| 385 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 386 | bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 388 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 389 | bool operator!=(const basic_string<charT,traits,Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 390 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | |
| 392 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 393 | bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | |
| 395 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 396 | bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | |
| 398 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 399 | bool operator< (const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 400 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | |
| 402 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 403 | bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | |
| 405 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 406 | bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | |
| 408 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 409 | bool operator> (const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 410 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | |
| 412 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 413 | bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | |
| 415 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 416 | bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 417 | |
| 418 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 419 | bool operator<=(const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 420 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | |
| 422 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 423 | bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | |
| 425 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 426 | bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | |
| 428 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 429 | bool operator>=(const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 430 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | |
| 432 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 433 | bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 434 | |
| 435 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 436 | bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 437 | |
| 438 | template<class charT, class traits, class Allocator> // since C++20 |
| 439 | constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, |
| 440 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
| 441 | |
| 442 | template<class charT, class traits, class Allocator> // since C++20 |
| 443 | constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, |
| 444 | const charT* rhs) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | |
| 446 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 447 | void swap(basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 448 | basic_string<charT, traits, Allocator>& rhs) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 449 | noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 450 | |
| 451 | template<class charT, class traits, class Allocator> |
| 452 | basic_istream<charT, traits>& |
| 453 | operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 454 | |
| 455 | template<class charT, class traits, class Allocator> |
| 456 | basic_ostream<charT, traits>& |
| 457 | operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); |
| 458 | |
| 459 | template<class charT, class traits, class Allocator> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 460 | basic_istream<charT, traits>& |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 461 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, |
| 462 | charT delim); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | |
| 464 | template<class charT, class traits, class Allocator> |
| 465 | basic_istream<charT, traits>& |
| 466 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 467 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 468 | template<class charT, class traits, class Allocator, class U> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 469 | typename basic_string<charT, traits, Allocator>::size_type |
| 470 | erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 471 | template<class charT, class traits, class Allocator, class Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 472 | typename basic_string<charT, traits, Allocator>::size_type |
| 473 | erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 474 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | typedef basic_string<char> string; |
| 476 | typedef basic_string<wchar_t> wstring; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 477 | typedef basic_string<char8_t> u8string; // C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 478 | typedef basic_string<char16_t> u16string; |
| 479 | typedef basic_string<char32_t> u32string; |
| 480 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 481 | int stoi (const string& str, size_t* idx = nullptr, int base = 10); |
| 482 | long stol (const string& str, size_t* idx = nullptr, int base = 10); |
| 483 | unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10); |
| 484 | long long stoll (const string& str, size_t* idx = nullptr, int base = 10); |
| 485 | unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 486 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 487 | float stof (const string& str, size_t* idx = nullptr); |
| 488 | double stod (const string& str, size_t* idx = nullptr); |
| 489 | long double stold(const string& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 490 | |
| 491 | string to_string(int val); |
| 492 | string to_string(unsigned val); |
| 493 | string to_string(long val); |
| 494 | string to_string(unsigned long val); |
| 495 | string to_string(long long val); |
| 496 | string to_string(unsigned long long val); |
| 497 | string to_string(float val); |
| 498 | string to_string(double val); |
| 499 | string to_string(long double val); |
| 500 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 501 | int stoi (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 502 | long stol (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 503 | unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 504 | long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 505 | unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 506 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 507 | float stof (const wstring& str, size_t* idx = nullptr); |
| 508 | double stod (const wstring& str, size_t* idx = nullptr); |
| 509 | long double stold(const wstring& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 510 | |
| 511 | wstring to_wstring(int val); |
| 512 | wstring to_wstring(unsigned val); |
| 513 | wstring to_wstring(long val); |
| 514 | wstring to_wstring(unsigned long val); |
| 515 | wstring to_wstring(long long val); |
| 516 | wstring to_wstring(unsigned long long val); |
| 517 | wstring to_wstring(float val); |
| 518 | wstring to_wstring(double val); |
| 519 | wstring to_wstring(long double val); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | |
| 521 | template <> struct hash<string>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 522 | template <> struct hash<u8string>; // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | template <> struct hash<u16string>; |
| 524 | template <> struct hash<u32string>; |
| 525 | template <> struct hash<wstring>; |
| 526 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 527 | basic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20 |
| 528 | basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20 |
| 529 | constexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20 |
| 530 | basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20 |
| 531 | basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14, constexpr since C++20 |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 532 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | } // std |
| 534 | |
| 535 | */ |
| 536 | |
Nikolas Klauser | f210d8a | 2022-02-15 18:18:08 +0100 | [diff] [blame] | 537 | #include <__algorithm/max.h> |
| 538 | #include <__algorithm/min.h> |
| 539 | #include <__algorithm/remove.h> |
| 540 | #include <__algorithm/remove_if.h> |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 541 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | #include <__config> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 543 | #include <__debug> |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 544 | #include <__format/enable_insertable.h> |
Nikolas Klauser | 11a0ff3 | 2022-06-06 23:35:24 +0200 | [diff] [blame] | 545 | #include <__functional/hash.h> |
Nikolas Klauser | 24540d3 | 2022-05-21 00:45:51 +0200 | [diff] [blame] | 546 | #include <__functional/unary_function.h> |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 547 | #include <__fwd/string.h> |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 548 | #include <__ios/fpos.h> |
Nikolas Klauser | fb1b067 | 2022-06-10 19:53:10 +0200 | [diff] [blame] | 549 | #include <__iterator/distance.h> |
| 550 | #include <__iterator/iterator_traits.h> |
| 551 | #include <__iterator/reverse_iterator.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 552 | #include <__iterator/wrap_iter.h> |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 553 | #include <__memory/allocate_at_least.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 554 | #include <__memory/allocator.h> |
| 555 | #include <__memory/allocator_traits.h> |
| 556 | #include <__memory/compressed_pair.h> |
| 557 | #include <__memory/construct_at.h> |
| 558 | #include <__memory/pointer_traits.h> |
Nikolas Klauser | 35080b4 | 2022-07-26 16:13:56 +0200 | [diff] [blame] | 559 | #include <__memory/swap_allocator.h> |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 560 | #include <__memory_resource/polymorphic_allocator.h> |
Nikolas Klauser | 11a0ff3 | 2022-06-06 23:35:24 +0200 | [diff] [blame] | 561 | #include <__string/char_traits.h> |
| 562 | #include <__string/extern_template_lists.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 563 | #include <__type_traits/is_allocator.h> |
| 564 | #include <__type_traits/noexcept_move_assign_container.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 565 | #include <__utility/auto_cast.h> |
| 566 | #include <__utility/move.h> |
| 567 | #include <__utility/swap.h> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 568 | #include <__utility/unreachable.h> |
| 569 | #include <climits> |
Louis Dionne | 44962c3 | 2022-06-13 11:21:16 -0400 | [diff] [blame] | 570 | #include <cstdint> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 571 | #include <cstdio> // EOF |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 572 | #include <cstdlib> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 573 | #include <cstring> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 574 | #include <limits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | #include <stdexcept> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 576 | #include <string_view> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 578 | #include <version> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 579 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 580 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 581 | # include <cwchar> |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 582 | #endif |
| 583 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 584 | // standard-mandated includes |
| 585 | |
| 586 | // [iterator.range] |
| 587 | #include <__iterator/access.h> |
| 588 | #include <__iterator/data.h> |
| 589 | #include <__iterator/empty.h> |
| 590 | #include <__iterator/reverse_access.h> |
| 591 | #include <__iterator/size.h> |
| 592 | |
| 593 | // [string.syn] |
| 594 | #include <compare> |
| 595 | #include <initializer_list> |
| 596 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 597 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 598 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 599 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 601 | _LIBCPP_PUSH_MACROS |
| 602 | #include <__undef_macros> |
| 603 | |
| 604 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 606 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 607 | // basic_string |
| 608 | |
| 609 | template<class _CharT, class _Traits, class _Allocator> |
| 610 | basic_string<_CharT, _Traits, _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 611 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 612 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, |
| 613 | const basic_string<_CharT, _Traits, _Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 614 | |
| 615 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 616 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 618 | operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | |
| 620 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 621 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 623 | operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 624 | |
| 625 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 626 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 627 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 628 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | |
| 630 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 631 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 633 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 635 | extern template _LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&); |
Shoaib Meenai | ea36371 | 2017-07-29 02:54:41 +0000 | [diff] [blame] | 636 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 637 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 638 | struct __string_is_trivial_iterator : public false_type {}; |
| 639 | |
| 640 | template <class _Tp> |
| 641 | struct __string_is_trivial_iterator<_Tp*> |
| 642 | : public is_arithmetic<_Tp> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 643 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 644 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 645 | struct __string_is_trivial_iterator<__wrap_iter<_Iter> > |
| 646 | : public __string_is_trivial_iterator<_Iter> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 647 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 648 | template <class _CharT, class _Traits, class _Tp> |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 649 | struct __can_be_converted_to_string_view : public _BoolConstant< |
| 650 | is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && |
| 651 | !is_convertible<const _Tp&, const _CharT*>::value |
| 652 | > {}; |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 653 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 654 | struct __uninitialized_size_tag {}; |
| 655 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 656 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 657 | class basic_string |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | { |
| 659 | public: |
| 660 | typedef basic_string __self; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 661 | typedef basic_string_view<_CharT, _Traits> __self_view; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | typedef _Traits traits_type; |
Marshall Clow | a3a74e0 | 2017-03-15 18:41:11 +0000 | [diff] [blame] | 663 | typedef _CharT value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 664 | typedef _Allocator allocator_type; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 665 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 666 | typedef typename __alloc_traits::size_type size_type; |
| 667 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 668 | typedef value_type& reference; |
| 669 | typedef const value_type& const_reference; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 670 | typedef typename __alloc_traits::pointer pointer; |
| 671 | typedef typename __alloc_traits::const_pointer const_pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 672 | |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 673 | static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); |
| 674 | static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); |
| 675 | static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); |
| 676 | static_assert(( is_same<_CharT, typename traits_type::char_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 677 | "traits_type::char_type must be the same type as CharT"); |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 678 | static_assert(( is_same<typename allocator_type::value_type, value_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 679 | "Allocator::value_type must be same type as value_type"); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 680 | |
Nikolas Klauser | eb116e2 | 2022-10-08 22:17:32 +0200 | [diff] [blame] | 681 | static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, |
| 682 | "[allocator.requirements] states that rebinding an allocator to the same type should result in the " |
| 683 | "original allocator"); |
| 684 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 685 | typedef __wrap_iter<pointer> iterator; |
| 686 | typedef __wrap_iter<const_pointer> const_iterator; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 687 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 688 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 689 | |
| 690 | private: |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 691 | static_assert(CHAR_BIT == 8, "This implementation assumes that one byte contains 8 bits"); |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 692 | |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 693 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 694 | |
| 695 | struct __long |
| 696 | { |
| 697 | pointer __data_; |
| 698 | size_type __size_; |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 699 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 700 | size_type __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 701 | }; |
| 702 | |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 703 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 704 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 705 | |
| 706 | struct __short |
| 707 | { |
| 708 | value_type __data_[__min_cap]; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 709 | unsigned char __padding_[sizeof(value_type) - 1]; |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 710 | unsigned char __size_ : 7; |
| 711 | unsigned char __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 712 | }; |
| 713 | |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 714 | // The __endian_factor is required because the field we use to store the size |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 715 | // has one fewer bit than it would if it were not a bitfield. |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 716 | // |
| 717 | // If the LSB is used to store the short-flag in the short string representation, |
| 718 | // we have to multiply the size by two when it is stored and divide it by two when |
| 719 | // it is loaded to make sure that we always store an even number. In the long string |
| 720 | // representation, we can ignore this because we can assume that we always allocate |
| 721 | // an even amount of value_types. |
| 722 | // |
| 723 | // If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2. |
| 724 | // This does not impact the short string representation, since we never need the MSB |
| 725 | // for representing the size of a short string anyway. |
| 726 | |
| 727 | #ifdef _LIBCPP_BIG_ENDIAN |
| 728 | static const size_type __endian_factor = 2; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 729 | #else |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 730 | static const size_type __endian_factor = 1; |
| 731 | #endif |
| 732 | |
| 733 | #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 734 | |
| 735 | #ifdef _LIBCPP_BIG_ENDIAN |
| 736 | static const size_type __endian_factor = 1; |
| 737 | #else |
| 738 | static const size_type __endian_factor = 2; |
| 739 | #endif |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 740 | |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 741 | // Attribute 'packed' is used to keep the layout compatible with the |
| 742 | // previous definition that did not use bit fields. This is because on |
| 743 | // some platforms bit fields have a default size rather than the actual |
| 744 | // size used, e.g., it is 4 bytes on AIX. See D128285 for details. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 745 | struct __long |
| 746 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 747 | struct _LIBCPP_PACKED { |
| 748 | size_type __is_long_ : 1; |
| 749 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 750 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 751 | size_type __size_; |
| 752 | pointer __data_; |
| 753 | }; |
| 754 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 755 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 756 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 757 | |
| 758 | struct __short |
| 759 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 760 | struct _LIBCPP_PACKED { |
| 761 | unsigned char __is_long_ : 1; |
| 762 | unsigned char __size_ : 7; |
| 763 | }; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 764 | char __padding_[sizeof(value_type) - 1]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 765 | value_type __data_[__min_cap]; |
| 766 | }; |
| 767 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 768 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 769 | |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 770 | static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size."); |
| 771 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 772 | union __ulx{__long __lx; __short __lxx;}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 773 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 774 | enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 775 | |
| 776 | struct __raw |
| 777 | { |
| 778 | size_type __words[__n_words]; |
| 779 | }; |
| 780 | |
| 781 | struct __rep |
| 782 | { |
| 783 | union |
| 784 | { |
| 785 | __long __l; |
| 786 | __short __s; |
| 787 | __raw __r; |
| 788 | }; |
| 789 | }; |
| 790 | |
| 791 | __compressed_pair<__rep, allocator_type> __r_; |
| 792 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 793 | // Construct a string with the given allocator and enough storage to hold `__size` characters, but |
| 794 | // don't initialize the characters. The contents of the string, including the null terminator, must be |
| 795 | // initialized separately. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 796 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 797 | explicit basic_string(__uninitialized_size_tag, size_type __size, const allocator_type& __a) |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 798 | : __r_(__default_init_tag(), __a) { |
| 799 | if (__size > max_size()) |
| 800 | __throw_length_error(); |
| 801 | if (__fits_in_sso(__size)) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 802 | __r_.first() = __rep(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 803 | __set_short_size(__size); |
| 804 | } else { |
| 805 | auto __capacity = __recommend(__size) + 1; |
| 806 | auto __allocation = __alloc_traits::allocate(__alloc(), __capacity); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 807 | __begin_lifetime(__allocation, __capacity); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 808 | __set_long_cap(__capacity); |
| 809 | __set_long_pointer(__allocation); |
| 810 | __set_long_size(__size); |
| 811 | } |
| 812 | std::__debug_db_insert_c(this); |
| 813 | } |
| 814 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 815 | public: |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 816 | _LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 817 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 818 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() |
| 819 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
| 820 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 821 | std::__debug_db_insert_c(this); |
| 822 | __default_init(); |
| 823 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 824 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 825 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const allocator_type& __a) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 826 | #if _LIBCPP_STD_VER <= 14 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 827 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 828 | #else |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 829 | _NOEXCEPT |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 830 | #endif |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 831 | : __r_(__default_init_tag(), __a) { |
| 832 | std::__debug_db_insert_c(this); |
| 833 | __default_init(); |
| 834 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 835 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 836 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str); |
| 837 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, const allocator_type& __a); |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 838 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 839 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 840 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str) |
| 841 | # if _LIBCPP_STD_VER <= 14 |
| 842 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
| 843 | # else |
| 844 | _NOEXCEPT |
| 845 | # endif |
| 846 | : __r_(std::move(__str.__r_)) { |
| 847 | __str.__default_init(); |
| 848 | std::__debug_db_insert_c(this); |
| 849 | if (__is_long()) |
| 850 | std::__debug_db_swap(this, &__str); |
| 851 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 852 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 853 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a) |
| 854 | : __r_(__default_init_tag(), __a) { |
| 855 | if (__str.__is_long() && __a != __str.__alloc()) // copy, not move |
| 856 | __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); |
| 857 | else { |
| 858 | if (__libcpp_is_constant_evaluated()) |
| 859 | __r_.first() = __rep(); |
| 860 | __r_.first() = __str.__r_.first(); |
| 861 | __str.__default_init(); |
| 862 | } |
| 863 | std::__debug_db_insert_c(this); |
| 864 | if (__is_long()) |
| 865 | std::__debug_db_swap(this, &__str); |
| 866 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 867 | #endif // _LIBCPP_CXX03_LANG |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 868 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 869 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 870 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) |
| 871 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 872 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); |
| 873 | __init(__s, traits_type::length(__s)); |
| 874 | std::__debug_db_insert_c(this); |
| 875 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 876 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 877 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 878 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 879 | |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 880 | #if _LIBCPP_STD_VER > 20 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 881 | basic_string(nullptr_t) = delete; |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 882 | #endif |
| 883 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 884 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) |
| 885 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 886 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); |
| 887 | __init(__s, __n); |
| 888 | std::__debug_db_insert_c(this); |
| 889 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 890 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 891 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 892 | basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) |
| 893 | : __r_(__default_init_tag(), __a) { |
| 894 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); |
| 895 | __init(__s, __n); |
| 896 | std::__debug_db_insert_c(this); |
| 897 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 898 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 899 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) |
| 900 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 901 | __init(__n, __c); |
| 902 | std::__debug_db_insert_c(this); |
| 903 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 904 | |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 905 | #if _LIBCPP_STD_VER > 20 |
| 906 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 907 | basic_string(basic_string&& __str, size_type __pos, const _Allocator& __alloc = _Allocator()) |
| 908 | : basic_string(std::move(__str), __pos, npos, __alloc) {} |
| 909 | |
| 910 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 911 | basic_string(basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator()) |
| 912 | : __r_(__default_init_tag(), __alloc) { |
| 913 | if (__pos > __str.size()) |
| 914 | __throw_out_of_range(); |
| 915 | |
| 916 | auto __len = std::min<size_type>(__n, __str.size() - __pos); |
| 917 | if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc()) { |
| 918 | __r_.first() = __str.__r_.first(); |
| 919 | __str.__default_init(); |
| 920 | |
| 921 | _Traits::move(data(), data() + __pos, __len); |
| 922 | __set_size(__len); |
| 923 | _Traits::assign(data()[__len], value_type()); |
| 924 | } else { |
| 925 | // Perform a copy because the allocators are not compatible. |
| 926 | __init(__str.data() + __pos, __len); |
| 927 | } |
| 928 | |
| 929 | std::__debug_db_insert_c(this); |
| 930 | if (__is_long()) |
| 931 | std::__debug_db_swap(this, &__str); |
| 932 | } |
| 933 | #endif |
| 934 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 935 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 936 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 937 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 938 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 939 | basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator()); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 940 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 941 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 942 | basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator()) |
| 943 | : __r_(__default_init_tag(), __a) { |
| 944 | size_type __str_sz = __str.size(); |
| 945 | if (__pos > __str_sz) |
| 946 | __throw_out_of_range(); |
| 947 | __init(__str.data() + __pos, __str_sz - __pos); |
| 948 | std::__debug_db_insert_c(this); |
| 949 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 950 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 951 | template <class _Tp, |
| 952 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 953 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 954 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 955 | basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()); |
| 956 | |
| 957 | template <class _Tp, |
| 958 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 959 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 960 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 961 | const _Tp& __t); |
| 962 | |
| 963 | template <class _Tp, |
| 964 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 965 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 966 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 967 | const _Tp& __t, const allocator_type& __a); |
| 968 | |
| 969 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 970 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) |
| 971 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 972 | __init(__first, __last); |
| 973 | std::__debug_db_insert_c(this); |
| 974 | } |
| 975 | |
| 976 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 977 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 978 | basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) |
| 979 | : __r_(__default_init_tag(), __a) { |
| 980 | __init(__first, __last); |
| 981 | std::__debug_db_insert_c(this); |
| 982 | } |
| 983 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 984 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 985 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) |
| 986 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 987 | __init(__il.begin(), __il.end()); |
| 988 | std::__debug_db_insert_c(this); |
| 989 | } |
| 990 | |
| 991 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a) |
| 992 | : __r_(__default_init_tag(), __a) { |
| 993 | __init(__il.begin(), __il.end()); |
| 994 | std::__debug_db_insert_c(this); |
| 995 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 996 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 997 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 998 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 999 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1000 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1001 | operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } |
| 1002 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1003 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const basic_string& __str); |
Eric Fiselier | 5ec13b1 | 2017-01-23 21:24:58 +0000 | [diff] [blame] | 1004 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1005 | template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 1006 | !__is_same_uncvref<_Tp, basic_string>::value> > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1007 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1008 | __self_view __sv = __t; |
| 1009 | return assign(__sv); |
| 1010 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1011 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1012 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1013 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1014 | basic_string& operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1015 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1016 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1017 | basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1019 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1020 | basic_string& operator=(const value_type* __s) {return assign(__s);} |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 1021 | #if _LIBCPP_STD_VER > 20 |
| 1022 | basic_string& operator=(nullptr_t) = delete; |
| 1023 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1024 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1025 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1026 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1027 | iterator begin() _NOEXCEPT |
| 1028 | {return iterator(this, __get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1029 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1030 | const_iterator begin() const _NOEXCEPT |
| 1031 | {return const_iterator(this, __get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1032 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1033 | iterator end() _NOEXCEPT |
| 1034 | {return iterator(this, __get_pointer() + size());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1035 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1036 | const_iterator end() const _NOEXCEPT |
| 1037 | {return const_iterator(this, __get_pointer() + size());} |
Louis Dionne | e554e10 | 2022-06-03 15:17:03 -0400 | [diff] [blame] | 1038 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1039 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1040 | reverse_iterator rbegin() _NOEXCEPT |
| 1041 | {return reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1042 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1043 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1044 | {return const_reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1045 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1046 | reverse_iterator rend() _NOEXCEPT |
| 1047 | {return reverse_iterator(begin());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1048 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1049 | const_reverse_iterator rend() const _NOEXCEPT |
| 1050 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1051 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1052 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1053 | const_iterator cbegin() const _NOEXCEPT |
| 1054 | {return begin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1055 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1056 | const_iterator cend() const _NOEXCEPT |
| 1057 | {return end();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1058 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1059 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 1060 | {return rbegin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1061 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1062 | const_reverse_iterator crend() const _NOEXCEPT |
| 1063 | {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1064 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1065 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | {return __is_long() ? __get_long_size() : __get_short_size();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1067 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT {return size();} |
| 1068 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT; |
| 1069 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type capacity() const _NOEXCEPT { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1070 | return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1; |
| 1071 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1072 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1073 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n, value_type __c); |
| 1074 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n) { resize(__n, value_type()); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1075 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1076 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __requested_capacity); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1077 | |
| 1078 | #if _LIBCPP_STD_VER > 20 |
| 1079 | template <class _Op> |
| 1080 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1081 | void resize_and_overwrite(size_type __n, _Op __op) { |
| 1082 | __resize_default_init(__n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1083 | __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n))); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1084 | } |
| 1085 | #endif |
| 1086 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1087 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __resize_default_init(size_type __n); |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1088 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1089 | _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_HIDE_FROM_ABI void reserve() _NOEXCEPT { shrink_to_fit(); } |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1090 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT; |
| 1091 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1092 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1093 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1094 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1095 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1096 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1097 | const_reference operator[](size_type __pos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1098 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __pos) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1099 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1100 | _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const; |
| 1101 | _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1102 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1103 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const basic_string& __str) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1104 | return append(__str); |
| 1105 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1106 | |
| 1107 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1108 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1109 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1110 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1111 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1112 | && !__is_same_uncvref<_Tp, basic_string >::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1113 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1114 | > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1115 | operator+=(const _Tp& __t) { |
| 1116 | __self_view __sv = __t; return append(__sv); |
| 1117 | } |
| 1118 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1119 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(const value_type* __s) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1120 | return append(__s); |
| 1121 | } |
| 1122 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1123 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator+=(value_type __c) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1124 | push_back(__c); |
| 1125 | return *this; |
| 1126 | } |
| 1127 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1128 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1129 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1130 | basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1131 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1132 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1133 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | basic_string& append(const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1135 | |
| 1136 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1137 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1138 | __enable_if_t< |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1139 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1140 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1141 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1142 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1143 | append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); } |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1144 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1145 | |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 1146 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1147 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1148 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1149 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1150 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1151 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1152 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1153 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1154 | append(const _Tp& __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1155 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n); |
| 1156 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s); |
| 1157 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(size_type __n, value_type __c); |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1158 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1159 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1160 | void __append_default_init(size_type __n); |
| 1161 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1162 | template<class _InputIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1163 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1164 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1165 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1166 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1167 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1168 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1169 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1170 | append(_InputIterator __first, _InputIterator __last) { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1171 | const basic_string __temp(__first, __last, __alloc()); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1172 | append(__temp.data(), __temp.size()); |
| 1173 | return *this; |
| 1174 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1175 | template<class _ForwardIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1176 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1177 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1178 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1179 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1180 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1181 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1182 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1183 | append(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1184 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1185 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1186 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1187 | basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1188 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1189 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1190 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(value_type __c); |
| 1191 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back(); |
| 1192 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() _NOEXCEPT; |
| 1193 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _NOEXCEPT; |
| 1194 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _NOEXCEPT; |
| 1195 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1196 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1197 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1198 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1199 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1200 | < |
| 1201 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1202 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1203 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1204 | assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); } |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1205 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 95d5e9a | 2016-03-09 18:08:29 +0000 | [diff] [blame] | 1206 | basic_string& assign(const basic_string& __str) { return *this = __str; } |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1207 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1208 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1209 | basic_string& assign(basic_string&& __str) |
Marshall Clow | 5aa9e94 | 2015-10-05 16:17:34 +0000 | [diff] [blame] | 1210 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1211 | {*this = std::move(__str); return *this;} |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1212 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1213 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 1214 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1215 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1216 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1217 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1218 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1219 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1220 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1221 | > |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1222 | assign(const _Tp & __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1223 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s, size_type __n); |
| 1224 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s); |
| 1225 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(size_type __n, value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1226 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1227 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1228 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1229 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1230 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1231 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1232 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1233 | assign(_InputIterator __first, _InputIterator __last); |
| 1234 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1235 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1236 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1237 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1238 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1239 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1240 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1241 | assign(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1242 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1243 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1245 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1247 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1248 | basic_string& insert(size_type __pos1, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1249 | |
| 1250 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1251 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1252 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1253 | < |
| 1254 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1255 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1256 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1257 | insert(size_type __pos1, const _Tp& __t) |
| 1258 | { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); } |
| 1259 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1260 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1261 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1262 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1263 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1264 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1265 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1266 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1267 | insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1268 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1269 | basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1270 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s, size_type __n); |
| 1271 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s); |
| 1272 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c); |
| 1273 | _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c); |
| 1274 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1275 | iterator insert(const_iterator __pos, size_type __n, value_type __c); |
| 1276 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1277 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1278 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1279 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1280 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1281 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1282 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1283 | insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); |
| 1284 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1285 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1286 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1287 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1288 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1290 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1291 | insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1292 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1293 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1294 | iterator insert(const_iterator __pos, initializer_list<value_type> __il) |
| 1295 | {return insert(__pos, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1296 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1297 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1298 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos); |
| 1299 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1300 | iterator erase(const_iterator __pos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1301 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1302 | iterator erase(const_iterator __first, const_iterator __last); |
| 1303 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1304 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1305 | basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1306 | |
| 1307 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1308 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1309 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1310 | < |
| 1311 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1312 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1313 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1314 | replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); } |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1315 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1316 | basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos); |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1317 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1318 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1319 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1320 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1321 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1322 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1323 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1324 | replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1325 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1326 | basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1327 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); |
| 1328 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); |
| 1329 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1330 | basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1331 | |
| 1332 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1333 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1334 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1335 | < |
| 1336 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1337 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1338 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1339 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); } |
| 1340 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1341 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1342 | basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1343 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1344 | basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1345 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1346 | basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1347 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1348 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1349 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1350 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1351 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1353 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1354 | replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1355 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1356 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1357 | basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1358 | {return replace(__i1, __i2, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1359 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1360 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1361 | _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1362 | |
| 1363 | // TODO: Maybe don't pass in the allocator. See https://llvm.org/PR57190 |
| 1364 | #if _LIBCPP_STD_VER <= 20 |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1365 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1366 | basic_string substr(size_type __pos = 0, size_type __n = npos) const { |
| 1367 | return basic_string(*this, __pos, __n, __alloc()); |
| 1368 | } |
| 1369 | #else |
| 1370 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1371 | basic_string substr(size_type __pos = 0, size_type __n = npos) const& { |
| 1372 | return basic_string(*this, __pos, __n, __alloc()); |
| 1373 | } |
| 1374 | |
| 1375 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1376 | basic_string substr(size_type __pos = 0, size_type __n = npos) && { |
| 1377 | return basic_string(std::move(*this), __pos, __n, __alloc()); |
| 1378 | } |
| 1379 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1381 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1382 | void swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1383 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1384 | _NOEXCEPT; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1385 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1386 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1387 | __is_nothrow_swappable<allocator_type>::value); |
| 1388 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1389 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1390 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1391 | const value_type* c_str() const _NOEXCEPT {return data();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1392 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1393 | const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());} |
Eric Fiselier | 4ee2a89 | 2017-11-20 20:23:27 +0000 | [diff] [blame] | 1394 | #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1395 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1396 | value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());} |
Marshall Clow | d3c2239 | 2016-03-08 15:44:30 +0000 | [diff] [blame] | 1397 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1398 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1399 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1400 | allocator_type get_allocator() const _NOEXCEPT {return __alloc();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1401 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1402 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1403 | size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1404 | |
| 1405 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1406 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1407 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1408 | < |
| 1409 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1410 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1411 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1412 | find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1413 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1414 | size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1415 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1416 | size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1417 | _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1418 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1419 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1420 | size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1421 | |
| 1422 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1423 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1424 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1425 | < |
| 1426 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1427 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1428 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1429 | rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1430 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1431 | size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1432 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1433 | size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1434 | _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1435 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1436 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1437 | size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1438 | |
| 1439 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1440 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1441 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1442 | < |
| 1443 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1444 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1445 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1446 | find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1447 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1448 | size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1449 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1450 | size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1451 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1452 | size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1453 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1454 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1455 | size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1456 | |
| 1457 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1458 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1459 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1460 | < |
| 1461 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1462 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1463 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1464 | find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1465 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1466 | size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1467 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1468 | size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1469 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1470 | size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1471 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1472 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1473 | size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1474 | |
| 1475 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1476 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1477 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1478 | < |
| 1479 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1480 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1481 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1482 | find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1483 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1484 | size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1485 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1486 | size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1487 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1488 | size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
| 1489 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1490 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1491 | size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1492 | |
| 1493 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1494 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1495 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1496 | < |
| 1497 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1498 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1499 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1500 | find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1501 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1502 | size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1503 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1504 | size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1505 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1506 | size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
| 1507 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1508 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1509 | int compare(const basic_string& __str) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1510 | |
| 1511 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1512 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1513 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1514 | < |
| 1515 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1516 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1517 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1518 | compare(const _Tp &__t) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1519 | |
| 1520 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1521 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1522 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1523 | < |
| 1524 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1525 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1526 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1527 | compare(size_type __pos1, size_type __n1, const _Tp& __t) const; |
| 1528 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1529 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1530 | int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1531 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1532 | int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, |
| 1533 | size_type __n2 = npos) const; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1534 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1535 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1536 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1537 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1538 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1539 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1540 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1541 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1542 | compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1543 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* __s) const _NOEXCEPT; |
| 1544 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(size_type __pos1, size_type __n1, const value_type* __s) const; |
| 1545 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1546 | int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1547 | |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1548 | #if _LIBCPP_STD_VER > 17 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1549 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1550 | bool starts_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1551 | { return __self_view(data(), size()).starts_with(__sv); } |
| 1552 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1553 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1554 | bool starts_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1555 | { return !empty() && _Traits::eq(front(), __c); } |
| 1556 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1557 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1558 | bool starts_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1559 | { return starts_with(__self_view(__s)); } |
| 1560 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1561 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1562 | bool ends_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1563 | { return __self_view(data(), size()).ends_with( __sv); } |
| 1564 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1565 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1566 | bool ends_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1567 | { return !empty() && _Traits::eq(back(), __c); } |
| 1568 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1569 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1570 | bool ends_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1571 | { return ends_with(__self_view(__s)); } |
| 1572 | #endif |
| 1573 | |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1574 | #if _LIBCPP_STD_VER > 20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1575 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1576 | bool contains(__self_view __sv) const noexcept |
| 1577 | { return __self_view(data(), size()).contains(__sv); } |
| 1578 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1579 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1580 | bool contains(value_type __c) const noexcept |
| 1581 | { return __self_view(data(), size()).contains(__c); } |
| 1582 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1583 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1584 | bool contains(const value_type* __s) const |
| 1585 | { return __self_view(data(), size()).contains(__s); } |
| 1586 | #endif |
| 1587 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1588 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1589 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1590 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __clear_and_shrink() _NOEXCEPT; |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1591 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1592 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1593 | |
| 1594 | bool __dereferenceable(const const_iterator* __i) const; |
| 1595 | bool __decrementable(const const_iterator* __i) const; |
| 1596 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1597 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1598 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1599 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1600 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1601 | private: |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1602 | template<class _Alloc> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1603 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1604 | bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs, |
| 1605 | const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT; |
| 1606 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1607 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __shrink_or_extend(size_type __target_capacity); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1608 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1609 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1610 | bool __is_long() const _NOEXCEPT { |
| 1611 | if (__libcpp_is_constant_evaluated()) |
| 1612 | return true; |
| 1613 | return __r_.first().__s.__is_long_; |
| 1614 | } |
| 1615 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1616 | static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __begin_lifetime(pointer __begin, size_type __n) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1617 | #if _LIBCPP_STD_VER > 17 |
| 1618 | if (__libcpp_is_constant_evaluated()) { |
| 1619 | for (size_type __i = 0; __i != __n; ++__i) |
| 1620 | std::construct_at(std::addressof(__begin[__i])); |
| 1621 | } |
| 1622 | #else |
| 1623 | (void)__begin; |
| 1624 | (void)__n; |
| 1625 | #endif // _LIBCPP_STD_VER > 17 |
| 1626 | } |
| 1627 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1628 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init() { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1629 | __r_.first() = __rep(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1630 | if (__libcpp_is_constant_evaluated()) { |
| 1631 | size_type __sz = __recommend(0) + 1; |
| 1632 | pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); |
| 1633 | __begin_lifetime(__ptr, __sz); |
| 1634 | __set_long_pointer(__ptr); |
| 1635 | __set_long_cap(__sz); |
| 1636 | __set_long_size(0); |
| 1637 | } |
| 1638 | } |
| 1639 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1640 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_constexpr() { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1641 | if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr) |
| 1642 | __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap()); |
| 1643 | } |
| 1644 | |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1645 | _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { |
| 1646 | // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly |
| 1647 | return !__libcpp_is_constant_evaluated() && (__sz < __min_cap); |
| 1648 | } |
| 1649 | |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1650 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1651 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1652 | iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) { |
| 1653 | size_type __sz = size(); |
| 1654 | size_type __cap = capacity(); |
| 1655 | value_type* __p; |
| 1656 | if (__cap - __sz >= __n) |
| 1657 | { |
| 1658 | __p = std::__to_address(__get_pointer()); |
| 1659 | size_type __n_move = __sz - __ip; |
| 1660 | if (__n_move != 0) |
| 1661 | traits_type::move(__p + __ip + __n, __p + __ip, __n_move); |
| 1662 | } |
| 1663 | else |
| 1664 | { |
| 1665 | __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); |
| 1666 | __p = std::__to_address(__get_long_pointer()); |
| 1667 | } |
| 1668 | __sz += __n; |
| 1669 | __set_size(__sz); |
| 1670 | traits_type::assign(__p[__sz], value_type()); |
| 1671 | for (__p += __ip; __first != __last; ++__p, ++__first) |
| 1672 | traits_type::assign(*__p, *__first); |
| 1673 | |
| 1674 | return begin() + __ip; |
| 1675 | } |
| 1676 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1677 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1678 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR const allocator_type& __alloc() const _NOEXCEPT { return __r_.second(); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1679 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1680 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1681 | void __set_short_size(size_type __s) _NOEXCEPT { |
| 1682 | _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity"); |
| 1683 | __r_.first().__s.__size_ = __s; |
| 1684 | __r_.first().__s.__is_long_ = false; |
| 1685 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1686 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1687 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1688 | size_type __get_short_size() const _NOEXCEPT { |
| 1689 | _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); |
| 1690 | return __r_.first().__s.__size_; |
| 1691 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1692 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1693 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1694 | void __set_long_size(size_type __s) _NOEXCEPT |
| 1695 | {__r_.first().__l.__size_ = __s;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1696 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1697 | size_type __get_long_size() const _NOEXCEPT |
| 1698 | {return __r_.first().__l.__size_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1699 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1700 | void __set_size(size_type __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1701 | {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} |
| 1702 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1703 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1704 | void __set_long_cap(size_type __s) _NOEXCEPT { |
| 1705 | __r_.first().__l.__cap_ = __s / __endian_factor; |
| 1706 | __r_.first().__l.__is_long_ = true; |
| 1707 | } |
| 1708 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1709 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1710 | size_type __get_long_cap() const _NOEXCEPT { |
| 1711 | return __r_.first().__l.__cap_ * __endian_factor; |
| 1712 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1713 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1714 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1715 | void __set_long_pointer(pointer __p) _NOEXCEPT |
| 1716 | {__r_.first().__l.__data_ = __p;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1717 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1718 | pointer __get_long_pointer() _NOEXCEPT |
| 1719 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1720 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1721 | const_pointer __get_long_pointer() const _NOEXCEPT |
| 1722 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1723 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1724 | pointer __get_short_pointer() _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1725 | {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1726 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1727 | const_pointer __get_short_pointer() const _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1728 | {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1729 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1730 | pointer __get_pointer() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1731 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1732 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1733 | const_pointer __get_pointer() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1734 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
| 1735 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1736 | template <size_type __a> static |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1737 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 1738 | size_type __align_it(size_type __s) _NOEXCEPT |
Eric Fiselier | 8599fcc | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 1739 | {return (__s + (__a-1)) & ~(__a-1);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1740 | enum {__alignment = 16}; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1741 | static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1742 | size_type __recommend(size_type __s) _NOEXCEPT |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1743 | { |
| 1744 | if (__s < __min_cap) { |
| 1745 | if (__libcpp_is_constant_evaluated()) |
| 1746 | return static_cast<size_type>(__min_cap); |
| 1747 | else |
| 1748 | return static_cast<size_type>(__min_cap) - 1; |
| 1749 | } |
Marshall Clow | 8058452 | 2018-02-07 21:30:17 +0000 | [diff] [blame] | 1750 | size_type __guess = __align_it<sizeof(value_type) < __alignment ? |
| 1751 | __alignment/sizeof(value_type) : 1 > (__s+1) - 1; |
| 1752 | if (__guess == __min_cap) ++__guess; |
| 1753 | return __guess; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1754 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1755 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1756 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1757 | void __init(const value_type* __s, size_type __sz, size_type __reserve); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1758 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1759 | void __init(const value_type* __s, size_type __sz); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1760 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | void __init(size_type __n, value_type __c); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1762 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 1763 | // Slow path for the (inlined) copy constructor for 'long' strings. |
| 1764 | // Always externally instantiated and not inlined. |
| 1765 | // Requires that __s is zero terminated. |
| 1766 | // The main reason for this function to exist is because for unstable, we |
| 1767 | // want to allow inlining of the copy constructor. However, we don't want |
| 1768 | // to call the __init() functions as those are marked as inline which may |
| 1769 | // result in over-aggressive inlining by the compiler, where our aim is |
| 1770 | // to only inline the fast path code directly in the ctor. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1771 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void __init_copy_ctor_external(const value_type* __s, size_type __sz); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 1772 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1773 | template <class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1774 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1775 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1776 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1777 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 1778 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1779 | __init(_InputIterator __first, _InputIterator __last); |
| 1780 | |
| 1781 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1782 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1783 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1784 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1785 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 1786 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1787 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 1788 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1789 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1790 | void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1791 | size_type __n_copy, size_type __n_del, size_type __n_add = 0); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1792 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1793 | void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 1794 | size_type __n_copy, size_type __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1795 | size_type __n_add, const value_type* __p_new_stuff); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1796 | |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 1797 | // __assign_no_alias is invoked for assignment operations where we |
| 1798 | // have proof that the input does not alias the current instance. |
| 1799 | // For example, operator=(basic_string) performs a 'self' check. |
| 1800 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1801 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_no_alias(const value_type* __s, size_type __n); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 1802 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1803 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1804 | void __erase_to_end(size_type __pos); |
| 1805 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 1806 | // __erase_external_with_move is invoked for erase() invocations where |
| 1807 | // `n ~= npos`, likely requiring memory moves on the string data. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1808 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void __erase_external_with_move(size_type __pos, size_type __n); |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 1809 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1810 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1811 | void __copy_assign_alloc(const basic_string& __str) |
| 1812 | {__copy_assign_alloc(__str, integral_constant<bool, |
| 1813 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 1814 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1815 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1816 | void __copy_assign_alloc(const basic_string& __str, true_type) |
| 1817 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1818 | if (__alloc() == __str.__alloc()) |
| 1819 | __alloc() = __str.__alloc(); |
| 1820 | else |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1821 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1822 | if (!__str.__is_long()) |
| 1823 | { |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 1824 | __clear_and_shrink(); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1825 | __alloc() = __str.__alloc(); |
| 1826 | } |
| 1827 | else |
| 1828 | { |
| 1829 | allocator_type __a = __str.__alloc(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1830 | auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap()); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1831 | __begin_lifetime(__allocation.ptr, __allocation.count); |
Nikolas Klauser | 1821ec3 | 2022-10-01 15:37:24 +0200 | [diff] [blame] | 1832 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1833 | __alloc() = std::move(__a); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1834 | __set_long_pointer(__allocation.ptr); |
| 1835 | __set_long_cap(__allocation.count); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1836 | __set_long_size(__str.size()); |
| 1837 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1838 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1839 | } |
| 1840 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1841 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1842 | void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1843 | {} |
| 1844 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1845 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1846 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1847 | void __move_assign(basic_string& __str, false_type) |
| 1848 | _NOEXCEPT_(__alloc_traits::is_always_equal::value); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1849 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1850 | void __move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1851 | #if _LIBCPP_STD_VER > 14 |
| 1852 | _NOEXCEPT; |
| 1853 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1854 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1855 | #endif |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1856 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1857 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1858 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1859 | void |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1860 | __move_assign_alloc(basic_string& __str) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1861 | _NOEXCEPT_( |
| 1862 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 1863 | is_nothrow_move_assignable<allocator_type>::value) |
| 1864 | {__move_assign_alloc(__str, integral_constant<bool, |
| 1865 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 1866 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1867 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1868 | void __move_assign_alloc(basic_string& __c, true_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1869 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
| 1870 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1871 | __alloc() = std::move(__c.__alloc()); |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1874 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1875 | void __move_assign_alloc(basic_string&, false_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1876 | _NOEXCEPT |
| 1877 | {} |
| 1878 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1879 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s); |
| 1880 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s, size_type __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 1881 | |
| 1882 | // Assigns the value in __s, guaranteed to be __n < __min_cap in length. |
| 1883 | inline basic_string& __assign_short(const value_type* __s, size_type __n) { |
| 1884 | pointer __p = __is_long() |
| 1885 | ? (__set_long_size(__n), __get_long_pointer()) |
| 1886 | : (__set_short_size(__n), __get_short_pointer()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1887 | traits_type::move(std::__to_address(__p), __s, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 1888 | traits_type::assign(__p[__n], value_type()); |
| 1889 | return *this; |
| 1890 | } |
| 1891 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1892 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1893 | basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 1894 | __set_size(__newsz); |
| 1895 | __invalidate_iterators_past(__newsz); |
| 1896 | traits_type::assign(__p[__newsz], value_type()); |
| 1897 | return *this; |
| 1898 | } |
| 1899 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1900 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __invalidate_iterators_past(size_type); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1901 | |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1902 | template<class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1903 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1904 | bool __addr_in_range(_Tp&& __t) const { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1905 | // assume that the ranges overlap, because we can't check during constant evaluation |
| 1906 | if (__libcpp_is_constant_evaluated()) |
| 1907 | return true; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1908 | const volatile void *__p = std::addressof(__t); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1909 | return data() <= __p && __p <= data() + size(); |
| 1910 | } |
| 1911 | |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1912 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1913 | void __throw_length_error() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1914 | std::__throw_length_error("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1915 | } |
| 1916 | |
| 1917 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1918 | void __throw_out_of_range() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1919 | std::__throw_out_of_range("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1920 | } |
| 1921 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1922 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const basic_string&); |
| 1923 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const value_type*, const basic_string&); |
| 1924 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(value_type, const basic_string&); |
| 1925 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const value_type*); |
| 1926 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, value_type); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1927 | }; |
| 1928 | |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1929 | // These declarations must appear before any functions are implicitly used |
| 1930 | // so that they have the correct visibility specifier. |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1931 | #define _LIBCPP_DECLARE(...) extern template __VA_ARGS__; |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1932 | #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1933 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1934 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1935 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1936 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1937 | #else |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1938 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1939 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1940 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1941 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1942 | #endif |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1943 | #undef _LIBCPP_DECLARE |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1944 | |
| 1945 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 1946 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1947 | template<class _InputIterator, |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 1948 | class _CharT = __iter_value_type<_InputIterator>, |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1949 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1950 | class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
| 1951 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1952 | > |
| 1953 | basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 1954 | -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1955 | |
| 1956 | template<class _CharT, |
| 1957 | class _Traits, |
| 1958 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1959 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1960 | > |
| 1961 | explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) |
| 1962 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 1963 | |
| 1964 | template<class _CharT, |
| 1965 | class _Traits, |
| 1966 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1967 | class = enable_if_t<__is_allocator<_Allocator>::value>, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1968 | class _Sz = typename allocator_traits<_Allocator>::size_type |
| 1969 | > |
| 1970 | basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) |
| 1971 | -> basic_string<_CharT, _Traits, _Allocator>; |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1972 | #endif |
| 1973 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1974 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1975 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1976 | void |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1977 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1978 | { |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1979 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1980 | if (!__libcpp_is_constant_evaluated()) { |
| 1981 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1982 | if (__c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1983 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1984 | const_pointer __new_last = __get_pointer() + __pos; |
| 1985 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1986 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1987 | --__p; |
| 1988 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 1989 | if (__i->base() > __new_last) |
| 1990 | { |
| 1991 | (*__p)->__c_ = nullptr; |
| 1992 | if (--__c->end_ != __p) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1993 | std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1994 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1995 | } |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1996 | __get_db()->unlock(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | } |
| 1998 | } |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1999 | #else |
| 2000 | (void)__pos; |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 2001 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2005 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 2006 | void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, |
| 2007 | size_type __sz, |
| 2008 | size_type __reserve) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2009 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2010 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2011 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2012 | if (__reserve > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2013 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2014 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2015 | if (__fits_in_sso(__reserve)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2016 | { |
| 2017 | __set_short_size(__sz); |
| 2018 | __p = __get_short_pointer(); |
| 2019 | } |
| 2020 | else |
| 2021 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2022 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1); |
| 2023 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2024 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2025 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2026 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2027 | __set_long_size(__sz); |
| 2028 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2029 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2030 | traits_type::assign(__p[__sz], value_type()); |
| 2031 | } |
| 2032 | |
| 2033 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2034 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2035 | void |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2036 | basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2037 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2038 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2039 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2040 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2041 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2042 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2043 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2044 | { |
| 2045 | __set_short_size(__sz); |
| 2046 | __p = __get_short_pointer(); |
| 2047 | } |
| 2048 | else |
| 2049 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2050 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2051 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2052 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2053 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2054 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2055 | __set_long_size(__sz); |
| 2056 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2057 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2058 | traits_type::assign(__p[__sz], value_type()); |
| 2059 | } |
| 2060 | |
| 2061 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2062 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2063 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2064 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2065 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2066 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2067 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2068 | __init(__s, traits_type::length(__s)); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2069 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2073 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2074 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2075 | : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | { |
| 2077 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2078 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2079 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2080 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2081 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2082 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2086 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2087 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
| 2088 | const basic_string& __str, const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2089 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2090 | { |
| 2091 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2092 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2093 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2094 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2095 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2096 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2097 | } |
| 2098 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2099 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2100 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2101 | void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( |
| 2102 | const value_type* __s, size_type __sz) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2103 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2104 | __r_.first() = __rep(); |
| 2105 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2106 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2107 | if (__fits_in_sso(__sz)) { |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2108 | __p = __get_short_pointer(); |
| 2109 | __set_short_size(__sz); |
| 2110 | } else { |
| 2111 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2112 | __throw_length_error(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2113 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2114 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2115 | __begin_lifetime(__p, __allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2116 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2117 | __set_long_cap(__allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2118 | __set_long_size(__sz); |
| 2119 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2120 | traits_type::copy(std::__to_address(__p), __s, __sz + 1); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2121 | } |
| 2122 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2123 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2124 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2125 | void |
| 2126 | basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) |
| 2127 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2128 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2129 | __r_.first() = __rep(); |
| 2130 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2131 | if (__n > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2132 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2133 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2134 | if (__fits_in_sso(__n)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2135 | { |
| 2136 | __set_short_size(__n); |
| 2137 | __p = __get_short_pointer(); |
| 2138 | } |
| 2139 | else |
| 2140 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2141 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1); |
| 2142 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2143 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2144 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2145 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2146 | __set_long_size(__n); |
| 2147 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2148 | traits_type::assign(std::__to_address(__p), __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2149 | traits_type::assign(__p[__n], value_type()); |
| 2150 | } |
| 2151 | |
| 2152 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2153 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2154 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2155 | basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2156 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2157 | { |
| 2158 | __init(__n, __c); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2159 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2160 | } |
| 2161 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2162 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2163 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2164 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, |
| 2165 | size_type __pos, size_type __n, |
| 2166 | const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2167 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2168 | { |
| 2169 | size_type __str_sz = __str.size(); |
| 2170 | if (__pos > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2171 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2172 | __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); |
| 2173 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2177 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2178 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2179 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2180 | const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2181 | : __r_(__default_init_tag(), __a) |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2182 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2183 | __self_view __sv0 = __t; |
| 2184 | __self_view __sv = __sv0.substr(__pos, __n); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2185 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2186 | std::__debug_db_insert_c(this); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2190 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2191 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2192 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2193 | : __r_(__default_init_tag(), __default_init_tag()) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2194 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2195 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2196 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2197 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2201 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2202 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2203 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2204 | : __r_(__default_init_tag(), __a) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2205 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2206 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2207 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2208 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2212 | template <class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2213 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2214 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2215 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2216 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 2217 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2218 | basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) |
| 2219 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2220 | __default_init(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2221 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2222 | try |
| 2223 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2224 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2225 | for (; __first != __last; ++__first) |
| 2226 | push_back(*__first); |
| 2227 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2228 | } |
| 2229 | catch (...) |
| 2230 | { |
| 2231 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2232 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2233 | throw; |
| 2234 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2235 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | template <class _CharT, class _Traits, class _Allocator> |
| 2239 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2240 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2241 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2242 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2243 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 2244 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2245 | basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 2246 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2247 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2248 | __r_.first() = __rep(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2249 | size_type __sz = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2250 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2251 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2252 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2253 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2254 | { |
| 2255 | __set_short_size(__sz); |
| 2256 | __p = __get_short_pointer(); |
| 2257 | } |
| 2258 | else |
| 2259 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2260 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2261 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2262 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2263 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2264 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2265 | __set_long_size(__sz); |
| 2266 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2267 | |
| 2268 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2269 | try |
| 2270 | { |
| 2271 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | a09a3b4 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 2272 | for (; __first != __last; ++__first, (void) ++__p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2273 | traits_type::assign(*__p, *__first); |
| 2274 | traits_type::assign(*__p, value_type()); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2275 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2276 | } |
| 2277 | catch (...) |
| 2278 | { |
| 2279 | if (__is_long()) |
| 2280 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
| 2281 | throw; |
| 2282 | } |
| 2283 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2287 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2288 | basic_string<_CharT, _Traits, _Allocator>::~basic_string() |
| 2289 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 2290 | std::__debug_db_erase_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2291 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2292 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
| 2295 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2296 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2297 | void |
| 2298 | basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace |
| 2299 | (size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2300 | size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2301 | { |
| 2302 | size_type __ms = max_size(); |
| 2303 | if (__delta_cap > __ms - __old_cap - 1) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2304 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2305 | pointer __old_p = __get_pointer(); |
| 2306 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2307 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2308 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2309 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2310 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2311 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2312 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2313 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2314 | traits_type::copy(std::__to_address(__p), |
| 2315 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2316 | if (__n_add != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2317 | traits_type::copy(std::__to_address(__p) + __n_copy, __p_new_stuff, __n_add); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2318 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2319 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2320 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2321 | std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2322 | if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2323 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2324 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2325 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2326 | __old_sz = __n_copy + __n_add + __sec_cp_sz; |
| 2327 | __set_long_size(__old_sz); |
| 2328 | traits_type::assign(__p[__old_sz], value_type()); |
| 2329 | } |
| 2330 | |
| 2331 | template <class _CharT, class _Traits, class _Allocator> |
| 2332 | void |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2333 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2334 | basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 2335 | size_type __n_copy, size_type __n_del, size_type __n_add) |
| 2336 | { |
| 2337 | size_type __ms = max_size(); |
Marshall Clow | 2267c5d | 2013-11-06 14:24:38 +0000 | [diff] [blame] | 2338 | if (__delta_cap > __ms - __old_cap) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2339 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2340 | pointer __old_p = __get_pointer(); |
| 2341 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2342 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2344 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2345 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2346 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2347 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2348 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2349 | traits_type::copy(std::__to_address(__p), |
| 2350 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2351 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2352 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2353 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2354 | std::__to_address(__old_p) + __n_copy + __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2355 | __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2356 | if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap) |
| 2357 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2358 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2359 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | // assign |
| 2363 | |
| 2364 | template <class _CharT, class _Traits, class _Allocator> |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2365 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2366 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2367 | basic_string<_CharT, _Traits, _Allocator>& |
| 2368 | basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias( |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2369 | const value_type* __s, size_type __n) { |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2370 | size_type __cap = __is_short ? static_cast<size_type>(__min_cap) : __get_long_cap(); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2371 | if (__n < __cap) { |
| 2372 | pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer(); |
| 2373 | __is_short ? __set_short_size(__n) : __set_long_size(__n); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2374 | traits_type::copy(std::__to_address(__p), __s, __n); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2375 | traits_type::assign(__p[__n], value_type()); |
| 2376 | __invalidate_iterators_past(__n); |
| 2377 | } else { |
| 2378 | size_type __sz = __is_short ? __get_short_size() : __get_long_size(); |
| 2379 | __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s); |
| 2380 | } |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2381 | return *this; |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2385 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2386 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2387 | basic_string<_CharT, _Traits, _Allocator>::__assign_external( |
| 2388 | const value_type* __s, size_type __n) { |
| 2389 | size_type __cap = capacity(); |
| 2390 | if (__cap >= __n) { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2391 | value_type* __p = std::__to_address(__get_pointer()); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2392 | traits_type::move(__p, __s, __n); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2393 | return __null_terminate_at(__p, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2394 | } else { |
| 2395 | size_type __sz = size(); |
| 2396 | __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2397 | return *this; |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2398 | } |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2402 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2403 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2404 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2405 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2406 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2407 | return (__builtin_constant_p(__n) && __fits_in_sso(__n)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2408 | ? __assign_short(__s, __n) |
| 2409 | : __assign_external(__s, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2413 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2414 | basic_string<_CharT, _Traits, _Allocator>& |
| 2415 | basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) |
| 2416 | { |
| 2417 | size_type __cap = capacity(); |
| 2418 | if (__cap < __n) |
| 2419 | { |
| 2420 | size_type __sz = size(); |
| 2421 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2422 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2423 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2424 | traits_type::assign(__p, __n, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2425 | return __null_terminate_at(__p, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2426 | } |
| 2427 | |
| 2428 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2429 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2430 | basic_string<_CharT, _Traits, _Allocator>& |
| 2431 | basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) |
| 2432 | { |
| 2433 | pointer __p; |
| 2434 | if (__is_long()) |
| 2435 | { |
| 2436 | __p = __get_long_pointer(); |
| 2437 | __set_long_size(1); |
| 2438 | } |
| 2439 | else |
| 2440 | { |
| 2441 | __p = __get_short_pointer(); |
| 2442 | __set_short_size(1); |
| 2443 | } |
| 2444 | traits_type::assign(*__p, __c); |
| 2445 | traits_type::assign(*++__p, value_type()); |
| 2446 | __invalidate_iterators_past(1); |
| 2447 | return *this; |
| 2448 | } |
| 2449 | |
| 2450 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2451 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2452 | basic_string<_CharT, _Traits, _Allocator>& |
| 2453 | basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) |
| 2454 | { |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2455 | if (this != &__str) { |
| 2456 | __copy_assign_alloc(__str); |
| 2457 | if (!__is_long()) { |
| 2458 | if (!__str.__is_long()) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2459 | __r_.first() = __str.__r_.first(); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2460 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2461 | return __assign_no_alias<true>(__str.data(), __str.size()); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2462 | } |
| 2463 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2464 | return __assign_no_alias<false>(__str.data(), __str.size()); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2465 | } |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2466 | } |
| 2467 | return *this; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2468 | } |
| 2469 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 2470 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2471 | |
| 2472 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2473 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2474 | void |
| 2475 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2476 | _NOEXCEPT_(__alloc_traits::is_always_equal::value) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2477 | { |
| 2478 | if (__alloc() != __str.__alloc()) |
| 2479 | assign(__str); |
| 2480 | else |
| 2481 | __move_assign(__str, true_type()); |
| 2482 | } |
| 2483 | |
| 2484 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2485 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2486 | void |
| 2487 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2488 | #if _LIBCPP_STD_VER > 14 |
| 2489 | _NOEXCEPT |
| 2490 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2491 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2492 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2493 | { |
marshall | 2ed4162 | 2019-11-27 07:13:00 -0800 | [diff] [blame] | 2494 | if (__is_long()) { |
| 2495 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), |
| 2496 | __get_long_cap()); |
| 2497 | #if _LIBCPP_STD_VER <= 14 |
| 2498 | if (!is_nothrow_move_assignable<allocator_type>::value) { |
| 2499 | __set_short_size(0); |
| 2500 | traits_type::assign(__get_short_pointer()[0], value_type()); |
| 2501 | } |
| 2502 | #endif |
| 2503 | } |
| 2504 | __move_assign_alloc(__str); |
| 2505 | __r_.first() = __str.__r_.first(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2506 | if (__libcpp_is_constant_evaluated()) { |
| 2507 | __str.__default_init(); |
| 2508 | } else { |
| 2509 | __str.__set_short_size(0); |
| 2510 | traits_type::assign(__str.__get_short_pointer()[0], value_type()); |
| 2511 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2515 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2516 | basic_string<_CharT, _Traits, _Allocator>& |
| 2517 | basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2518 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2519 | { |
| 2520 | __move_assign(__str, integral_constant<bool, |
| 2521 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 2522 | return *this; |
| 2523 | } |
| 2524 | |
| 2525 | #endif |
| 2526 | |
| 2527 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2528 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2529 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2530 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2531 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2532 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2533 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2534 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2535 | basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2536 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2537 | const basic_string __temp(__first, __last, __alloc()); |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2538 | assign(__temp.data(), __temp.size()); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2539 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | template <class _CharT, class _Traits, class _Allocator> |
| 2543 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2544 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2545 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2546 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2547 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2548 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2549 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2550 | basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2551 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2552 | size_type __cap = capacity(); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2553 | size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2554 | static_cast<size_type>(std::distance(__first, __last)) : 0; |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2555 | |
| 2556 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2557 | (__cap >= __n || !__addr_in_range(*__first))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2558 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2559 | if (__cap < __n) |
| 2560 | { |
| 2561 | size_type __sz = size(); |
| 2562 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2563 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2564 | pointer __p = __get_pointer(); |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2565 | for (; __first != __last; ++__p, (void) ++__first) |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2566 | traits_type::assign(*__p, *__first); |
| 2567 | traits_type::assign(*__p, value_type()); |
| 2568 | __set_size(__n); |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 2569 | __invalidate_iterators_past(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2570 | } |
| 2571 | else |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2572 | { |
| 2573 | const basic_string __temp(__first, __last, __alloc()); |
| 2574 | assign(__temp.data(), __temp.size()); |
| 2575 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2576 | return *this; |
| 2577 | } |
| 2578 | |
| 2579 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2580 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2581 | basic_string<_CharT, _Traits, _Allocator>& |
| 2582 | basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) |
| 2583 | { |
| 2584 | size_type __sz = __str.size(); |
| 2585 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2586 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2587 | return assign(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2588 | } |
| 2589 | |
| 2590 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2591 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2592 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2593 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2594 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2595 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 2596 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 2597 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2598 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2599 | basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2600 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2601 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2602 | size_type __sz = __sv.size(); |
| 2603 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2604 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2605 | return assign(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | |
| 2609 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2610 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2611 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2612 | basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) { |
| 2613 | return __assign_external(__s, traits_type::length(__s)); |
| 2614 | } |
| 2615 | |
| 2616 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2617 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2618 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2619 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2620 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2621 | _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); |
Louis Dionne | 3e0c433 | 2021-08-31 10:49:06 -0400 | [diff] [blame] | 2622 | return __builtin_constant_p(*__s) |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2623 | ? (__fits_in_sso(traits_type::length(__s)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2624 | ? __assign_short(__s, traits_type::length(__s)) |
| 2625 | : __assign_external(__s, traits_type::length(__s))) |
| 2626 | : __assign_external(__s); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2627 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2628 | // append |
| 2629 | |
| 2630 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2631 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2632 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2633 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2634 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2635 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2636 | size_type __cap = capacity(); |
| 2637 | size_type __sz = size(); |
| 2638 | if (__cap - __sz >= __n) |
| 2639 | { |
| 2640 | if (__n) |
| 2641 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2642 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2643 | traits_type::copy(__p + __sz, __s, __n); |
| 2644 | __sz += __n; |
| 2645 | __set_size(__sz); |
| 2646 | traits_type::assign(__p[__sz], value_type()); |
| 2647 | } |
| 2648 | } |
| 2649 | else |
| 2650 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); |
| 2651 | return *this; |
| 2652 | } |
| 2653 | |
| 2654 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2655 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2656 | basic_string<_CharT, _Traits, _Allocator>& |
| 2657 | basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) |
| 2658 | { |
| 2659 | if (__n) |
| 2660 | { |
| 2661 | size_type __cap = capacity(); |
| 2662 | size_type __sz = size(); |
| 2663 | if (__cap - __sz < __n) |
| 2664 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2665 | pointer __p = __get_pointer(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2666 | traits_type::assign(std::__to_address(__p) + __sz, __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2667 | __sz += __n; |
| 2668 | __set_size(__sz); |
| 2669 | traits_type::assign(__p[__sz], value_type()); |
| 2670 | } |
| 2671 | return *this; |
| 2672 | } |
| 2673 | |
| 2674 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2675 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 2676 | basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) |
| 2677 | { |
| 2678 | if (__n) |
| 2679 | { |
| 2680 | size_type __cap = capacity(); |
| 2681 | size_type __sz = size(); |
| 2682 | if (__cap - __sz < __n) |
| 2683 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2684 | pointer __p = __get_pointer(); |
| 2685 | __sz += __n; |
| 2686 | __set_size(__sz); |
| 2687 | traits_type::assign(__p[__sz], value_type()); |
| 2688 | } |
| 2689 | } |
| 2690 | |
| 2691 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2692 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2693 | void |
| 2694 | basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) |
| 2695 | { |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2696 | bool __is_short = !__is_long(); |
| 2697 | size_type __cap; |
| 2698 | size_type __sz; |
| 2699 | if (__is_short) |
| 2700 | { |
| 2701 | __cap = __min_cap - 1; |
| 2702 | __sz = __get_short_size(); |
| 2703 | } |
| 2704 | else |
| 2705 | { |
| 2706 | __cap = __get_long_cap() - 1; |
| 2707 | __sz = __get_long_size(); |
| 2708 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2709 | if (__sz == __cap) |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2710 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2711 | __grow_by(__cap, 1, __sz, __sz, 0); |
Louis Dionne | 82d2b2c | 2021-11-16 11:26:56 -0500 | [diff] [blame] | 2712 | __is_short = false; // the string is always long after __grow_by |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2713 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2714 | pointer __p = __get_pointer(); |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2715 | if (__is_short) |
| 2716 | { |
| 2717 | __p = __get_short_pointer() + __sz; |
| 2718 | __set_short_size(__sz+1); |
| 2719 | } |
| 2720 | else |
| 2721 | { |
| 2722 | __p = __get_long_pointer() + __sz; |
| 2723 | __set_long_size(__sz+1); |
| 2724 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2725 | traits_type::assign(*__p, __c); |
| 2726 | traits_type::assign(*++__p, value_type()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2729 | template <class _CharT, class _Traits, class _Allocator> |
| 2730 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2731 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2732 | __enable_if_t |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2733 | < |
| 2734 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
| 2735 | basic_string<_CharT, _Traits, _Allocator>& |
| 2736 | > |
| 2737 | basic_string<_CharT, _Traits, _Allocator>::append( |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 2738 | _ForwardIterator __first, _ForwardIterator __last) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2739 | { |
| 2740 | size_type __sz = size(); |
| 2741 | size_type __cap = capacity(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2742 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2743 | if (__n) |
| 2744 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2745 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2746 | !__addr_in_range(*__first)) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2747 | { |
| 2748 | if (__cap - __sz < __n) |
| 2749 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2750 | pointer __p = __get_pointer() + __sz; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2751 | for (; __first != __last; ++__p, (void) ++__first) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2752 | traits_type::assign(*__p, *__first); |
| 2753 | traits_type::assign(*__p, value_type()); |
| 2754 | __set_size(__sz + __n); |
| 2755 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2756 | else |
| 2757 | { |
| 2758 | const basic_string __temp(__first, __last, __alloc()); |
| 2759 | append(__temp.data(), __temp.size()); |
| 2760 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2761 | } |
| 2762 | return *this; |
| 2763 | } |
| 2764 | |
| 2765 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2766 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2767 | basic_string<_CharT, _Traits, _Allocator>& |
| 2768 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) |
| 2769 | { |
| 2770 | return append(__str.data(), __str.size()); |
| 2771 | } |
| 2772 | |
| 2773 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2774 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2775 | basic_string<_CharT, _Traits, _Allocator>& |
| 2776 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) |
| 2777 | { |
| 2778 | size_type __sz = __str.size(); |
| 2779 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2780 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2781 | return append(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 2785 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2786 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2787 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2788 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2789 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2790 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2791 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2792 | basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2793 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2794 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2795 | size_type __sz = __sv.size(); |
| 2796 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2797 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2798 | return append(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2802 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2803 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2804 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2805 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2806 | _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2807 | return append(__s, traits_type::length(__s)); |
| 2808 | } |
| 2809 | |
| 2810 | // insert |
| 2811 | |
| 2812 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2813 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2814 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2815 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2816 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2817 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2818 | size_type __sz = size(); |
| 2819 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2820 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2821 | size_type __cap = capacity(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2822 | if (__libcpp_is_constant_evaluated()) { |
| 2823 | if (__cap - __sz >= __n) |
| 2824 | __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s); |
| 2825 | else |
| 2826 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2827 | return *this; |
| 2828 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2829 | if (__cap - __sz >= __n) |
| 2830 | { |
| 2831 | if (__n) |
| 2832 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2833 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2834 | size_type __n_move = __sz - __pos; |
| 2835 | if (__n_move != 0) |
| 2836 | { |
| 2837 | if (__p + __pos <= __s && __s < __p + __sz) |
| 2838 | __s += __n; |
| 2839 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2840 | } |
| 2841 | traits_type::move(__p + __pos, __s, __n); |
| 2842 | __sz += __n; |
| 2843 | __set_size(__sz); |
| 2844 | traits_type::assign(__p[__sz], value_type()); |
| 2845 | } |
| 2846 | } |
| 2847 | else |
| 2848 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2849 | return *this; |
| 2850 | } |
| 2851 | |
| 2852 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2853 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2854 | basic_string<_CharT, _Traits, _Allocator>& |
| 2855 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) |
| 2856 | { |
| 2857 | size_type __sz = size(); |
| 2858 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2859 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2860 | if (__n) |
| 2861 | { |
| 2862 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2863 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2864 | if (__cap - __sz >= __n) |
| 2865 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2866 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2867 | size_type __n_move = __sz - __pos; |
| 2868 | if (__n_move != 0) |
| 2869 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2870 | } |
| 2871 | else |
| 2872 | { |
| 2873 | __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2874 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2875 | } |
| 2876 | traits_type::assign(__p + __pos, __n, __c); |
| 2877 | __sz += __n; |
| 2878 | __set_size(__sz); |
| 2879 | traits_type::assign(__p[__sz], value_type()); |
| 2880 | } |
| 2881 | return *this; |
| 2882 | } |
| 2883 | |
| 2884 | template <class _CharT, class _Traits, class _Allocator> |
| 2885 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2886 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2887 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2888 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2889 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2890 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2891 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2892 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) |
| 2893 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2894 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2895 | "string::insert(iterator, range) called with an iterator not" |
| 2896 | " referring to this string"); |
| 2897 | const basic_string __temp(__first, __last, __alloc()); |
| 2898 | return insert(__pos, __temp.data(), __temp.data() + __temp.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | template <class _CharT, class _Traits, class _Allocator> |
| 2902 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2903 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2904 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2905 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2906 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2907 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2908 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2909 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) |
| 2910 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2911 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2912 | "string::insert(iterator, range) called with an iterator not referring to this string"); |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2913 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2914 | size_type __ip = static_cast<size_type>(__pos - begin()); |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2915 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
| 2916 | if (__n == 0) |
| 2917 | return begin() + __ip; |
| 2918 | |
| 2919 | if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2920 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2921 | return __insert_from_safe_copy(__n, __ip, __first, __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2922 | } |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2923 | else |
| 2924 | { |
| 2925 | const basic_string __temp(__first, __last, __alloc()); |
| 2926 | return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end()); |
| 2927 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2931 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2932 | basic_string<_CharT, _Traits, _Allocator>& |
| 2933 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) |
| 2934 | { |
| 2935 | return insert(__pos1, __str.data(), __str.size()); |
| 2936 | } |
| 2937 | |
| 2938 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2939 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2940 | basic_string<_CharT, _Traits, _Allocator>& |
| 2941 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, |
| 2942 | size_type __pos2, size_type __n) |
| 2943 | { |
| 2944 | size_type __str_sz = __str.size(); |
| 2945 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2946 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2947 | return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2951 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2952 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2953 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2954 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2955 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 2956 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2957 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2958 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2959 | size_type __pos2, size_type __n) |
| 2960 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2961 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2962 | size_type __str_sz = __sv.size(); |
| 2963 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2964 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2965 | return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2969 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2970 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2971 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2972 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2973 | _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2974 | return insert(__pos, __s, traits_type::length(__s)); |
| 2975 | } |
| 2976 | |
| 2977 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2978 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2979 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2980 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) |
| 2981 | { |
Louis Dionne | f4cc6fb | 2022-02-15 15:47:45 -0500 | [diff] [blame] | 2982 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2983 | "string::insert(iterator, character) called with an iterator not" |
| 2984 | " referring to this string"); |
| 2985 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2986 | size_type __ip = static_cast<size_type>(__pos - begin()); |
| 2987 | size_type __sz = size(); |
| 2988 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2989 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2990 | if (__cap == __sz) |
| 2991 | { |
| 2992 | __grow_by(__cap, 1, __sz, __ip, 0, 1); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2993 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2994 | } |
| 2995 | else |
| 2996 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2997 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2998 | size_type __n_move = __sz - __ip; |
| 2999 | if (__n_move != 0) |
| 3000 | traits_type::move(__p + __ip + 1, __p + __ip, __n_move); |
| 3001 | } |
| 3002 | traits_type::assign(__p[__ip], __c); |
| 3003 | traits_type::assign(__p[++__sz], value_type()); |
| 3004 | __set_size(__sz); |
| 3005 | return begin() + static_cast<difference_type>(__ip); |
| 3006 | } |
| 3007 | |
| 3008 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3009 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3010 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3011 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) |
| 3012 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3013 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3014 | "string::insert(iterator, n, value) called with an iterator not" |
| 3015 | " referring to this string"); |
| 3016 | difference_type __p = __pos - begin(); |
| 3017 | insert(static_cast<size_type>(__p), __n, __c); |
| 3018 | return begin() + __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | // replace |
| 3022 | |
| 3023 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3024 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3025 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3026 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2) |
Eric Fiselier | e5b2184 | 2017-03-09 01:54:13 +0000 | [diff] [blame] | 3027 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3028 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3029 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3030 | size_type __sz = size(); |
| 3031 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3032 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3033 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3034 | size_type __cap = capacity(); |
| 3035 | if (__cap - __sz + __n1 >= __n2) |
| 3036 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3037 | if (__libcpp_is_constant_evaluated()) { |
| 3038 | __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s); |
| 3039 | return *this; |
| 3040 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3041 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3042 | if (__n1 != __n2) |
| 3043 | { |
| 3044 | size_type __n_move = __sz - __pos - __n1; |
| 3045 | if (__n_move != 0) |
| 3046 | { |
| 3047 | if (__n1 > __n2) |
| 3048 | { |
| 3049 | traits_type::move(__p + __pos, __s, __n2); |
| 3050 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3051 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3052 | } |
| 3053 | if (__p + __pos < __s && __s < __p + __sz) |
| 3054 | { |
| 3055 | if (__p + __pos + __n1 <= __s) |
| 3056 | __s += __n2 - __n1; |
| 3057 | else // __p + __pos < __s < __p + __pos + __n1 |
| 3058 | { |
| 3059 | traits_type::move(__p + __pos, __s, __n1); |
| 3060 | __pos += __n1; |
| 3061 | __s += __n2; |
| 3062 | __n2 -= __n1; |
| 3063 | __n1 = 0; |
| 3064 | } |
| 3065 | } |
| 3066 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3067 | } |
| 3068 | } |
| 3069 | traits_type::move(__p + __pos, __s, __n2); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3070 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3071 | } |
| 3072 | else |
| 3073 | __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); |
| 3074 | return *this; |
| 3075 | } |
| 3076 | |
| 3077 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3078 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3079 | basic_string<_CharT, _Traits, _Allocator>& |
| 3080 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) |
| 3081 | { |
| 3082 | size_type __sz = size(); |
| 3083 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3084 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3085 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3086 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3087 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3088 | if (__cap - __sz + __n1 >= __n2) |
| 3089 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3090 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3091 | if (__n1 != __n2) |
| 3092 | { |
| 3093 | size_type __n_move = __sz - __pos - __n1; |
| 3094 | if (__n_move != 0) |
| 3095 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3096 | } |
| 3097 | } |
| 3098 | else |
| 3099 | { |
| 3100 | __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3101 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3102 | } |
| 3103 | traits_type::assign(__p + __pos, __n2, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3104 | return __null_terminate_at(__p, __sz - (__n1 - __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | template <class _CharT, class _Traits, class _Allocator> |
| 3108 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3109 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3110 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3111 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3112 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3113 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3114 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3115 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3116 | _InputIterator __j1, _InputIterator __j2) |
| 3117 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 3118 | const basic_string __temp(__j1, __j2, __alloc()); |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3119 | return replace(__i1, __i2, __temp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
| 3122 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3123 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3124 | basic_string<_CharT, _Traits, _Allocator>& |
| 3125 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) |
| 3126 | { |
| 3127 | return replace(__pos1, __n1, __str.data(), __str.size()); |
| 3128 | } |
| 3129 | |
| 3130 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3131 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3132 | basic_string<_CharT, _Traits, _Allocator>& |
| 3133 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 3134 | size_type __pos2, size_type __n2) |
| 3135 | { |
| 3136 | size_type __str_sz = __str.size(); |
| 3137 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3138 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3139 | return replace(__pos1, __n1, __str.data() + __pos2, std::min(__n2, __str_sz - __pos2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3143 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3144 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3145 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3146 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3147 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 3148 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3149 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3150 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3151 | size_type __pos2, size_type __n2) |
| 3152 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3153 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3154 | size_type __str_sz = __sv.size(); |
| 3155 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3156 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3157 | return replace(__pos1, __n1, __sv.data() + __pos2, std::min(__n2, __str_sz - __pos2)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3161 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3162 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3163 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3164 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3165 | _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3166 | return replace(__pos, __n1, __s, traits_type::length(__s)); |
| 3167 | } |
| 3168 | |
| 3169 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3170 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3171 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3172 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3173 | { |
| 3174 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), |
| 3175 | __str.data(), __str.size()); |
| 3176 | } |
| 3177 | |
| 3178 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3179 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3180 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3181 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3182 | { |
| 3183 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); |
| 3184 | } |
| 3185 | |
| 3186 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3187 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3188 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3189 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3190 | { |
| 3191 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); |
| 3192 | } |
| 3193 | |
| 3194 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3195 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3196 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3197 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3198 | { |
| 3199 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); |
| 3200 | } |
| 3201 | |
| 3202 | // erase |
| 3203 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3204 | // 'externally instantiated' erase() implementation, called when __n != npos. |
| 3205 | // Does not check __pos against size() |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3206 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3207 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3208 | void |
| 3209 | basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( |
| 3210 | size_type __pos, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3211 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3212 | if (__n) |
| 3213 | { |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3214 | size_type __sz = size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3215 | value_type* __p = std::__to_address(__get_pointer()); |
| 3216 | __n = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3217 | size_type __n_move = __sz - __pos - __n; |
| 3218 | if (__n_move != 0) |
| 3219 | traits_type::move(__p + __pos, __p + __pos + __n, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3220 | __null_terminate_at(__p, __sz - __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3221 | } |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3222 | } |
| 3223 | |
| 3224 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3225 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3226 | basic_string<_CharT, _Traits, _Allocator>& |
| 3227 | basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, |
| 3228 | size_type __n) { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3229 | if (__pos > size()) |
| 3230 | __throw_out_of_range(); |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3231 | if (__n == npos) { |
| 3232 | __erase_to_end(__pos); |
| 3233 | } else { |
| 3234 | __erase_external_with_move(__pos, __n); |
| 3235 | } |
| 3236 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3240 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3241 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3242 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) |
| 3243 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3244 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3245 | "string::erase(iterator) called with an iterator not" |
| 3246 | " referring to this string"); |
| 3247 | |
| 3248 | _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); |
| 3249 | iterator __b = begin(); |
| 3250 | size_type __r = static_cast<size_type>(__pos - __b); |
| 3251 | erase(__r, 1); |
| 3252 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3253 | } |
| 3254 | |
| 3255 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3256 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3257 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3258 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 3259 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3260 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 3261 | "string::erase(iterator, iterator) called with an iterator not" |
| 3262 | " referring to this string"); |
| 3263 | |
| 3264 | _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); |
| 3265 | iterator __b = begin(); |
| 3266 | size_type __r = static_cast<size_type>(__first - __b); |
| 3267 | erase(__r, static_cast<size_type>(__last - __first)); |
| 3268 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3272 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3273 | void |
| 3274 | basic_string<_CharT, _Traits, _Allocator>::pop_back() |
| 3275 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3276 | _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3277 | __erase_to_end(size() - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3281 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3282 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3283 | basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3284 | { |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3285 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3286 | if (__is_long()) |
| 3287 | { |
| 3288 | traits_type::assign(*__get_long_pointer(), value_type()); |
| 3289 | __set_long_size(0); |
| 3290 | } |
| 3291 | else |
| 3292 | { |
| 3293 | traits_type::assign(*__get_short_pointer(), value_type()); |
| 3294 | __set_short_size(0); |
| 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3299 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3300 | void |
| 3301 | basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) |
| 3302 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3303 | __null_terminate_at(std::__to_address(__get_pointer()), __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3307 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3308 | void |
| 3309 | basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) |
| 3310 | { |
| 3311 | size_type __sz = size(); |
| 3312 | if (__n > __sz) |
| 3313 | append(__n - __sz, __c); |
| 3314 | else |
| 3315 | __erase_to_end(__n); |
| 3316 | } |
| 3317 | |
| 3318 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3319 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 3320 | basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) |
| 3321 | { |
| 3322 | size_type __sz = size(); |
| 3323 | if (__n > __sz) { |
| 3324 | __append_default_init(__n - __sz); |
| 3325 | } else |
| 3326 | __erase_to_end(__n); |
| 3327 | } |
| 3328 | |
| 3329 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3330 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3331 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3332 | basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3333 | { |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 3334 | size_type __m = __alloc_traits::max_size(__alloc()); |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 3335 | if (__m <= std::numeric_limits<size_type>::max() / 2) { |
| 3336 | return __m - __alignment; |
| 3337 | } else { |
| 3338 | bool __uses_lsb = __endian_factor == 2; |
| 3339 | return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment; |
| 3340 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3344 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3345 | void |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3346 | basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3347 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3348 | if (__requested_capacity > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3349 | __throw_length_error(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3350 | |
Louis Dionne | 05b6d3e | 2022-01-14 12:30:22 -0500 | [diff] [blame] | 3351 | // Make sure reserve(n) never shrinks. This is technically only required in C++20 |
| 3352 | // and later (since P0966R1), however we provide consistent behavior in all Standard |
| 3353 | // modes because this function is instantiated in the shared library. |
| 3354 | if (__requested_capacity <= capacity()) |
| 3355 | return; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3356 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3357 | size_type __target_capacity = std::max(__requested_capacity, size()); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3358 | __target_capacity = __recommend(__target_capacity); |
| 3359 | if (__target_capacity == capacity()) return; |
| 3360 | |
| 3361 | __shrink_or_extend(__target_capacity); |
| 3362 | } |
| 3363 | |
| 3364 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3365 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3366 | void |
| 3367 | basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT |
| 3368 | { |
| 3369 | size_type __target_capacity = __recommend(size()); |
| 3370 | if (__target_capacity == capacity()) return; |
| 3371 | |
| 3372 | __shrink_or_extend(__target_capacity); |
| 3373 | } |
| 3374 | |
| 3375 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3376 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3377 | void |
| 3378 | basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) |
| 3379 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3380 | size_type __cap = capacity(); |
| 3381 | size_type __sz = size(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3382 | |
| 3383 | pointer __new_data, __p; |
| 3384 | bool __was_long, __now_long; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3385 | if (__fits_in_sso(__target_capacity)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3386 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3387 | __was_long = true; |
| 3388 | __now_long = false; |
| 3389 | __new_data = __get_short_pointer(); |
| 3390 | __p = __get_long_pointer(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3391 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3392 | else |
| 3393 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3394 | if (__target_capacity > __cap) { |
| 3395 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3396 | __new_data = __allocation.ptr; |
| 3397 | __target_capacity = __allocation.count - 1; |
| 3398 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3399 | else |
| 3400 | { |
| 3401 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3402 | try |
| 3403 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3404 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3405 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3406 | __new_data = __allocation.ptr; |
| 3407 | __target_capacity = __allocation.count - 1; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3408 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3409 | } |
| 3410 | catch (...) |
| 3411 | { |
| 3412 | return; |
| 3413 | } |
| 3414 | #else // _LIBCPP_NO_EXCEPTIONS |
| 3415 | if (__new_data == nullptr) |
| 3416 | return; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3417 | #endif // _LIBCPP_NO_EXCEPTIONS |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3418 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3419 | __begin_lifetime(__new_data, __target_capacity + 1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3420 | __now_long = true; |
| 3421 | __was_long = __is_long(); |
| 3422 | __p = __get_pointer(); |
| 3423 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3424 | traits_type::copy(std::__to_address(__new_data), |
| 3425 | std::__to_address(__p), size()+1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3426 | if (__was_long) |
| 3427 | __alloc_traits::deallocate(__alloc(), __p, __cap+1); |
| 3428 | if (__now_long) |
| 3429 | { |
| 3430 | __set_long_cap(__target_capacity+1); |
| 3431 | __set_long_size(__sz); |
| 3432 | __set_long_pointer(__new_data); |
| 3433 | } |
| 3434 | else |
| 3435 | __set_short_size(__sz); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3436 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3440 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3441 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3442 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3443 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3444 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3445 | return *(data() + __pos); |
| 3446 | } |
| 3447 | |
| 3448 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3449 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3450 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3451 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3452 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3453 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3454 | return *(__get_pointer() + __pos); |
| 3455 | } |
| 3456 | |
| 3457 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3458 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3459 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 3460 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const |
| 3461 | { |
| 3462 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3463 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3464 | return (*this)[__n]; |
| 3465 | } |
| 3466 | |
| 3467 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3468 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3469 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 3470 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) |
| 3471 | { |
| 3472 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3473 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3474 | return (*this)[__n]; |
| 3475 | } |
| 3476 | |
| 3477 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3478 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3479 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3480 | basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3481 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3482 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3483 | return *__get_pointer(); |
| 3484 | } |
| 3485 | |
| 3486 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3487 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3488 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3489 | basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3490 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3491 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3492 | return *data(); |
| 3493 | } |
| 3494 | |
| 3495 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3496 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3497 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3498 | basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3499 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3500 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3501 | return *(__get_pointer() + size() - 1); |
| 3502 | } |
| 3503 | |
| 3504 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3505 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3506 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3507 | basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3508 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3509 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3510 | return *(data() + size() - 1); |
| 3511 | } |
| 3512 | |
| 3513 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3514 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3515 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3516 | basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3517 | { |
| 3518 | size_type __sz = size(); |
| 3519 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3520 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3521 | size_type __rlen = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3522 | traits_type::copy(__s, data() + __pos, __rlen); |
| 3523 | return __rlen; |
| 3524 | } |
| 3525 | |
| 3526 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3527 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3528 | void |
| 3529 | basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3530 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3531 | _NOEXCEPT |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3532 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3533 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3534 | __is_nothrow_swappable<allocator_type>::value) |
| 3535 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3536 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 3537 | if (!__is_long()) |
| 3538 | std::__debug_db_invalidate_all(this); |
| 3539 | if (!__str.__is_long()) |
| 3540 | std::__debug_db_invalidate_all(&__str); |
| 3541 | std::__debug_db_swap(this, &__str); |
| 3542 | |
Eric Fiselier | 9bf691f | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 3543 | _LIBCPP_ASSERT( |
| 3544 | __alloc_traits::propagate_on_container_swap::value || |
| 3545 | __alloc_traits::is_always_equal::value || |
| 3546 | __alloc() == __str.__alloc(), "swapping non-equal allocators"); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3547 | std::swap(__r_.first(), __str.__r_.first()); |
| 3548 | std::__swap_allocator(__alloc(), __str.__alloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | // find |
| 3552 | |
| 3553 | template <class _Traits> |
| 3554 | struct _LIBCPP_HIDDEN __traits_eq |
| 3555 | { |
| 3556 | typedef typename _Traits::char_type char_type; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3557 | _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3558 | bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT |
| 3559 | {return _Traits::eq(__x, __y);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3560 | }; |
| 3561 | |
| 3562 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3563 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3564 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3565 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3566 | size_type __pos, |
| 3567 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3568 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3569 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3570 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3571 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3575 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3576 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3577 | basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, |
| 3578 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3579 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3580 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3581 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3582 | } |
| 3583 | |
| 3584 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3585 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3586 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3587 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3588 | < |
| 3589 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3590 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3591 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3592 | basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3593 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3594 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3595 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3596 | return __str_find<value_type, size_type, traits_type, npos> |
| 3597 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3598 | } |
| 3599 | |
| 3600 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3601 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3602 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3603 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3604 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3605 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3606 | _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3607 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3608 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3609 | } |
| 3610 | |
| 3611 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3612 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3613 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3614 | basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, |
| 3615 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3616 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3617 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3618 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | // rfind |
| 3622 | |
| 3623 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3624 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3625 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3626 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3627 | size_type __pos, |
| 3628 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3629 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3630 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3631 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3632 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3636 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3637 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3638 | basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, |
| 3639 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3640 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3641 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3642 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3646 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3647 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3648 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3649 | < |
| 3650 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3651 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3652 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3653 | basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3654 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3655 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3656 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3657 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 3658 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3659 | } |
| 3660 | |
| 3661 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3662 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3663 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3664 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3665 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3666 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3667 | _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3668 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3669 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3673 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3674 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3675 | basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, |
| 3676 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3677 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3678 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3679 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3680 | } |
| 3681 | |
| 3682 | // find_first_of |
| 3683 | |
| 3684 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3685 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3686 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3687 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3688 | size_type __pos, |
| 3689 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3690 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3691 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3692 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3693 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3697 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3698 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3699 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, |
| 3700 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3701 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3702 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3703 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3707 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3708 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3709 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3710 | < |
| 3711 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3712 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3713 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3714 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3715 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3716 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3717 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3718 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 3719 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3720 | } |
| 3721 | |
| 3722 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3723 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3724 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3725 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3726 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3727 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3728 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3729 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3730 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3734 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3735 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3736 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, |
| 3737 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3738 | { |
| 3739 | return find(__c, __pos); |
| 3740 | } |
| 3741 | |
| 3742 | // find_last_of |
| 3743 | |
| 3744 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3745 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3746 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3747 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3748 | size_type __pos, |
| 3749 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3750 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3751 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3752 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3753 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3757 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3758 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3759 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, |
| 3760 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3761 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3762 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3763 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3767 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3768 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3769 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3770 | < |
| 3771 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3772 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3773 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3774 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3775 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3776 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3777 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3778 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 3779 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3780 | } |
| 3781 | |
| 3782 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3783 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3784 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3785 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3786 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3787 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3788 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3789 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3790 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3794 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3795 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3796 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, |
| 3797 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3798 | { |
| 3799 | return rfind(__c, __pos); |
| 3800 | } |
| 3801 | |
| 3802 | // find_first_not_of |
| 3803 | |
| 3804 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3805 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3806 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3807 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3808 | size_type __pos, |
| 3809 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3810 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3811 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3812 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3813 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3817 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3818 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3819 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, |
| 3820 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3821 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3822 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3823 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3827 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3828 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3829 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3830 | < |
| 3831 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3832 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3833 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3834 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3835 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3836 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3837 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3838 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 3839 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3840 | } |
| 3841 | |
| 3842 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3843 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3844 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3845 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3846 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3847 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3848 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3849 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3850 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3851 | } |
| 3852 | |
| 3853 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3854 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3855 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3856 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, |
| 3857 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3858 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3859 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3860 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | // find_last_not_of |
| 3864 | |
| 3865 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3866 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3867 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3868 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3869 | size_type __pos, |
| 3870 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3871 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3872 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3873 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3874 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3878 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3879 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3880 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, |
| 3881 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3882 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3883 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3884 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3888 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3889 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3890 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3891 | < |
| 3892 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3893 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3894 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3895 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3896 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3897 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3898 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3899 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 3900 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3901 | } |
| 3902 | |
| 3903 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3904 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3905 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3906 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3907 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3908 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3909 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3910 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3911 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3912 | } |
| 3913 | |
| 3914 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3915 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3916 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3917 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, |
| 3918 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3919 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3920 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3921 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
| 3924 | // compare |
| 3925 | |
| 3926 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3927 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3928 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3929 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3930 | < |
| 3931 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3932 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3933 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3934 | basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3935 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3936 | __self_view __sv = __t; |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3937 | size_t __lhs_sz = size(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3938 | size_t __rhs_sz = __sv.size(); |
| 3939 | int __result = traits_type::compare(data(), __sv.data(), |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3940 | std::min(__lhs_sz, __rhs_sz)); |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3941 | if (__result != 0) |
| 3942 | return __result; |
| 3943 | if (__lhs_sz < __rhs_sz) |
| 3944 | return -1; |
| 3945 | if (__lhs_sz > __rhs_sz) |
| 3946 | return 1; |
| 3947 | return 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3951 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3952 | int |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3953 | basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3954 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3955 | return compare(__self_view(__str)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3956 | } |
| 3957 | |
| 3958 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3959 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3960 | int |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3961 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3962 | size_type __n1, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3963 | const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3964 | size_type __n2) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3965 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3966 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3967 | size_type __sz = size(); |
| 3968 | if (__pos1 > __sz || __n2 == npos) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3969 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3970 | size_type __rlen = std::min(__n1, __sz - __pos1); |
| 3971 | int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3972 | if (__r == 0) |
| 3973 | { |
| 3974 | if (__rlen < __n2) |
| 3975 | __r = -1; |
| 3976 | else if (__rlen > __n2) |
| 3977 | __r = 1; |
| 3978 | } |
| 3979 | return __r; |
| 3980 | } |
| 3981 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3982 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3983 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3984 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3985 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3986 | < |
| 3987 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3988 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3989 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3990 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3991 | size_type __n1, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3992 | const _Tp& __t) const |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3993 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3994 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3995 | return compare(__pos1, __n1, __sv.data(), __sv.size()); |
| 3996 | } |
| 3997 | |
| 3998 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3999 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4000 | int |
| 4001 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4002 | size_type __n1, |
| 4003 | const basic_string& __str) const |
| 4004 | { |
| 4005 | return compare(__pos1, __n1, __str.data(), __str.size()); |
| 4006 | } |
| 4007 | |
| 4008 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4009 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4010 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 4011 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4012 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 4013 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 4014 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 4015 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 4016 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4017 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4018 | size_type __n1, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4019 | const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4020 | size_type __pos2, |
| 4021 | size_type __n2) const |
| 4022 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4023 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4024 | return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 4025 | } |
| 4026 | |
| 4027 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4028 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4029 | int |
| 4030 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4031 | size_type __n1, |
| 4032 | const basic_string& __str, |
| 4033 | size_type __pos2, |
| 4034 | size_type __n2) const |
| 4035 | { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4036 | return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4037 | } |
| 4038 | |
| 4039 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4040 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4041 | int |
| 4042 | basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT |
| 4043 | { |
| 4044 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4045 | return compare(0, npos, __s, traits_type::length(__s)); |
| 4046 | } |
| 4047 | |
| 4048 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4049 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4050 | int |
| 4051 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4052 | size_type __n1, |
| 4053 | const value_type* __s) const |
| 4054 | { |
| 4055 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4056 | return compare(__pos1, __n1, __s, traits_type::length(__s)); |
| 4057 | } |
| 4058 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4059 | // __invariants |
| 4060 | |
| 4061 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4062 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4063 | bool |
| 4064 | basic_string<_CharT, _Traits, _Allocator>::__invariants() const |
| 4065 | { |
| 4066 | if (size() > capacity()) |
| 4067 | return false; |
| 4068 | if (capacity() < __min_cap - 1) |
| 4069 | return false; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4070 | if (data() == nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4071 | return false; |
Louis Dionne | 663415f | 2020-10-05 16:16:13 -0400 | [diff] [blame] | 4072 | if (data()[size()] != value_type()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4073 | return false; |
| 4074 | return true; |
| 4075 | } |
| 4076 | |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4077 | // __clear_and_shrink |
| 4078 | |
| 4079 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4080 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4081 | void |
Marshall Clow | e60a718 | 2018-05-29 17:04:37 +0000 | [diff] [blame] | 4082 | basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4083 | { |
| 4084 | clear(); |
| 4085 | if(__is_long()) |
| 4086 | { |
| 4087 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); |
Nikolas Klauser | 1821ec3 | 2022-10-01 15:37:24 +0200 | [diff] [blame] | 4088 | __default_init(); |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4089 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4090 | } |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4091 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4092 | // operator== |
| 4093 | |
| 4094 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4095 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4096 | bool |
| 4097 | operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4098 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4099 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4100 | #if _LIBCPP_STD_VER > 17 |
| 4101 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4102 | #else |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4103 | size_t __lhs_sz = __lhs.size(); |
| 4104 | return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), |
| 4105 | __rhs.data(), |
| 4106 | __lhs_sz) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4107 | #endif |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | template<class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4111 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4112 | bool |
| 4113 | operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, |
| 4114 | const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT |
| 4115 | { |
| 4116 | size_t __lhs_sz = __lhs.size(); |
| 4117 | if (__lhs_sz != __rhs.size()) |
| 4118 | return false; |
| 4119 | const char* __lp = __lhs.data(); |
| 4120 | const char* __rp = __rhs.data(); |
| 4121 | if (__lhs.__is_long()) |
| 4122 | return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; |
| 4123 | for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) |
| 4124 | if (*__lp != *__rp) |
| 4125 | return false; |
| 4126 | return true; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4127 | } |
| 4128 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4129 | #if _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4130 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4131 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4132 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4133 | operator==(const _CharT* __lhs, |
| 4134 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4135 | { |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4136 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4137 | _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); |
| 4138 | size_t __lhs_len = _Traits::length(__lhs); |
| 4139 | if (__lhs_len != __rhs.size()) return false; |
| 4140 | return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4141 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4142 | #endif // _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4143 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4144 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4145 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4146 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4147 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
| 4148 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4149 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4150 | #if _LIBCPP_STD_VER > 17 |
| 4151 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4152 | #else |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4153 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4154 | _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); |
| 4155 | size_t __rhs_len = _Traits::length(__rhs); |
| 4156 | if (__rhs_len != __lhs.size()) return false; |
| 4157 | return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4158 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4159 | } |
| 4160 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4161 | #if _LIBCPP_STD_VER > 17 |
| 4162 | |
| 4163 | template <class _CharT, class _Traits, class _Allocator> |
| 4164 | _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>( |
| 4165 | const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4166 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) noexcept { |
| 4167 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4168 | } |
| 4169 | |
| 4170 | template <class _CharT, class _Traits, class _Allocator> |
| 4171 | _LIBCPP_HIDE_FROM_ABI constexpr auto |
| 4172 | operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) { |
| 4173 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4174 | } |
| 4175 | |
| 4176 | #else // _LIBCPP_STD_VER > 17 |
| 4177 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4178 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4179 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4180 | bool |
| 4181 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4182 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4183 | { |
| 4184 | return !(__lhs == __rhs); |
| 4185 | } |
| 4186 | |
| 4187 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4188 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4189 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4190 | operator!=(const _CharT* __lhs, |
| 4191 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4192 | { |
| 4193 | return !(__lhs == __rhs); |
| 4194 | } |
| 4195 | |
| 4196 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4197 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4198 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4199 | operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4200 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4201 | { |
| 4202 | return !(__lhs == __rhs); |
| 4203 | } |
| 4204 | |
| 4205 | // operator< |
| 4206 | |
| 4207 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4208 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4209 | bool |
| 4210 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4211 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4212 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4213 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4217 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4218 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4219 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4220 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4221 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4222 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4226 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4227 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4228 | operator< (const _CharT* __lhs, |
| 4229 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4230 | { |
| 4231 | return __rhs.compare(__lhs) > 0; |
| 4232 | } |
| 4233 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4234 | // operator> |
| 4235 | |
| 4236 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4237 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4238 | bool |
| 4239 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4240 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4241 | { |
| 4242 | return __rhs < __lhs; |
| 4243 | } |
| 4244 | |
| 4245 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4246 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4247 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4248 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4249 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4250 | { |
| 4251 | return __rhs < __lhs; |
| 4252 | } |
| 4253 | |
| 4254 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4255 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4256 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4257 | operator> (const _CharT* __lhs, |
| 4258 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4259 | { |
| 4260 | return __rhs < __lhs; |
| 4261 | } |
| 4262 | |
| 4263 | // operator<= |
| 4264 | |
| 4265 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4266 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4267 | bool |
| 4268 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4269 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4270 | { |
| 4271 | return !(__rhs < __lhs); |
| 4272 | } |
| 4273 | |
| 4274 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4275 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4276 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4277 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4278 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4279 | { |
| 4280 | return !(__rhs < __lhs); |
| 4281 | } |
| 4282 | |
| 4283 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4284 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4285 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4286 | operator<=(const _CharT* __lhs, |
| 4287 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4288 | { |
| 4289 | return !(__rhs < __lhs); |
| 4290 | } |
| 4291 | |
| 4292 | // operator>= |
| 4293 | |
| 4294 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4295 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4296 | bool |
| 4297 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4298 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4299 | { |
| 4300 | return !(__lhs < __rhs); |
| 4301 | } |
| 4302 | |
| 4303 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4304 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4305 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4306 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4307 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4308 | { |
| 4309 | return !(__lhs < __rhs); |
| 4310 | } |
| 4311 | |
| 4312 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4313 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4314 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4315 | operator>=(const _CharT* __lhs, |
| 4316 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4317 | { |
| 4318 | return !(__lhs < __rhs); |
| 4319 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4320 | #endif // _LIBCPP_STD_VER > 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4321 | |
| 4322 | // operator + |
| 4323 | |
| 4324 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4325 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4326 | basic_string<_CharT, _Traits, _Allocator> |
| 4327 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4328 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4329 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4330 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4331 | auto __lhs_sz = __lhs.size(); |
| 4332 | auto __rhs_sz = __rhs.size(); |
| 4333 | _String __r(__uninitialized_size_tag(), |
| 4334 | __lhs_sz + __rhs_sz, |
| 4335 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4336 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4337 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4338 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4339 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4340 | return __r; |
| 4341 | } |
| 4342 | |
| 4343 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4344 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4345 | basic_string<_CharT, _Traits, _Allocator> |
| 4346 | operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4347 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4348 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4349 | auto __lhs_sz = _Traits::length(__lhs); |
| 4350 | auto __rhs_sz = __rhs.size(); |
| 4351 | _String __r(__uninitialized_size_tag(), |
| 4352 | __lhs_sz + __rhs_sz, |
| 4353 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4354 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4355 | _Traits::copy(__ptr, __lhs, __lhs_sz); |
| 4356 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4357 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4358 | return __r; |
| 4359 | } |
| 4360 | |
| 4361 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4362 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4363 | basic_string<_CharT, _Traits, _Allocator> |
| 4364 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4365 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4366 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4367 | typename _String::size_type __rhs_sz = __rhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4368 | _String __r(__uninitialized_size_tag(), |
| 4369 | __rhs_sz + 1, |
| 4370 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4371 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4372 | _Traits::assign(__ptr, 1, __lhs); |
| 4373 | _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz); |
| 4374 | _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4375 | return __r; |
| 4376 | } |
| 4377 | |
| 4378 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4379 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4380 | basic_string<_CharT, _Traits, _Allocator> |
| 4381 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) |
| 4382 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4383 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4384 | typename _String::size_type __lhs_sz = __lhs.size(); |
| 4385 | typename _String::size_type __rhs_sz = _Traits::length(__rhs); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4386 | _String __r(__uninitialized_size_tag(), |
| 4387 | __lhs_sz + __rhs_sz, |
| 4388 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4389 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4390 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4391 | _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz); |
| 4392 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4393 | return __r; |
| 4394 | } |
| 4395 | |
| 4396 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4397 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4398 | basic_string<_CharT, _Traits, _Allocator> |
| 4399 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) |
| 4400 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4401 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4402 | typename _String::size_type __lhs_sz = __lhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4403 | _String __r(__uninitialized_size_tag(), |
| 4404 | __lhs_sz + 1, |
| 4405 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4406 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4407 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4408 | _Traits::assign(__ptr + __lhs_sz, 1, __rhs); |
| 4409 | _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4410 | return __r; |
| 4411 | } |
| 4412 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 4413 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4414 | |
| 4415 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4416 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4417 | basic_string<_CharT, _Traits, _Allocator> |
| 4418 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4419 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4420 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4424 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4425 | basic_string<_CharT, _Traits, _Allocator> |
| 4426 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4427 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4428 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4432 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4433 | basic_string<_CharT, _Traits, _Allocator> |
| 4434 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4435 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4436 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4440 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4441 | basic_string<_CharT, _Traits, _Allocator> |
| 4442 | operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4443 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4444 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4448 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4449 | basic_string<_CharT, _Traits, _Allocator> |
| 4450 | operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4451 | { |
| 4452 | __rhs.insert(__rhs.begin(), __lhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4453 | return std::move(__rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4454 | } |
| 4455 | |
| 4456 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4457 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4458 | basic_string<_CharT, _Traits, _Allocator> |
| 4459 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) |
| 4460 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4461 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4465 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4466 | basic_string<_CharT, _Traits, _Allocator> |
| 4467 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) |
| 4468 | { |
| 4469 | __lhs.push_back(__rhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4470 | return std::move(__lhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4471 | } |
| 4472 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4473 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4474 | |
| 4475 | // swap |
| 4476 | |
| 4477 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4478 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4479 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4480 | swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 4481 | basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4482 | _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4483 | { |
| 4484 | __lhs.swap(__rhs); |
| 4485 | } |
| 4486 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4487 | _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4488 | _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4489 | _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4490 | _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4491 | _LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = nullptr, int __base = 10); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4492 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4493 | _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr); |
| 4494 | _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr); |
| 4495 | _LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4496 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4497 | _LIBCPP_FUNC_VIS string to_string(int __val); |
| 4498 | _LIBCPP_FUNC_VIS string to_string(unsigned __val); |
| 4499 | _LIBCPP_FUNC_VIS string to_string(long __val); |
| 4500 | _LIBCPP_FUNC_VIS string to_string(unsigned long __val); |
| 4501 | _LIBCPP_FUNC_VIS string to_string(long long __val); |
| 4502 | _LIBCPP_FUNC_VIS string to_string(unsigned long long __val); |
| 4503 | _LIBCPP_FUNC_VIS string to_string(float __val); |
| 4504 | _LIBCPP_FUNC_VIS string to_string(double __val); |
| 4505 | _LIBCPP_FUNC_VIS string to_string(long double __val); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4506 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4507 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4508 | _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4509 | _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4510 | _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4511 | _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4512 | _LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4513 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4514 | _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr); |
| 4515 | _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr); |
| 4516 | _LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4517 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4518 | _LIBCPP_FUNC_VIS wstring to_wstring(int __val); |
| 4519 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); |
| 4520 | _LIBCPP_FUNC_VIS wstring to_wstring(long __val); |
| 4521 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); |
| 4522 | _LIBCPP_FUNC_VIS wstring to_wstring(long long __val); |
| 4523 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); |
| 4524 | _LIBCPP_FUNC_VIS wstring to_wstring(float __val); |
| 4525 | _LIBCPP_FUNC_VIS wstring to_wstring(double __val); |
| 4526 | _LIBCPP_FUNC_VIS wstring to_wstring(long double __val); |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4527 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4528 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4529 | template<class _CharT, class _Traits, class _Allocator> |
Martin Storsjö | 88890c2 | 2021-02-22 01:13:13 +0200 | [diff] [blame] | 4530 | _LIBCPP_TEMPLATE_DATA_VIS |
Eric Fiselier | c9fdaf1 | 2020-01-15 17:02:17 -0500 | [diff] [blame] | 4531 | const typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4532 | basic_string<_CharT, _Traits, _Allocator>::npos; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4533 | |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4534 | template <class _CharT, class _Allocator> |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4535 | struct __string_hash : public __unary_function<basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4536 | { |
| 4537 | size_t |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4538 | operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT |
| 4539 | { return __do_string_hash(__val.data(), __val.data() + __val.size()); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4540 | }; |
| 4541 | |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4542 | template <class _Allocator> |
| 4543 | struct hash<basic_string<char, char_traits<char>, _Allocator> > : __string_hash<char, _Allocator> {}; |
| 4544 | |
| 4545 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
| 4546 | template <class _Allocator> |
| 4547 | struct hash<basic_string<char8_t, char_traits<char8_t>, _Allocator> > : __string_hash<char8_t, _Allocator> {}; |
| 4548 | #endif |
| 4549 | |
| 4550 | template <class _Allocator> |
| 4551 | struct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __string_hash<char16_t, _Allocator> {}; |
| 4552 | |
| 4553 | template <class _Allocator> |
| 4554 | struct hash<basic_string<char32_t, char_traits<char32_t>, _Allocator> > : __string_hash<char32_t, _Allocator> {}; |
| 4555 | |
| 4556 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4557 | template <class _Allocator> |
| 4558 | struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Allocator> > : __string_hash<wchar_t, _Allocator> {}; |
| 4559 | #endif |
| 4560 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4561 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4562 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4563 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4564 | const basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4565 | |
| 4566 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4567 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4568 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4569 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4570 | |
| 4571 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4572 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4573 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4574 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4575 | |
| 4576 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4577 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4578 | basic_istream<_CharT, _Traits>& |
| 4579 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4580 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4581 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4582 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4583 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4584 | basic_istream<_CharT, _Traits>& |
| 4585 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4586 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4587 | |
| 4588 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4589 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4590 | basic_istream<_CharT, _Traits>& |
| 4591 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4592 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4593 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4594 | #if _LIBCPP_STD_VER > 17 |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4595 | template <class _CharT, class _Traits, class _Allocator, class _Up> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4596 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4597 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4598 | erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) { |
| 4599 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4600 | __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end()); |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4601 | return __old_size - __str.size(); |
| 4602 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4603 | |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4604 | template <class _CharT, class _Traits, class _Allocator, class _Predicate> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4605 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4606 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4607 | erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, |
| 4608 | _Predicate __pred) { |
| 4609 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4610 | __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4611 | __str.end()); |
| 4612 | return __old_size - __str.size(); |
| 4613 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4614 | #endif |
| 4615 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4616 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4617 | |
| 4618 | template<class _CharT, class _Traits, class _Allocator> |
| 4619 | bool |
| 4620 | basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 4621 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4622 | return data() <= std::__to_address(__i->base()) && |
| 4623 | std::__to_address(__i->base()) < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | template<class _CharT, class _Traits, class _Allocator> |
| 4627 | bool |
| 4628 | basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const |
| 4629 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4630 | return data() < std::__to_address(__i->base()) && |
| 4631 | std::__to_address(__i->base()) <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | template<class _CharT, class _Traits, class _Allocator> |
| 4635 | bool |
| 4636 | basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 4637 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4638 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4639 | return data() <= __p && __p <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4640 | } |
| 4641 | |
| 4642 | template<class _CharT, class _Traits, class _Allocator> |
| 4643 | bool |
| 4644 | basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 4645 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4646 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4647 | return data() <= __p && __p < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4648 | } |
| 4649 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4650 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4651 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4652 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4653 | // Literal suffixes for basic_string [basic.string.literals] |
Marshall Clow | ac86837 | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 4654 | inline namespace literals |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4655 | { |
| 4656 | inline namespace string_literals |
| 4657 | { |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4658 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4659 | basic_string<char> operator "" s( const char *__str, size_t __len ) |
| 4660 | { |
| 4661 | return basic_string<char> (__str, __len); |
| 4662 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4663 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4664 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4665 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4666 | basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) |
| 4667 | { |
| 4668 | return basic_string<wchar_t> (__str, __len); |
| 4669 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4670 | #endif |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4671 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 4672 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4673 | inline _LIBCPP_HIDE_FROM_ABI constexpr |
Nikolas Klauser | 5da956d | 2022-09-02 16:20:28 +0200 | [diff] [blame] | 4674 | basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 4675 | { |
| 4676 | return basic_string<char8_t> (__str, __len); |
| 4677 | } |
| 4678 | #endif |
| 4679 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4680 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4681 | basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) |
| 4682 | { |
| 4683 | return basic_string<char16_t> (__str, __len); |
| 4684 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4685 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4686 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4687 | basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) |
| 4688 | { |
| 4689 | return basic_string<char32_t> (__str, __len); |
| 4690 | } |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 4691 | } // namespace string_literals |
| 4692 | } // namespace literals |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 4693 | |
| 4694 | #if _LIBCPP_STD_VER > 17 |
| 4695 | template <> |
| 4696 | inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true; |
| 4697 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4698 | template <> |
| 4699 | inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true; |
| 4700 | #endif |
| 4701 | #endif |
| 4702 | |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4703 | #endif |
| 4704 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4705 | _LIBCPP_END_NAMESPACE_STD |
| 4706 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 4707 | _LIBCPP_POP_MACROS |
| 4708 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 4709 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 4710 | # include <algorithm> |
| 4711 | # include <functional> |
| 4712 | # include <iterator> |
| 4713 | # include <new> |
| 4714 | # include <typeinfo> |
| 4715 | # include <utility> |
| 4716 | # include <vector> |
| 4717 | #endif |
| 4718 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4719 | #endif // _LIBCPP_STRING |