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 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 112 | template<class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 113 | 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] | 114 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 115 | explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20 |
| 116 | basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 117 | 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] | 118 | basic_string(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 119 | 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] | 120 | template<class InputIterator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 121 | basic_string(InputIterator begin, InputIterator end, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 122 | const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 123 | basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20 |
| 124 | basic_string(const basic_string&, const Allocator&); // constexpr since C++20 |
| 125 | basic_string(basic_string&&, const Allocator&); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 126 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 127 | ~basic_string(); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 128 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 129 | operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 130 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 131 | basic_string& operator=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 132 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 133 | basic_string& operator=(const T& t); // C++17, constexpr since C++20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 134 | basic_string& operator=(basic_string&& str) |
| 135 | noexcept( |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 136 | allocator_type::propagate_on_container_move_assignment::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 137 | allocator_type::is_always_equal::value ); // C++17, constexpr since C++20 |
| 138 | basic_string& operator=(const value_type* s); // constexpr since C++20 |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 139 | basic_string& operator=(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 140 | basic_string& operator=(value_type c); // constexpr since C++20 |
| 141 | basic_string& operator=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 142 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 143 | iterator begin() noexcept; // constexpr since C++20 |
| 144 | const_iterator begin() const noexcept; // constexpr since C++20 |
| 145 | iterator end() noexcept; // constexpr since C++20 |
| 146 | const_iterator end() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 147 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 148 | reverse_iterator rbegin() noexcept; // constexpr since C++20 |
| 149 | const_reverse_iterator rbegin() const noexcept; // constexpr since C++20 |
| 150 | reverse_iterator rend() noexcept; // constexpr since C++20 |
| 151 | const_reverse_iterator rend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 152 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 153 | const_iterator cbegin() const noexcept; // constexpr since C++20 |
| 154 | const_iterator cend() const noexcept; // constexpr since C++20 |
| 155 | const_reverse_iterator crbegin() const noexcept; // constexpr since C++20 |
| 156 | const_reverse_iterator crend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 157 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 158 | size_type size() const noexcept; // constexpr since C++20 |
| 159 | size_type length() const noexcept; // constexpr since C++20 |
| 160 | size_type max_size() const noexcept; // constexpr since C++20 |
| 161 | size_type capacity() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 162 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 163 | void resize(size_type n, value_type c); // constexpr since C++20 |
| 164 | void resize(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 165 | |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 166 | template<class Operation> |
| 167 | constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23 |
| 168 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 169 | void reserve(size_type res_arg); // constexpr since C++20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 170 | void reserve(); // deprecated in C++20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 171 | void shrink_to_fit(); // constexpr since C++20 |
| 172 | void clear() noexcept; // constexpr since C++20 |
| 173 | bool empty() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 174 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 175 | const_reference operator[](size_type pos) const; // constexpr since C++20 |
| 176 | reference operator[](size_type pos); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 178 | const_reference at(size_type n) const; // constexpr since C++20 |
| 179 | reference at(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 180 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 181 | basic_string& operator+=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 182 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 183 | basic_string& operator+=(const T& t); // C++17, constexpr since C++20 |
| 184 | basic_string& operator+=(const value_type* s); // constexpr since C++20 |
| 185 | basic_string& operator+=(value_type c); // constexpr since C++20 |
| 186 | basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 187 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 188 | basic_string& append(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 189 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 190 | basic_string& append(const T& t); // C++17, constexpr since C++20 |
| 191 | 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] | 192 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 193 | basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 194 | basic_string& append(const value_type* s, size_type n); // constexpr since C++20 |
| 195 | basic_string& append(const value_type* s); // constexpr since C++20 |
| 196 | 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] | 197 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 198 | basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20 |
| 199 | basic_string& append(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 200 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 201 | void push_back(value_type c); // constexpr since C++20 |
| 202 | void pop_back(); // constexpr since C++20 |
| 203 | reference front(); // constexpr since C++20 |
| 204 | const_reference front() const; // constexpr since C++20 |
| 205 | reference back(); // constexpr since C++20 |
| 206 | const_reference back() const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 207 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 208 | basic_string& assign(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 209 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 210 | basic_string& assign(const T& t); // C++17, constexpr since C++20 |
| 211 | basic_string& assign(basic_string&& str); // constexpr since C++20 |
| 212 | 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] | 213 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 214 | basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 215 | basic_string& assign(const value_type* s, size_type n); // constexpr since C++20 |
| 216 | basic_string& assign(const value_type* s); // constexpr since C++20 |
| 217 | 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] | 218 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 219 | basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20 |
| 220 | basic_string& assign(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 221 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 222 | 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] | 223 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 224 | 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] | 225 | basic_string& insert(size_type pos1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 226 | size_type pos2, size_type n); // constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +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, size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 229 | basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20 |
| 230 | basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20 |
| 231 | basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20 |
| 232 | iterator insert(const_iterator p, value_type c); // constexpr since C++20 |
| 233 | 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] | 234 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 235 | iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20 |
| 236 | 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] | 237 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 238 | basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20 |
| 239 | iterator erase(const_iterator position); // constexpr since C++20 |
| 240 | iterator erase(const_iterator first, const_iterator last); // 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& 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] | 243 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 244 | 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] | 245 | 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] | 246 | 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] | 247 | template <class T> |
| 248 | basic_string& replace(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 249 | size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 250 | basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20 |
| 251 | basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20 |
| 252 | basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20 |
| 253 | 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] | 254 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 255 | basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20 |
| 256 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20 |
| 257 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20 |
| 258 | 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] | 259 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 260 | basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20 |
| 261 | 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] | 262 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 263 | size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20 |
| 264 | basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 265 | |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 266 | void swap(basic_string& str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 267 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 268 | 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] | 269 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 270 | const value_type* c_str() const noexcept; // constexpr since C++20 |
| 271 | const value_type* data() const noexcept; // constexpr since C++20 |
| 272 | value_type* data() noexcept; // C++17, constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 273 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 274 | allocator_type get_allocator() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 276 | 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] | 277 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 278 | size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 279 | size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 280 | size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 281 | 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] | 282 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 283 | 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] | 284 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 285 | size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 286 | size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 287 | size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 288 | 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] | 289 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 290 | 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] | 291 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 292 | size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 293 | size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 294 | size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 295 | 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] | 296 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 297 | 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] | 298 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 299 | 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 |
| 300 | size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 301 | size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 302 | 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] | 303 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 304 | 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] | 305 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 306 | 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 |
| 307 | size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 308 | size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 309 | 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] | 310 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 311 | 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] | 312 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 313 | 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 |
| 314 | size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 315 | size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 316 | 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] | 317 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 318 | int compare(const basic_string& str) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 319 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 320 | int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 321 | 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] | 322 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 323 | 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] | 324 | int compare(size_type pos1, size_type n1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 325 | 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] | 326 | template <class T> |
| 327 | int compare(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 328 | size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20 |
| 329 | int compare(const value_type* s) const noexcept; // constexpr since C++20 |
| 330 | int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20 |
| 331 | 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] | 332 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 333 | constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 334 | constexpr bool starts_with(charT c) const noexcept; // C++20 |
| 335 | constexpr bool starts_with(const charT* s) const; // C++20 |
| 336 | constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 337 | constexpr bool ends_with(charT c) const noexcept; // C++20 |
| 338 | constexpr bool ends_with(const charT* s) const; // C++20 |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 339 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 340 | constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b |
| 341 | constexpr bool contains(charT c) const noexcept; // C++2b |
| 342 | constexpr bool contains(const charT* s) const; // C++2b |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 345 | template<class InputIterator, |
| 346 | class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> |
| 347 | basic_string(InputIterator, InputIterator, Allocator = Allocator()) |
| 348 | -> basic_string<typename iterator_traits<InputIterator>::value_type, |
| 349 | char_traits<typename iterator_traits<InputIterator>::value_type>, |
| 350 | Allocator>; // C++17 |
| 351 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 352 | template<class charT, class traits, class Allocator> |
| 353 | basic_string<charT, traits, Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 354 | operator+(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 355 | const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 356 | |
| 357 | template<class charT, class traits, class Allocator> |
| 358 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 359 | 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] | 360 | |
| 361 | template<class charT, class traits, class Allocator> |
| 362 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 363 | 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] | 364 | |
| 365 | template<class charT, class traits, class Allocator> |
| 366 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 367 | 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] | 368 | |
| 369 | template<class charT, class traits, class Allocator> |
| 370 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 371 | 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] | 372 | |
| 373 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 374 | bool operator==(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 375 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 376 | |
| 377 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 378 | 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] | 379 | |
| 380 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 381 | 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] | 382 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 383 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 384 | bool operator!=(const basic_string<charT,traits,Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 385 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 386 | |
| 387 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 388 | 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] | 389 | |
| 390 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 391 | 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] | 392 | |
| 393 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 394 | bool operator< (const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 395 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 396 | |
| 397 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 398 | 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] | 399 | |
| 400 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 401 | 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] | 402 | |
| 403 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 404 | bool operator> (const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 405 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | |
| 407 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 408 | 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] | 409 | |
| 410 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 411 | 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] | 412 | |
| 413 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 414 | bool operator<=(const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 415 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 416 | |
| 417 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 418 | 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] | 419 | |
| 420 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 421 | 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] | 422 | |
| 423 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 424 | bool operator>=(const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 425 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 426 | |
| 427 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 428 | 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] | 429 | |
| 430 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 431 | 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] | 432 | |
| 433 | template<class charT, class traits, class Allocator> // since C++20 |
| 434 | constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, |
| 435 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
| 436 | |
| 437 | template<class charT, class traits, class Allocator> // since C++20 |
| 438 | constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, |
| 439 | const charT* rhs) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 440 | |
| 441 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 442 | void swap(basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 443 | basic_string<charT, traits, Allocator>& rhs) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 444 | noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | |
| 446 | template<class charT, class traits, class Allocator> |
| 447 | basic_istream<charT, traits>& |
| 448 | operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 449 | |
| 450 | template<class charT, class traits, class Allocator> |
| 451 | basic_ostream<charT, traits>& |
| 452 | operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); |
| 453 | |
| 454 | template<class charT, class traits, class Allocator> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 455 | basic_istream<charT, traits>& |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 456 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, |
| 457 | charT delim); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 458 | |
| 459 | template<class charT, class traits, class Allocator> |
| 460 | basic_istream<charT, traits>& |
| 461 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 462 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 463 | template<class charT, class traits, class Allocator, class U> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 464 | typename basic_string<charT, traits, Allocator>::size_type |
| 465 | erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 466 | template<class charT, class traits, class Allocator, class Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 467 | typename basic_string<charT, traits, Allocator>::size_type |
| 468 | erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 469 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 470 | typedef basic_string<char> string; |
| 471 | typedef basic_string<wchar_t> wstring; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 472 | typedef basic_string<char8_t> u8string; // C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 473 | typedef basic_string<char16_t> u16string; |
| 474 | typedef basic_string<char32_t> u32string; |
| 475 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 476 | int stoi (const string& str, size_t* idx = nullptr, int base = 10); |
| 477 | long stol (const string& str, size_t* idx = nullptr, int base = 10); |
| 478 | unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10); |
| 479 | long long stoll (const string& str, size_t* idx = nullptr, int base = 10); |
| 480 | 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] | 481 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 482 | float stof (const string& str, size_t* idx = nullptr); |
| 483 | double stod (const string& str, size_t* idx = nullptr); |
| 484 | long double stold(const string& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 485 | |
| 486 | string to_string(int val); |
| 487 | string to_string(unsigned val); |
| 488 | string to_string(long val); |
| 489 | string to_string(unsigned long val); |
| 490 | string to_string(long long val); |
| 491 | string to_string(unsigned long long val); |
| 492 | string to_string(float val); |
| 493 | string to_string(double val); |
| 494 | string to_string(long double val); |
| 495 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 496 | int stoi (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 497 | long stol (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 498 | unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 499 | long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 500 | 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] | 501 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 502 | float stof (const wstring& str, size_t* idx = nullptr); |
| 503 | double stod (const wstring& str, size_t* idx = nullptr); |
| 504 | long double stold(const wstring& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 505 | |
| 506 | wstring to_wstring(int val); |
| 507 | wstring to_wstring(unsigned val); |
| 508 | wstring to_wstring(long val); |
| 509 | wstring to_wstring(unsigned long val); |
| 510 | wstring to_wstring(long long val); |
| 511 | wstring to_wstring(unsigned long long val); |
| 512 | wstring to_wstring(float val); |
| 513 | wstring to_wstring(double val); |
| 514 | wstring to_wstring(long double val); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | |
| 516 | template <> struct hash<string>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 517 | template <> struct hash<u8string>; // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | template <> struct hash<u16string>; |
| 519 | template <> struct hash<u32string>; |
| 520 | template <> struct hash<wstring>; |
| 521 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 522 | basic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20 |
| 523 | basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20 |
| 524 | constexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20 |
| 525 | basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20 |
| 526 | 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] | 527 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | } // std |
| 529 | |
| 530 | */ |
| 531 | |
Nikolas Klauser | f210d8a | 2022-02-15 18:18:08 +0100 | [diff] [blame] | 532 | #include <__algorithm/max.h> |
| 533 | #include <__algorithm/min.h> |
| 534 | #include <__algorithm/remove.h> |
| 535 | #include <__algorithm/remove_if.h> |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 536 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 537 | #include <__config> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 538 | #include <__debug> |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 539 | #include <__format/enable_insertable.h> |
Nikolas Klauser | 11a0ff3 | 2022-06-06 23:35:24 +0200 | [diff] [blame] | 540 | #include <__functional/hash.h> |
Nikolas Klauser | 24540d3 | 2022-05-21 00:45:51 +0200 | [diff] [blame] | 541 | #include <__functional/unary_function.h> |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame^] | 542 | #include <__fwd/string.h> |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 543 | #include <__ios/fpos.h> |
Nikolas Klauser | fb1b067 | 2022-06-10 19:53:10 +0200 | [diff] [blame] | 544 | #include <__iterator/distance.h> |
| 545 | #include <__iterator/iterator_traits.h> |
| 546 | #include <__iterator/reverse_iterator.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 547 | #include <__iterator/wrap_iter.h> |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 548 | #include <__memory/allocate_at_least.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 549 | #include <__memory/allocator.h> |
| 550 | #include <__memory/allocator_traits.h> |
| 551 | #include <__memory/compressed_pair.h> |
| 552 | #include <__memory/construct_at.h> |
| 553 | #include <__memory/pointer_traits.h> |
Nikolas Klauser | 35080b4 | 2022-07-26 16:13:56 +0200 | [diff] [blame] | 554 | #include <__memory/swap_allocator.h> |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 555 | #include <__memory_resource/polymorphic_allocator.h> |
Nikolas Klauser | 11a0ff3 | 2022-06-06 23:35:24 +0200 | [diff] [blame] | 556 | #include <__string/char_traits.h> |
| 557 | #include <__string/extern_template_lists.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 558 | #include <__type_traits/is_allocator.h> |
| 559 | #include <__type_traits/noexcept_move_assign_container.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 560 | #include <__utility/auto_cast.h> |
| 561 | #include <__utility/move.h> |
| 562 | #include <__utility/swap.h> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 563 | #include <__utility/unreachable.h> |
| 564 | #include <climits> |
Louis Dionne | 44962c3 | 2022-06-13 11:21:16 -0400 | [diff] [blame] | 565 | #include <cstdint> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 566 | #include <cstdio> // EOF |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 567 | #include <cstdlib> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 568 | #include <cstring> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 569 | #include <limits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 570 | #include <stdexcept> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 571 | #include <string_view> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 572 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 573 | #include <version> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 574 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 575 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 576 | # include <cwchar> |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 577 | #endif |
| 578 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 579 | // standard-mandated includes |
| 580 | |
| 581 | // [iterator.range] |
| 582 | #include <__iterator/access.h> |
| 583 | #include <__iterator/data.h> |
| 584 | #include <__iterator/empty.h> |
| 585 | #include <__iterator/reverse_access.h> |
| 586 | #include <__iterator/size.h> |
| 587 | |
| 588 | // [string.syn] |
| 589 | #include <compare> |
| 590 | #include <initializer_list> |
| 591 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 592 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 593 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 594 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 595 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 596 | _LIBCPP_PUSH_MACROS |
| 597 | #include <__undef_macros> |
| 598 | |
| 599 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 601 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | // basic_string |
| 603 | |
| 604 | template<class _CharT, class _Traits, class _Allocator> |
| 605 | basic_string<_CharT, _Traits, _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 606 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 607 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, |
| 608 | const basic_string<_CharT, _Traits, _Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 609 | |
| 610 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 611 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 612 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 613 | operator+(const _CharT* __x, 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_HIDE_FROM_ABI _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+(_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 | inline _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+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __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 | _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, _CharT __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 630 | 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] | 631 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 632 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 633 | struct __string_is_trivial_iterator : public false_type {}; |
| 634 | |
| 635 | template <class _Tp> |
| 636 | struct __string_is_trivial_iterator<_Tp*> |
| 637 | : public is_arithmetic<_Tp> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 638 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 639 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 640 | struct __string_is_trivial_iterator<__wrap_iter<_Iter> > |
| 641 | : public __string_is_trivial_iterator<_Iter> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 642 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 643 | template <class _CharT, class _Traits, class _Tp> |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 644 | struct __can_be_converted_to_string_view : public _BoolConstant< |
| 645 | is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && |
| 646 | !is_convertible<const _Tp&, const _CharT*>::value |
| 647 | > {}; |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 648 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 649 | struct __uninitialized_size_tag {}; |
| 650 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 651 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame^] | 652 | class basic_string |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 653 | { |
| 654 | public: |
| 655 | typedef basic_string __self; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 656 | typedef basic_string_view<_CharT, _Traits> __self_view; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 657 | typedef _Traits traits_type; |
Marshall Clow | a3a74e0 | 2017-03-15 18:41:11 +0000 | [diff] [blame] | 658 | typedef _CharT value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 659 | typedef _Allocator allocator_type; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 660 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 661 | typedef typename __alloc_traits::size_type size_type; |
| 662 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 663 | typedef value_type& reference; |
| 664 | typedef const value_type& const_reference; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 665 | typedef typename __alloc_traits::pointer pointer; |
| 666 | typedef typename __alloc_traits::const_pointer const_pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 | |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 668 | static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); |
| 669 | static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); |
| 670 | static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); |
| 671 | static_assert(( is_same<_CharT, typename traits_type::char_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 672 | "traits_type::char_type must be the same type as CharT"); |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 673 | static_assert(( is_same<typename allocator_type::value_type, value_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 674 | "Allocator::value_type must be same type as value_type"); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 675 | |
Nikolas Klauser | eb116e2 | 2022-10-08 22:17:32 +0200 | [diff] [blame] | 676 | static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, |
| 677 | "[allocator.requirements] states that rebinding an allocator to the same type should result in the " |
| 678 | "original allocator"); |
| 679 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | typedef __wrap_iter<pointer> iterator; |
| 681 | typedef __wrap_iter<const_pointer> const_iterator; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 682 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 683 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 684 | |
| 685 | private: |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 686 | 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] | 687 | |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 688 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 689 | |
| 690 | struct __long |
| 691 | { |
| 692 | pointer __data_; |
| 693 | size_type __size_; |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 694 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 695 | size_type __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 696 | }; |
| 697 | |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 698 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 699 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 700 | |
| 701 | struct __short |
| 702 | { |
| 703 | value_type __data_[__min_cap]; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 704 | unsigned char __padding_[sizeof(value_type) - 1]; |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 705 | unsigned char __size_ : 7; |
| 706 | unsigned char __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 707 | }; |
| 708 | |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 709 | // 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] | 710 | // 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] | 711 | // |
| 712 | // If the LSB is used to store the short-flag in the short string representation, |
| 713 | // we have to multiply the size by two when it is stored and divide it by two when |
| 714 | // it is loaded to make sure that we always store an even number. In the long string |
| 715 | // representation, we can ignore this because we can assume that we always allocate |
| 716 | // an even amount of value_types. |
| 717 | // |
| 718 | // If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2. |
| 719 | // This does not impact the short string representation, since we never need the MSB |
| 720 | // for representing the size of a short string anyway. |
| 721 | |
| 722 | #ifdef _LIBCPP_BIG_ENDIAN |
| 723 | static const size_type __endian_factor = 2; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 724 | #else |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 725 | static const size_type __endian_factor = 1; |
| 726 | #endif |
| 727 | |
| 728 | #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 729 | |
| 730 | #ifdef _LIBCPP_BIG_ENDIAN |
| 731 | static const size_type __endian_factor = 1; |
| 732 | #else |
| 733 | static const size_type __endian_factor = 2; |
| 734 | #endif |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 735 | |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 736 | // Attribute 'packed' is used to keep the layout compatible with the |
| 737 | // previous definition that did not use bit fields. This is because on |
| 738 | // some platforms bit fields have a default size rather than the actual |
| 739 | // 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] | 740 | struct __long |
| 741 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 742 | struct _LIBCPP_PACKED { |
| 743 | size_type __is_long_ : 1; |
| 744 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 745 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 746 | size_type __size_; |
| 747 | pointer __data_; |
| 748 | }; |
| 749 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 750 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 751 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 752 | |
| 753 | struct __short |
| 754 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 755 | struct _LIBCPP_PACKED { |
| 756 | unsigned char __is_long_ : 1; |
| 757 | unsigned char __size_ : 7; |
| 758 | }; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 759 | char __padding_[sizeof(value_type) - 1]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 760 | value_type __data_[__min_cap]; |
| 761 | }; |
| 762 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 763 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 764 | |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 765 | static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size."); |
| 766 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 767 | union __ulx{__long __lx; __short __lxx;}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 769 | enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 770 | |
| 771 | struct __raw |
| 772 | { |
| 773 | size_type __words[__n_words]; |
| 774 | }; |
| 775 | |
| 776 | struct __rep |
| 777 | { |
| 778 | union |
| 779 | { |
| 780 | __long __l; |
| 781 | __short __s; |
| 782 | __raw __r; |
| 783 | }; |
| 784 | }; |
| 785 | |
| 786 | __compressed_pair<__rep, allocator_type> __r_; |
| 787 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 788 | // Construct a string with the given allocator and enough storage to hold `__size` characters, but |
| 789 | // don't initialize the characters. The contents of the string, including the null terminator, must be |
| 790 | // initialized separately. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 791 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 792 | 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] | 793 | : __r_(__default_init_tag(), __a) { |
| 794 | if (__size > max_size()) |
| 795 | __throw_length_error(); |
| 796 | if (__fits_in_sso(__size)) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 797 | __r_.first() = __rep(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 798 | __set_short_size(__size); |
| 799 | } else { |
| 800 | auto __capacity = __recommend(__size) + 1; |
| 801 | auto __allocation = __alloc_traits::allocate(__alloc(), __capacity); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 802 | __begin_lifetime(__allocation, __capacity); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 803 | __set_long_cap(__capacity); |
| 804 | __set_long_pointer(__allocation); |
| 805 | __set_long_size(__size); |
| 806 | } |
| 807 | std::__debug_db_insert_c(this); |
| 808 | } |
| 809 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 810 | public: |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 811 | _LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 812 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 813 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() |
| 814 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
| 815 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 816 | std::__debug_db_insert_c(this); |
| 817 | __default_init(); |
| 818 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 819 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 820 | _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] | 821 | #if _LIBCPP_STD_VER <= 14 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 822 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 823 | #else |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 824 | _NOEXCEPT |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 825 | #endif |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 826 | : __r_(__default_init_tag(), __a) { |
| 827 | std::__debug_db_insert_c(this); |
| 828 | __default_init(); |
| 829 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 830 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 831 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str); |
| 832 | _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] | 833 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 834 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 835 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str) |
| 836 | # if _LIBCPP_STD_VER <= 14 |
| 837 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
| 838 | # else |
| 839 | _NOEXCEPT |
| 840 | # endif |
| 841 | : __r_(std::move(__str.__r_)) { |
| 842 | __str.__default_init(); |
| 843 | std::__debug_db_insert_c(this); |
| 844 | if (__is_long()) |
| 845 | std::__debug_db_swap(this, &__str); |
| 846 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 847 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 848 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a) |
| 849 | : __r_(__default_init_tag(), __a) { |
| 850 | if (__str.__is_long() && __a != __str.__alloc()) // copy, not move |
| 851 | __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); |
| 852 | else { |
| 853 | if (__libcpp_is_constant_evaluated()) |
| 854 | __r_.first() = __rep(); |
| 855 | __r_.first() = __str.__r_.first(); |
| 856 | __str.__default_init(); |
| 857 | } |
| 858 | std::__debug_db_insert_c(this); |
| 859 | if (__is_long()) |
| 860 | std::__debug_db_swap(this, &__str); |
| 861 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 862 | #endif // _LIBCPP_CXX03_LANG |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 863 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 864 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 865 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) |
| 866 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 867 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); |
| 868 | __init(__s, traits_type::length(__s)); |
| 869 | std::__debug_db_insert_c(this); |
| 870 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 871 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 872 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 873 | _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] | 874 | |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 875 | #if _LIBCPP_STD_VER > 20 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 876 | basic_string(nullptr_t) = delete; |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 877 | #endif |
| 878 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 879 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) |
| 880 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 881 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); |
| 882 | __init(__s, __n); |
| 883 | std::__debug_db_insert_c(this); |
| 884 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 885 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 886 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 887 | basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) |
| 888 | : __r_(__default_init_tag(), __a) { |
| 889 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); |
| 890 | __init(__s, __n); |
| 891 | std::__debug_db_insert_c(this); |
| 892 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 893 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 894 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) |
| 895 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 896 | __init(__n, __c); |
| 897 | std::__debug_db_insert_c(this); |
| 898 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 899 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 900 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 901 | _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] | 902 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 903 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 904 | 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] | 905 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 906 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 907 | basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator()) |
| 908 | : __r_(__default_init_tag(), __a) { |
| 909 | size_type __str_sz = __str.size(); |
| 910 | if (__pos > __str_sz) |
| 911 | __throw_out_of_range(); |
| 912 | __init(__str.data() + __pos, __str_sz - __pos); |
| 913 | std::__debug_db_insert_c(this); |
| 914 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 915 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 916 | template <class _Tp, |
| 917 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 918 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 919 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 920 | basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()); |
| 921 | |
| 922 | template <class _Tp, |
| 923 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 924 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 925 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 926 | const _Tp& __t); |
| 927 | |
| 928 | template <class _Tp, |
| 929 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 930 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 931 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 932 | const _Tp& __t, const allocator_type& __a); |
| 933 | |
| 934 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 935 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) |
| 936 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 937 | __init(__first, __last); |
| 938 | std::__debug_db_insert_c(this); |
| 939 | } |
| 940 | |
| 941 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 942 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 943 | basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) |
| 944 | : __r_(__default_init_tag(), __a) { |
| 945 | __init(__first, __last); |
| 946 | std::__debug_db_insert_c(this); |
| 947 | } |
| 948 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 949 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 950 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) |
| 951 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 952 | __init(__il.begin(), __il.end()); |
| 953 | std::__debug_db_insert_c(this); |
| 954 | } |
| 955 | |
| 956 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a) |
| 957 | : __r_(__default_init_tag(), __a) { |
| 958 | __init(__il.begin(), __il.end()); |
| 959 | std::__debug_db_insert_c(this); |
| 960 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 961 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 962 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 963 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 964 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 965 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 966 | operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } |
| 967 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 968 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const basic_string& __str); |
Eric Fiselier | 5ec13b1 | 2017-01-23 21:24:58 +0000 | [diff] [blame] | 969 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 970 | template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 971 | !__is_same_uncvref<_Tp, basic_string>::value> > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 972 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 973 | __self_view __sv = __t; |
| 974 | return assign(__sv); |
| 975 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 976 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 977 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 978 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 979 | basic_string& operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 980 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 981 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 982 | 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] | 983 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 984 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 985 | basic_string& operator=(const value_type* __s) {return assign(__s);} |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 986 | #if _LIBCPP_STD_VER > 20 |
| 987 | basic_string& operator=(nullptr_t) = delete; |
| 988 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 989 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 990 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 991 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 992 | iterator begin() _NOEXCEPT |
| 993 | {return iterator(this, __get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 994 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 995 | const_iterator begin() const _NOEXCEPT |
| 996 | {return const_iterator(this, __get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 997 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 998 | iterator end() _NOEXCEPT |
| 999 | {return iterator(this, __get_pointer() + size());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1000 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1001 | const_iterator end() const _NOEXCEPT |
| 1002 | {return const_iterator(this, __get_pointer() + size());} |
Louis Dionne | e554e10 | 2022-06-03 15:17:03 -0400 | [diff] [blame] | 1003 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1004 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1005 | reverse_iterator rbegin() _NOEXCEPT |
| 1006 | {return reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1007 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1008 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1009 | {return const_reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1010 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1011 | reverse_iterator rend() _NOEXCEPT |
| 1012 | {return reverse_iterator(begin());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1013 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1014 | const_reverse_iterator rend() const _NOEXCEPT |
| 1015 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1016 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1017 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1018 | const_iterator cbegin() const _NOEXCEPT |
| 1019 | {return begin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1020 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1021 | const_iterator cend() const _NOEXCEPT |
| 1022 | {return end();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1023 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1024 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 1025 | {return rbegin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1026 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1027 | const_reverse_iterator crend() const _NOEXCEPT |
| 1028 | {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1029 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1030 | _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] | 1031 | {return __is_long() ? __get_long_size() : __get_short_size();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1032 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT {return size();} |
| 1033 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT; |
| 1034 | _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] | 1035 | return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1; |
| 1036 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1037 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1038 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n, value_type __c); |
| 1039 | _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] | 1040 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1041 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __requested_capacity); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1042 | |
| 1043 | #if _LIBCPP_STD_VER > 20 |
| 1044 | template <class _Op> |
| 1045 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1046 | void resize_and_overwrite(size_type __n, _Op __op) { |
| 1047 | __resize_default_init(__n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1048 | __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n))); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1049 | } |
| 1050 | #endif |
| 1051 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1052 | _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] | 1053 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1054 | _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] | 1055 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT; |
| 1056 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1057 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1058 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1059 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1060 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1061 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1062 | const_reference operator[](size_type __pos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1063 | _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] | 1064 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1065 | _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const; |
| 1066 | _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1068 | _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] | 1069 | return append(__str); |
| 1070 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1071 | |
| 1072 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1073 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1074 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1075 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1076 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1077 | && !__is_same_uncvref<_Tp, basic_string >::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1078 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1079 | > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1080 | operator+=(const _Tp& __t) { |
| 1081 | __self_view __sv = __t; return append(__sv); |
| 1082 | } |
| 1083 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1084 | _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] | 1085 | return append(__s); |
| 1086 | } |
| 1087 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1088 | _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] | 1089 | push_back(__c); |
| 1090 | return *this; |
| 1091 | } |
| 1092 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1093 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1094 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1095 | basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1096 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1097 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1098 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1099 | basic_string& append(const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1100 | |
| 1101 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1102 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1103 | __enable_if_t< |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1104 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1105 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1106 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1107 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1108 | 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] | 1109 | _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] | 1110 | |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 1111 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1112 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1113 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1114 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1115 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1116 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1117 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1118 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1119 | append(const _Tp& __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1120 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n); |
| 1121 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s); |
| 1122 | _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] | 1123 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1124 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1125 | void __append_default_init(size_type __n); |
| 1126 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | template<class _InputIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1128 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1129 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1130 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1131 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1132 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1133 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1134 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1135 | append(_InputIterator __first, _InputIterator __last) { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1136 | const basic_string __temp(__first, __last, __alloc()); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1137 | append(__temp.data(), __temp.size()); |
| 1138 | return *this; |
| 1139 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1140 | template<class _ForwardIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1141 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1142 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1143 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1144 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1145 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1146 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1147 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1148 | append(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1149 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1150 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1151 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1152 | 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] | 1153 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1154 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1155 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(value_type __c); |
| 1156 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back(); |
| 1157 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() _NOEXCEPT; |
| 1158 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _NOEXCEPT; |
| 1159 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _NOEXCEPT; |
| 1160 | _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] | 1161 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1162 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1163 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1164 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1165 | < |
| 1166 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1167 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1168 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1169 | 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] | 1170 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 95d5e9a | 2016-03-09 18:08:29 +0000 | [diff] [blame] | 1171 | basic_string& assign(const basic_string& __str) { return *this = __str; } |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1172 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1173 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1174 | basic_string& assign(basic_string&& __str) |
Marshall Clow | 5aa9e94 | 2015-10-05 16:17:34 +0000 | [diff] [blame] | 1175 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1176 | {*this = std::move(__str); return *this;} |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1177 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1178 | _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] | 1179 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1180 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1181 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1182 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1183 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1184 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1185 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1186 | > |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1187 | assign(const _Tp & __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1188 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s, size_type __n); |
| 1189 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s); |
| 1190 | _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] | 1191 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1192 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1193 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1194 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1195 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1196 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1197 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | assign(_InputIterator __first, _InputIterator __last); |
| 1199 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1200 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1201 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1202 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1203 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1204 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1205 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1206 | assign(_ForwardIterator __first, _ForwardIterator __last); |
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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1209 | 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] | 1210 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1211 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1212 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1213 | basic_string& insert(size_type __pos1, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1214 | |
| 1215 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1216 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1217 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1218 | < |
| 1219 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1220 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1221 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1222 | insert(size_type __pos1, const _Tp& __t) |
| 1223 | { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); } |
| 1224 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1225 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1226 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1227 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1228 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1229 | __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] | 1230 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1231 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1232 | 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] | 1233 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1234 | 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] | 1235 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s, size_type __n); |
| 1236 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s); |
| 1237 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c); |
| 1238 | _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c); |
| 1239 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1240 | iterator insert(const_iterator __pos, size_type __n, value_type __c); |
| 1241 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1242 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1243 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1244 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1245 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1246 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1247 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1248 | insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); |
| 1249 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1250 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1251 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1252 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1253 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1254 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1255 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1256 | insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1257 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1258 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1259 | iterator insert(const_iterator __pos, initializer_list<value_type> __il) |
| 1260 | {return insert(__pos, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1261 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1263 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos); |
| 1264 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1265 | iterator erase(const_iterator __pos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1266 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1267 | iterator erase(const_iterator __first, const_iterator __last); |
| 1268 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1269 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1270 | 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] | 1271 | |
| 1272 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1273 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1274 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1275 | < |
| 1276 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1277 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1278 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1279 | 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] | 1280 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1281 | 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] | 1282 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1283 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1284 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1285 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1286 | __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] | 1287 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1288 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1289 | 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] | 1290 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1291 | 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] | 1292 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); |
| 1293 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); |
| 1294 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1295 | 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] | 1296 | |
| 1297 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1298 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1299 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1300 | < |
| 1301 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1302 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1303 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1304 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); } |
| 1305 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1306 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1307 | 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] | 1308 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1309 | 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] | 1310 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1311 | 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] | 1312 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1313 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1314 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1315 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1316 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1317 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1318 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1319 | replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1320 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1321 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1322 | 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] | 1323 | {return replace(__i1, __i2, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1324 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1326 | _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; |
| 1327 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1328 | basic_string substr(size_type __pos = 0, size_type __n = npos) const; |
| 1329 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1330 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1331 | void swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1332 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1333 | _NOEXCEPT; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1334 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1335 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1336 | __is_nothrow_swappable<allocator_type>::value); |
| 1337 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1339 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1340 | const value_type* c_str() const _NOEXCEPT {return data();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1341 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1342 | const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());} |
Eric Fiselier | 4ee2a89 | 2017-11-20 20:23:27 +0000 | [diff] [blame] | 1343 | #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1344 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1345 | value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());} |
Marshall Clow | d3c2239 | 2016-03-08 15:44:30 +0000 | [diff] [blame] | 1346 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1347 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1348 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1349 | allocator_type get_allocator() const _NOEXCEPT {return __alloc();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1350 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1351 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1352 | 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] | 1353 | |
| 1354 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1355 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1356 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1357 | < |
| 1358 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1359 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1360 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1361 | find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1362 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1363 | 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] | 1364 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1365 | 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] | 1366 | _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] | 1367 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1368 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1369 | 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] | 1370 | |
| 1371 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1372 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1373 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1374 | < |
| 1375 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1376 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1377 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1378 | rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1379 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1380 | 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] | 1381 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1382 | 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] | 1383 | _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] | 1384 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1385 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1386 | 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] | 1387 | |
| 1388 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1389 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1390 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1391 | < |
| 1392 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1393 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1394 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1395 | find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1396 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1397 | 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] | 1398 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1399 | 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] | 1400 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1401 | 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] | 1402 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1403 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1404 | 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] | 1405 | |
| 1406 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1407 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1408 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1409 | < |
| 1410 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1411 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1412 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1413 | find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1414 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1415 | 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] | 1416 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1417 | 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] | 1418 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1419 | 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] | 1420 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1421 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1422 | 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] | 1423 | |
| 1424 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1425 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1426 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1427 | < |
| 1428 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1429 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1430 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1431 | 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] | 1432 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1433 | 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] | 1434 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1435 | 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] | 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_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
| 1438 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1439 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1440 | 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] | 1441 | |
| 1442 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1443 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1444 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1445 | < |
| 1446 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1447 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1448 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1449 | 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] | 1450 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1451 | 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] | 1452 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1453 | 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] | 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_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
| 1456 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1457 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1458 | int compare(const basic_string& __str) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1459 | |
| 1460 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1461 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1462 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1463 | < |
| 1464 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1465 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1466 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1467 | compare(const _Tp &__t) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1468 | |
| 1469 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1470 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1471 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1472 | < |
| 1473 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1474 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1475 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1476 | compare(size_type __pos1, size_type __n1, const _Tp& __t) const; |
| 1477 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1478 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1479 | 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] | 1480 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1481 | int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, |
| 1482 | size_type __n2 = npos) const; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1483 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1484 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1485 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1486 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1487 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1488 | __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] | 1489 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1490 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1491 | 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] | 1492 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* __s) const _NOEXCEPT; |
| 1493 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(size_type __pos1, size_type __n1, const value_type* __s) const; |
| 1494 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1495 | 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] | 1496 | |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1497 | #if _LIBCPP_STD_VER > 17 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1498 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1499 | bool starts_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1500 | { return __self_view(data(), size()).starts_with(__sv); } |
| 1501 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1502 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1503 | bool starts_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1504 | { return !empty() && _Traits::eq(front(), __c); } |
| 1505 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1506 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1507 | bool starts_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1508 | { return starts_with(__self_view(__s)); } |
| 1509 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1510 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1511 | bool ends_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1512 | { return __self_view(data(), size()).ends_with( __sv); } |
| 1513 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1514 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1515 | bool ends_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1516 | { return !empty() && _Traits::eq(back(), __c); } |
| 1517 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1518 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1519 | bool ends_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1520 | { return ends_with(__self_view(__s)); } |
| 1521 | #endif |
| 1522 | |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1523 | #if _LIBCPP_STD_VER > 20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1524 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1525 | bool contains(__self_view __sv) const noexcept |
| 1526 | { return __self_view(data(), size()).contains(__sv); } |
| 1527 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1528 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1529 | bool contains(value_type __c) const noexcept |
| 1530 | { return __self_view(data(), size()).contains(__c); } |
| 1531 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1532 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1533 | bool contains(const value_type* __s) const |
| 1534 | { return __self_view(data(), size()).contains(__s); } |
| 1535 | #endif |
| 1536 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1537 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1538 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1539 | _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] | 1540 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1541 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1542 | |
| 1543 | bool __dereferenceable(const const_iterator* __i) const; |
| 1544 | bool __decrementable(const const_iterator* __i) const; |
| 1545 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1546 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1547 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1548 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1549 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1550 | private: |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1551 | template<class _Alloc> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1552 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1553 | bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs, |
| 1554 | const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT; |
| 1555 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1556 | _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] | 1557 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1558 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1559 | bool __is_long() const _NOEXCEPT { |
| 1560 | if (__libcpp_is_constant_evaluated()) |
| 1561 | return true; |
| 1562 | return __r_.first().__s.__is_long_; |
| 1563 | } |
| 1564 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1565 | 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] | 1566 | #if _LIBCPP_STD_VER > 17 |
| 1567 | if (__libcpp_is_constant_evaluated()) { |
| 1568 | for (size_type __i = 0; __i != __n; ++__i) |
| 1569 | std::construct_at(std::addressof(__begin[__i])); |
| 1570 | } |
| 1571 | #else |
| 1572 | (void)__begin; |
| 1573 | (void)__n; |
| 1574 | #endif // _LIBCPP_STD_VER > 17 |
| 1575 | } |
| 1576 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1577 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init() { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1578 | __r_.first() = __rep(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1579 | if (__libcpp_is_constant_evaluated()) { |
| 1580 | size_type __sz = __recommend(0) + 1; |
| 1581 | pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); |
| 1582 | __begin_lifetime(__ptr, __sz); |
| 1583 | __set_long_pointer(__ptr); |
| 1584 | __set_long_cap(__sz); |
| 1585 | __set_long_size(0); |
| 1586 | } |
| 1587 | } |
| 1588 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1589 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_constexpr() { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1590 | if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr) |
| 1591 | __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap()); |
| 1592 | } |
| 1593 | |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1594 | _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { |
| 1595 | // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly |
| 1596 | return !__libcpp_is_constant_evaluated() && (__sz < __min_cap); |
| 1597 | } |
| 1598 | |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1599 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1600 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1601 | iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) { |
| 1602 | size_type __sz = size(); |
| 1603 | size_type __cap = capacity(); |
| 1604 | value_type* __p; |
| 1605 | if (__cap - __sz >= __n) |
| 1606 | { |
| 1607 | __p = std::__to_address(__get_pointer()); |
| 1608 | size_type __n_move = __sz - __ip; |
| 1609 | if (__n_move != 0) |
| 1610 | traits_type::move(__p + __ip + __n, __p + __ip, __n_move); |
| 1611 | } |
| 1612 | else |
| 1613 | { |
| 1614 | __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); |
| 1615 | __p = std::__to_address(__get_long_pointer()); |
| 1616 | } |
| 1617 | __sz += __n; |
| 1618 | __set_size(__sz); |
| 1619 | traits_type::assign(__p[__sz], value_type()); |
| 1620 | for (__p += __ip; __first != __last; ++__p, ++__first) |
| 1621 | traits_type::assign(*__p, *__first); |
| 1622 | |
| 1623 | return begin() + __ip; |
| 1624 | } |
| 1625 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1626 | _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] | 1627 | _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] | 1628 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1629 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1630 | void __set_short_size(size_type __s) _NOEXCEPT { |
| 1631 | _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity"); |
| 1632 | __r_.first().__s.__size_ = __s; |
| 1633 | __r_.first().__s.__is_long_ = false; |
| 1634 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1635 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1636 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1637 | size_type __get_short_size() const _NOEXCEPT { |
| 1638 | _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); |
| 1639 | return __r_.first().__s.__size_; |
| 1640 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1641 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1642 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1643 | void __set_long_size(size_type __s) _NOEXCEPT |
| 1644 | {__r_.first().__l.__size_ = __s;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1645 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1646 | size_type __get_long_size() const _NOEXCEPT |
| 1647 | {return __r_.first().__l.__size_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1648 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1649 | void __set_size(size_type __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} |
| 1651 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1652 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1653 | void __set_long_cap(size_type __s) _NOEXCEPT { |
| 1654 | __r_.first().__l.__cap_ = __s / __endian_factor; |
| 1655 | __r_.first().__l.__is_long_ = true; |
| 1656 | } |
| 1657 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1658 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1659 | size_type __get_long_cap() const _NOEXCEPT { |
| 1660 | return __r_.first().__l.__cap_ * __endian_factor; |
| 1661 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1662 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1663 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1664 | void __set_long_pointer(pointer __p) _NOEXCEPT |
| 1665 | {__r_.first().__l.__data_ = __p;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1666 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1667 | pointer __get_long_pointer() _NOEXCEPT |
| 1668 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1669 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1670 | const_pointer __get_long_pointer() const _NOEXCEPT |
| 1671 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1672 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1673 | pointer __get_short_pointer() _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1674 | {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1675 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1676 | const_pointer __get_short_pointer() const _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1677 | {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1678 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1679 | pointer __get_pointer() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1680 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1681 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1682 | const_pointer __get_pointer() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
| 1684 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1685 | template <size_type __a> static |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1686 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 1687 | size_type __align_it(size_type __s) _NOEXCEPT |
Eric Fiselier | 8599fcc | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 1688 | {return (__s + (__a-1)) & ~(__a-1);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1689 | enum {__alignment = 16}; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1690 | static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1691 | size_type __recommend(size_type __s) _NOEXCEPT |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1692 | { |
| 1693 | if (__s < __min_cap) { |
| 1694 | if (__libcpp_is_constant_evaluated()) |
| 1695 | return static_cast<size_type>(__min_cap); |
| 1696 | else |
| 1697 | return static_cast<size_type>(__min_cap) - 1; |
| 1698 | } |
Marshall Clow | 8058452 | 2018-02-07 21:30:17 +0000 | [diff] [blame] | 1699 | size_type __guess = __align_it<sizeof(value_type) < __alignment ? |
| 1700 | __alignment/sizeof(value_type) : 1 > (__s+1) - 1; |
| 1701 | if (__guess == __min_cap) ++__guess; |
| 1702 | return __guess; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1703 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1704 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1705 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1706 | void __init(const value_type* __s, size_type __sz, size_type __reserve); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1707 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1708 | void __init(const value_type* __s, size_type __sz); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1709 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1710 | void __init(size_type __n, value_type __c); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1711 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 1712 | // Slow path for the (inlined) copy constructor for 'long' strings. |
| 1713 | // Always externally instantiated and not inlined. |
| 1714 | // Requires that __s is zero terminated. |
| 1715 | // The main reason for this function to exist is because for unstable, we |
| 1716 | // want to allow inlining of the copy constructor. However, we don't want |
| 1717 | // to call the __init() functions as those are marked as inline which may |
| 1718 | // result in over-aggressive inlining by the compiler, where our aim is |
| 1719 | // to only inline the fast path code directly in the ctor. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1720 | _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] | 1721 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1722 | template <class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1723 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1724 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1725 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1726 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 1727 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1728 | __init(_InputIterator __first, _InputIterator __last); |
| 1729 | |
| 1730 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1731 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1732 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1733 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1734 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 1735 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1736 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 1737 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1738 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1739 | 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] | 1740 | 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] | 1741 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1742 | void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 1743 | size_type __n_copy, size_type __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1744 | size_type __n_add, const value_type* __p_new_stuff); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 1746 | // __assign_no_alias is invoked for assignment operations where we |
| 1747 | // have proof that the input does not alias the current instance. |
| 1748 | // For example, operator=(basic_string) performs a 'self' check. |
| 1749 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1750 | _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] | 1751 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1752 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1753 | void __erase_to_end(size_type __pos); |
| 1754 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 1755 | // __erase_external_with_move is invoked for erase() invocations where |
| 1756 | // `n ~= npos`, likely requiring memory moves on the string data. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1757 | _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] | 1758 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1759 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1760 | void __copy_assign_alloc(const basic_string& __str) |
| 1761 | {__copy_assign_alloc(__str, integral_constant<bool, |
| 1762 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 1763 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1764 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1765 | void __copy_assign_alloc(const basic_string& __str, true_type) |
| 1766 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1767 | if (__alloc() == __str.__alloc()) |
| 1768 | __alloc() = __str.__alloc(); |
| 1769 | else |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1770 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1771 | if (!__str.__is_long()) |
| 1772 | { |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 1773 | __clear_and_shrink(); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1774 | __alloc() = __str.__alloc(); |
| 1775 | } |
| 1776 | else |
| 1777 | { |
| 1778 | allocator_type __a = __str.__alloc(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1779 | auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap()); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1780 | __begin_lifetime(__allocation.ptr, __allocation.count); |
Nikolas Klauser | 1821ec3 | 2022-10-01 15:37:24 +0200 | [diff] [blame] | 1781 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1782 | __alloc() = std::move(__a); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1783 | __set_long_pointer(__allocation.ptr); |
| 1784 | __set_long_cap(__allocation.count); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1785 | __set_long_size(__str.size()); |
| 1786 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1787 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1790 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1791 | void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1792 | {} |
| 1793 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1794 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1795 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1796 | void __move_assign(basic_string& __str, false_type) |
| 1797 | _NOEXCEPT_(__alloc_traits::is_always_equal::value); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1798 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1799 | void __move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1800 | #if _LIBCPP_STD_VER > 14 |
| 1801 | _NOEXCEPT; |
| 1802 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1803 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1804 | #endif |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1805 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1806 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1807 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1808 | void |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1809 | __move_assign_alloc(basic_string& __str) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1810 | _NOEXCEPT_( |
| 1811 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 1812 | is_nothrow_move_assignable<allocator_type>::value) |
| 1813 | {__move_assign_alloc(__str, integral_constant<bool, |
| 1814 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 1815 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1816 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1817 | void __move_assign_alloc(basic_string& __c, true_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1818 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
| 1819 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1820 | __alloc() = std::move(__c.__alloc()); |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1823 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1824 | void __move_assign_alloc(basic_string&, false_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1825 | _NOEXCEPT |
| 1826 | {} |
| 1827 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1828 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s); |
| 1829 | _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] | 1830 | |
| 1831 | // Assigns the value in __s, guaranteed to be __n < __min_cap in length. |
| 1832 | inline basic_string& __assign_short(const value_type* __s, size_type __n) { |
| 1833 | pointer __p = __is_long() |
| 1834 | ? (__set_long_size(__n), __get_long_pointer()) |
| 1835 | : (__set_short_size(__n), __get_short_pointer()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1836 | traits_type::move(std::__to_address(__p), __s, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 1837 | traits_type::assign(__p[__n], value_type()); |
| 1838 | return *this; |
| 1839 | } |
| 1840 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1841 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1842 | basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 1843 | __set_size(__newsz); |
| 1844 | __invalidate_iterators_past(__newsz); |
| 1845 | traits_type::assign(__p[__newsz], value_type()); |
| 1846 | return *this; |
| 1847 | } |
| 1848 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1849 | _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] | 1850 | |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1851 | template<class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1852 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1853 | bool __addr_in_range(_Tp&& __t) const { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1854 | // assume that the ranges overlap, because we can't check during constant evaluation |
| 1855 | if (__libcpp_is_constant_evaluated()) |
| 1856 | return true; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1857 | const volatile void *__p = std::addressof(__t); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1858 | return data() <= __p && __p <= data() + size(); |
| 1859 | } |
| 1860 | |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1861 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1862 | void __throw_length_error() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1863 | std::__throw_length_error("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1867 | void __throw_out_of_range() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1868 | std::__throw_out_of_range("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1869 | } |
| 1870 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1871 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const basic_string&); |
| 1872 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const value_type*, const basic_string&); |
| 1873 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(value_type, const basic_string&); |
| 1874 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const value_type*); |
| 1875 | 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] | 1876 | }; |
| 1877 | |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1878 | // These declarations must appear before any functions are implicitly used |
| 1879 | // so that they have the correct visibility specifier. |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1880 | #define _LIBCPP_DECLARE(...) extern template __VA_ARGS__; |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1881 | #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1882 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1883 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1884 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1885 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1886 | #else |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1887 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1888 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1889 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1890 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1891 | #endif |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1892 | #undef _LIBCPP_DECLARE |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1893 | |
| 1894 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 1895 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1896 | template<class _InputIterator, |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 1897 | class _CharT = __iter_value_type<_InputIterator>, |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1898 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1899 | class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
| 1900 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1901 | > |
| 1902 | basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 1903 | -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1904 | |
| 1905 | template<class _CharT, |
| 1906 | class _Traits, |
| 1907 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1908 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1909 | > |
| 1910 | explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) |
| 1911 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 1912 | |
| 1913 | template<class _CharT, |
| 1914 | class _Traits, |
| 1915 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1916 | class = enable_if_t<__is_allocator<_Allocator>::value>, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1917 | class _Sz = typename allocator_traits<_Allocator>::size_type |
| 1918 | > |
| 1919 | basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) |
| 1920 | -> basic_string<_CharT, _Traits, _Allocator>; |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1921 | #endif |
| 1922 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1923 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1924 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1925 | void |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1926 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1927 | { |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1928 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1929 | if (!__libcpp_is_constant_evaluated()) { |
| 1930 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1931 | if (__c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1932 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1933 | const_pointer __new_last = __get_pointer() + __pos; |
| 1934 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1935 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1936 | --__p; |
| 1937 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 1938 | if (__i->base() > __new_last) |
| 1939 | { |
| 1940 | (*__p)->__c_ = nullptr; |
| 1941 | if (--__c->end_ != __p) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1942 | std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1943 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1944 | } |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1945 | __get_db()->unlock(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1946 | } |
| 1947 | } |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1948 | #else |
| 1949 | (void)__pos; |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1950 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1954 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1955 | void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, |
| 1956 | size_type __sz, |
| 1957 | size_type __reserve) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1958 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1959 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1960 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1961 | if (__reserve > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 1962 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1963 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1964 | if (__fits_in_sso(__reserve)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1965 | { |
| 1966 | __set_short_size(__sz); |
| 1967 | __p = __get_short_pointer(); |
| 1968 | } |
| 1969 | else |
| 1970 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1971 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1); |
| 1972 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1973 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1974 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1975 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1976 | __set_long_size(__sz); |
| 1977 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1978 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1979 | traits_type::assign(__p[__sz], value_type()); |
| 1980 | } |
| 1981 | |
| 1982 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1983 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1984 | void |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1985 | 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] | 1986 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1987 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1988 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1989 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 1990 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1991 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1992 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1993 | { |
| 1994 | __set_short_size(__sz); |
| 1995 | __p = __get_short_pointer(); |
| 1996 | } |
| 1997 | else |
| 1998 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1999 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2000 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2001 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2002 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2003 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2004 | __set_long_size(__sz); |
| 2005 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2006 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2007 | traits_type::assign(__p[__sz], value_type()); |
| 2008 | } |
| 2009 | |
| 2010 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2011 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2012 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2013 | 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] | 2014 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2015 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2016 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2017 | __init(__s, traits_type::length(__s)); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2018 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
| 2021 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2022 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2023 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2024 | : __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] | 2025 | { |
| 2026 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2027 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2028 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2029 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2030 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2031 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2035 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2036 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
| 2037 | const basic_string& __str, const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2038 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2039 | { |
| 2040 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2041 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2042 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2043 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2044 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2045 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2046 | } |
| 2047 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2048 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2049 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2050 | void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( |
| 2051 | const value_type* __s, size_type __sz) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2052 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2053 | __r_.first() = __rep(); |
| 2054 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2055 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2056 | if (__fits_in_sso(__sz)) { |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2057 | __p = __get_short_pointer(); |
| 2058 | __set_short_size(__sz); |
| 2059 | } else { |
| 2060 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2061 | __throw_length_error(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2062 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2063 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2064 | __begin_lifetime(__p, __allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2065 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2066 | __set_long_cap(__allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2067 | __set_long_size(__sz); |
| 2068 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2069 | traits_type::copy(std::__to_address(__p), __s, __sz + 1); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2070 | } |
| 2071 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | void |
| 2075 | basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) |
| 2076 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2077 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2078 | __r_.first() = __rep(); |
| 2079 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2080 | if (__n > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2081 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2082 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2083 | if (__fits_in_sso(__n)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2084 | { |
| 2085 | __set_short_size(__n); |
| 2086 | __p = __get_short_pointer(); |
| 2087 | } |
| 2088 | else |
| 2089 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2090 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1); |
| 2091 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2092 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2093 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2094 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2095 | __set_long_size(__n); |
| 2096 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2097 | traits_type::assign(std::__to_address(__p), __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2098 | traits_type::assign(__p[__n], value_type()); |
| 2099 | } |
| 2100 | |
| 2101 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2102 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2103 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2104 | 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] | 2105 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2106 | { |
| 2107 | __init(__n, __c); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2108 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2112 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2113 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, |
| 2114 | size_type __pos, size_type __n, |
| 2115 | const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2116 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | { |
| 2118 | size_type __str_sz = __str.size(); |
| 2119 | if (__pos > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2120 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2121 | __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); |
| 2122 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2126 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2127 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2128 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2129 | 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] | 2130 | : __r_(__default_init_tag(), __a) |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2131 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2132 | __self_view __sv0 = __t; |
| 2133 | __self_view __sv = __sv0.substr(__pos, __n); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2134 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2135 | std::__debug_db_insert_c(this); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2139 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2140 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2141 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2142 | : __r_(__default_init_tag(), __default_init_tag()) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2143 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2144 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2145 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2146 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2150 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2151 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2152 | 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] | 2153 | : __r_(__default_init_tag(), __a) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2154 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2155 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2156 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2157 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2161 | template <class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2162 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2163 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2164 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2165 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 2166 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2167 | basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) |
| 2168 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2169 | __default_init(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2170 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2171 | try |
| 2172 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2173 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2174 | for (; __first != __last; ++__first) |
| 2175 | push_back(*__first); |
| 2176 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2177 | } |
| 2178 | catch (...) |
| 2179 | { |
| 2180 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2181 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2182 | throw; |
| 2183 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2184 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | template <class _CharT, class _Traits, class _Allocator> |
| 2188 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2189 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2190 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2191 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2192 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 2193 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2194 | basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 2195 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2196 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2197 | __r_.first() = __rep(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2198 | size_type __sz = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2199 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2200 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2201 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2202 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2203 | { |
| 2204 | __set_short_size(__sz); |
| 2205 | __p = __get_short_pointer(); |
| 2206 | } |
| 2207 | else |
| 2208 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2209 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2210 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2211 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2212 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2213 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2214 | __set_long_size(__sz); |
| 2215 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2216 | |
| 2217 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2218 | try |
| 2219 | { |
| 2220 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | a09a3b4 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 2221 | for (; __first != __last; ++__first, (void) ++__p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2222 | traits_type::assign(*__p, *__first); |
| 2223 | traits_type::assign(*__p, value_type()); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2224 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2225 | } |
| 2226 | catch (...) |
| 2227 | { |
| 2228 | if (__is_long()) |
| 2229 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
| 2230 | throw; |
| 2231 | } |
| 2232 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
| 2235 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2236 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2237 | basic_string<_CharT, _Traits, _Allocator>::~basic_string() |
| 2238 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 2239 | std::__debug_db_erase_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2240 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2241 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
| 2244 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2245 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2246 | void |
| 2247 | basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace |
| 2248 | (size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2249 | 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] | 2250 | { |
| 2251 | size_type __ms = max_size(); |
| 2252 | if (__delta_cap > __ms - __old_cap - 1) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2253 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2254 | pointer __old_p = __get_pointer(); |
| 2255 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2256 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2257 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2258 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2259 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2260 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2261 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2262 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2263 | traits_type::copy(std::__to_address(__p), |
| 2264 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2265 | if (__n_add != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2266 | 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] | 2267 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2268 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2269 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2270 | std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2271 | if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2272 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2273 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2274 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2275 | __old_sz = __n_copy + __n_add + __sec_cp_sz; |
| 2276 | __set_long_size(__old_sz); |
| 2277 | traits_type::assign(__p[__old_sz], value_type()); |
| 2278 | } |
| 2279 | |
| 2280 | template <class _CharT, class _Traits, class _Allocator> |
| 2281 | void |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2282 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2283 | basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 2284 | size_type __n_copy, size_type __n_del, size_type __n_add) |
| 2285 | { |
| 2286 | size_type __ms = max_size(); |
Marshall Clow | 2267c5d | 2013-11-06 14:24:38 +0000 | [diff] [blame] | 2287 | if (__delta_cap > __ms - __old_cap) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2288 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2289 | pointer __old_p = __get_pointer(); |
| 2290 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2291 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2292 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2293 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2294 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2295 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2296 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2297 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2298 | traits_type::copy(std::__to_address(__p), |
| 2299 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2300 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2301 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2302 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2303 | std::__to_address(__old_p) + __n_copy + __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2304 | __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2305 | if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap) |
| 2306 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2307 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2308 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | // assign |
| 2312 | |
| 2313 | template <class _CharT, class _Traits, class _Allocator> |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2314 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2315 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2316 | basic_string<_CharT, _Traits, _Allocator>& |
| 2317 | basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias( |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2318 | const value_type* __s, size_type __n) { |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2319 | 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] | 2320 | if (__n < __cap) { |
| 2321 | pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer(); |
| 2322 | __is_short ? __set_short_size(__n) : __set_long_size(__n); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2323 | traits_type::copy(std::__to_address(__p), __s, __n); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2324 | traits_type::assign(__p[__n], value_type()); |
| 2325 | __invalidate_iterators_past(__n); |
| 2326 | } else { |
| 2327 | size_type __sz = __is_short ? __get_short_size() : __get_long_size(); |
| 2328 | __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s); |
| 2329 | } |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2330 | return *this; |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2334 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2335 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2336 | basic_string<_CharT, _Traits, _Allocator>::__assign_external( |
| 2337 | const value_type* __s, size_type __n) { |
| 2338 | size_type __cap = capacity(); |
| 2339 | if (__cap >= __n) { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2340 | value_type* __p = std::__to_address(__get_pointer()); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2341 | traits_type::move(__p, __s, __n); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2342 | return __null_terminate_at(__p, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2343 | } else { |
| 2344 | size_type __sz = size(); |
| 2345 | __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2346 | return *this; |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2347 | } |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2351 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2352 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2353 | 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] | 2354 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2355 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2356 | return (__builtin_constant_p(__n) && __fits_in_sso(__n)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2357 | ? __assign_short(__s, __n) |
| 2358 | : __assign_external(__s, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2362 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2363 | basic_string<_CharT, _Traits, _Allocator>& |
| 2364 | basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) |
| 2365 | { |
| 2366 | size_type __cap = capacity(); |
| 2367 | if (__cap < __n) |
| 2368 | { |
| 2369 | size_type __sz = size(); |
| 2370 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2371 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2372 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2373 | traits_type::assign(__p, __n, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2374 | return __null_terminate_at(__p, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2378 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2379 | basic_string<_CharT, _Traits, _Allocator>& |
| 2380 | basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) |
| 2381 | { |
| 2382 | pointer __p; |
| 2383 | if (__is_long()) |
| 2384 | { |
| 2385 | __p = __get_long_pointer(); |
| 2386 | __set_long_size(1); |
| 2387 | } |
| 2388 | else |
| 2389 | { |
| 2390 | __p = __get_short_pointer(); |
| 2391 | __set_short_size(1); |
| 2392 | } |
| 2393 | traits_type::assign(*__p, __c); |
| 2394 | traits_type::assign(*++__p, value_type()); |
| 2395 | __invalidate_iterators_past(1); |
| 2396 | return *this; |
| 2397 | } |
| 2398 | |
| 2399 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2400 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2401 | basic_string<_CharT, _Traits, _Allocator>& |
| 2402 | basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) |
| 2403 | { |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2404 | if (this != &__str) { |
| 2405 | __copy_assign_alloc(__str); |
| 2406 | if (!__is_long()) { |
| 2407 | if (!__str.__is_long()) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2408 | __r_.first() = __str.__r_.first(); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2409 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2410 | return __assign_no_alias<true>(__str.data(), __str.size()); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2411 | } |
| 2412 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2413 | return __assign_no_alias<false>(__str.data(), __str.size()); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2414 | } |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2415 | } |
| 2416 | return *this; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 2419 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2420 | |
| 2421 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2422 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2423 | void |
| 2424 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2425 | _NOEXCEPT_(__alloc_traits::is_always_equal::value) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2426 | { |
| 2427 | if (__alloc() != __str.__alloc()) |
| 2428 | assign(__str); |
| 2429 | else |
| 2430 | __move_assign(__str, true_type()); |
| 2431 | } |
| 2432 | |
| 2433 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2434 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2435 | void |
| 2436 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2437 | #if _LIBCPP_STD_VER > 14 |
| 2438 | _NOEXCEPT |
| 2439 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2440 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2441 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2442 | { |
marshall | 2ed4162 | 2019-11-27 07:13:00 -0800 | [diff] [blame] | 2443 | if (__is_long()) { |
| 2444 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), |
| 2445 | __get_long_cap()); |
| 2446 | #if _LIBCPP_STD_VER <= 14 |
| 2447 | if (!is_nothrow_move_assignable<allocator_type>::value) { |
| 2448 | __set_short_size(0); |
| 2449 | traits_type::assign(__get_short_pointer()[0], value_type()); |
| 2450 | } |
| 2451 | #endif |
| 2452 | } |
| 2453 | __move_assign_alloc(__str); |
| 2454 | __r_.first() = __str.__r_.first(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2455 | if (__libcpp_is_constant_evaluated()) { |
| 2456 | __str.__default_init(); |
| 2457 | } else { |
| 2458 | __str.__set_short_size(0); |
| 2459 | traits_type::assign(__str.__get_short_pointer()[0], value_type()); |
| 2460 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2464 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2465 | basic_string<_CharT, _Traits, _Allocator>& |
| 2466 | basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2467 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2468 | { |
| 2469 | __move_assign(__str, integral_constant<bool, |
| 2470 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 2471 | return *this; |
| 2472 | } |
| 2473 | |
| 2474 | #endif |
| 2475 | |
| 2476 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2477 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2478 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2479 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2480 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2481 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2482 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2483 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2484 | basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2485 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2486 | const basic_string __temp(__first, __last, __alloc()); |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2487 | assign(__temp.data(), __temp.size()); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2488 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | template <class _CharT, class _Traits, class _Allocator> |
| 2492 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2493 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2494 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2495 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2496 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2497 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2498 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2499 | basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2500 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2501 | size_type __cap = capacity(); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2502 | size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2503 | static_cast<size_type>(std::distance(__first, __last)) : 0; |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2504 | |
| 2505 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2506 | (__cap >= __n || !__addr_in_range(*__first))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2507 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2508 | if (__cap < __n) |
| 2509 | { |
| 2510 | size_type __sz = size(); |
| 2511 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2512 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2513 | pointer __p = __get_pointer(); |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2514 | for (; __first != __last; ++__p, (void) ++__first) |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2515 | traits_type::assign(*__p, *__first); |
| 2516 | traits_type::assign(*__p, value_type()); |
| 2517 | __set_size(__n); |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 2518 | __invalidate_iterators_past(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2519 | } |
| 2520 | else |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2521 | { |
| 2522 | const basic_string __temp(__first, __last, __alloc()); |
| 2523 | assign(__temp.data(), __temp.size()); |
| 2524 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2525 | return *this; |
| 2526 | } |
| 2527 | |
| 2528 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2529 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2530 | basic_string<_CharT, _Traits, _Allocator>& |
| 2531 | basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) |
| 2532 | { |
| 2533 | size_type __sz = __str.size(); |
| 2534 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2535 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2536 | return assign(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2540 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2541 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2542 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2543 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2544 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 2545 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 2546 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2547 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2548 | 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] | 2549 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2550 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2551 | size_type __sz = __sv.size(); |
| 2552 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2553 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2554 | return assign(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | |
| 2558 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2559 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2560 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2561 | basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) { |
| 2562 | return __assign_external(__s, traits_type::length(__s)); |
| 2563 | } |
| 2564 | |
| 2565 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2566 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2567 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2568 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2569 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2570 | _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); |
Louis Dionne | 3e0c433 | 2021-08-31 10:49:06 -0400 | [diff] [blame] | 2571 | return __builtin_constant_p(*__s) |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2572 | ? (__fits_in_sso(traits_type::length(__s)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2573 | ? __assign_short(__s, traits_type::length(__s)) |
| 2574 | : __assign_external(__s, traits_type::length(__s))) |
| 2575 | : __assign_external(__s); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2576 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2577 | // append |
| 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>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2582 | 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] | 2583 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2584 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2585 | size_type __cap = capacity(); |
| 2586 | size_type __sz = size(); |
| 2587 | if (__cap - __sz >= __n) |
| 2588 | { |
| 2589 | if (__n) |
| 2590 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2591 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2592 | traits_type::copy(__p + __sz, __s, __n); |
| 2593 | __sz += __n; |
| 2594 | __set_size(__sz); |
| 2595 | traits_type::assign(__p[__sz], value_type()); |
| 2596 | } |
| 2597 | } |
| 2598 | else |
| 2599 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); |
| 2600 | return *this; |
| 2601 | } |
| 2602 | |
| 2603 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2604 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2605 | basic_string<_CharT, _Traits, _Allocator>& |
| 2606 | basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) |
| 2607 | { |
| 2608 | if (__n) |
| 2609 | { |
| 2610 | size_type __cap = capacity(); |
| 2611 | size_type __sz = size(); |
| 2612 | if (__cap - __sz < __n) |
| 2613 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2614 | pointer __p = __get_pointer(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2615 | traits_type::assign(std::__to_address(__p) + __sz, __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2616 | __sz += __n; |
| 2617 | __set_size(__sz); |
| 2618 | traits_type::assign(__p[__sz], value_type()); |
| 2619 | } |
| 2620 | return *this; |
| 2621 | } |
| 2622 | |
| 2623 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2624 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 2625 | basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) |
| 2626 | { |
| 2627 | if (__n) |
| 2628 | { |
| 2629 | size_type __cap = capacity(); |
| 2630 | size_type __sz = size(); |
| 2631 | if (__cap - __sz < __n) |
| 2632 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2633 | pointer __p = __get_pointer(); |
| 2634 | __sz += __n; |
| 2635 | __set_size(__sz); |
| 2636 | traits_type::assign(__p[__sz], value_type()); |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2641 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2642 | void |
| 2643 | basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) |
| 2644 | { |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2645 | bool __is_short = !__is_long(); |
| 2646 | size_type __cap; |
| 2647 | size_type __sz; |
| 2648 | if (__is_short) |
| 2649 | { |
| 2650 | __cap = __min_cap - 1; |
| 2651 | __sz = __get_short_size(); |
| 2652 | } |
| 2653 | else |
| 2654 | { |
| 2655 | __cap = __get_long_cap() - 1; |
| 2656 | __sz = __get_long_size(); |
| 2657 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2658 | if (__sz == __cap) |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2659 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2660 | __grow_by(__cap, 1, __sz, __sz, 0); |
Louis Dionne | 82d2b2c | 2021-11-16 11:26:56 -0500 | [diff] [blame] | 2661 | __is_short = false; // the string is always long after __grow_by |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2662 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2663 | pointer __p = __get_pointer(); |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2664 | if (__is_short) |
| 2665 | { |
| 2666 | __p = __get_short_pointer() + __sz; |
| 2667 | __set_short_size(__sz+1); |
| 2668 | } |
| 2669 | else |
| 2670 | { |
| 2671 | __p = __get_long_pointer() + __sz; |
| 2672 | __set_long_size(__sz+1); |
| 2673 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2674 | traits_type::assign(*__p, __c); |
| 2675 | traits_type::assign(*++__p, value_type()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2678 | template <class _CharT, class _Traits, class _Allocator> |
| 2679 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2680 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2681 | __enable_if_t |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2682 | < |
| 2683 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
| 2684 | basic_string<_CharT, _Traits, _Allocator>& |
| 2685 | > |
| 2686 | basic_string<_CharT, _Traits, _Allocator>::append( |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 2687 | _ForwardIterator __first, _ForwardIterator __last) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2688 | { |
| 2689 | size_type __sz = size(); |
| 2690 | size_type __cap = capacity(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2691 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2692 | if (__n) |
| 2693 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2694 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2695 | !__addr_in_range(*__first)) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2696 | { |
| 2697 | if (__cap - __sz < __n) |
| 2698 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2699 | pointer __p = __get_pointer() + __sz; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2700 | for (; __first != __last; ++__p, (void) ++__first) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2701 | traits_type::assign(*__p, *__first); |
| 2702 | traits_type::assign(*__p, value_type()); |
| 2703 | __set_size(__sz + __n); |
| 2704 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2705 | else |
| 2706 | { |
| 2707 | const basic_string __temp(__first, __last, __alloc()); |
| 2708 | append(__temp.data(), __temp.size()); |
| 2709 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2710 | } |
| 2711 | return *this; |
| 2712 | } |
| 2713 | |
| 2714 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2715 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2716 | basic_string<_CharT, _Traits, _Allocator>& |
| 2717 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) |
| 2718 | { |
| 2719 | return append(__str.data(), __str.size()); |
| 2720 | } |
| 2721 | |
| 2722 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2723 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2724 | basic_string<_CharT, _Traits, _Allocator>& |
| 2725 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) |
| 2726 | { |
| 2727 | size_type __sz = __str.size(); |
| 2728 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2729 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2730 | return append(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 2734 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2735 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2736 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2737 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2738 | __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] | 2739 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2740 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2741 | 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] | 2742 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2743 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2744 | size_type __sz = __sv.size(); |
| 2745 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2746 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2747 | return append(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2751 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2752 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2753 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2754 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2755 | _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2756 | return append(__s, traits_type::length(__s)); |
| 2757 | } |
| 2758 | |
| 2759 | // insert |
| 2760 | |
| 2761 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2762 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2763 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2764 | 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] | 2765 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2766 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2767 | size_type __sz = size(); |
| 2768 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2769 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2770 | size_type __cap = capacity(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2771 | if (__libcpp_is_constant_evaluated()) { |
| 2772 | if (__cap - __sz >= __n) |
| 2773 | __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s); |
| 2774 | else |
| 2775 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2776 | return *this; |
| 2777 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2778 | if (__cap - __sz >= __n) |
| 2779 | { |
| 2780 | if (__n) |
| 2781 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2782 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2783 | size_type __n_move = __sz - __pos; |
| 2784 | if (__n_move != 0) |
| 2785 | { |
| 2786 | if (__p + __pos <= __s && __s < __p + __sz) |
| 2787 | __s += __n; |
| 2788 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2789 | } |
| 2790 | traits_type::move(__p + __pos, __s, __n); |
| 2791 | __sz += __n; |
| 2792 | __set_size(__sz); |
| 2793 | traits_type::assign(__p[__sz], value_type()); |
| 2794 | } |
| 2795 | } |
| 2796 | else |
| 2797 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2798 | return *this; |
| 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>& |
| 2804 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) |
| 2805 | { |
| 2806 | size_type __sz = size(); |
| 2807 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2808 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2809 | if (__n) |
| 2810 | { |
| 2811 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2812 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2813 | if (__cap - __sz >= __n) |
| 2814 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2815 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2816 | size_type __n_move = __sz - __pos; |
| 2817 | if (__n_move != 0) |
| 2818 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2819 | } |
| 2820 | else |
| 2821 | { |
| 2822 | __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2823 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2824 | } |
| 2825 | traits_type::assign(__p + __pos, __n, __c); |
| 2826 | __sz += __n; |
| 2827 | __set_size(__sz); |
| 2828 | traits_type::assign(__p[__sz], value_type()); |
| 2829 | } |
| 2830 | return *this; |
| 2831 | } |
| 2832 | |
| 2833 | template <class _CharT, class _Traits, class _Allocator> |
| 2834 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2835 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2836 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2837 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2838 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2839 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2840 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2841 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) |
| 2842 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2843 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2844 | "string::insert(iterator, range) called with an iterator not" |
| 2845 | " referring to this string"); |
| 2846 | const basic_string __temp(__first, __last, __alloc()); |
| 2847 | return insert(__pos, __temp.data(), __temp.data() + __temp.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2848 | } |
| 2849 | |
| 2850 | template <class _CharT, class _Traits, class _Allocator> |
| 2851 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2852 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2853 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2854 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2855 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2856 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2857 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2858 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) |
| 2859 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2860 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2861 | "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] | 2862 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2863 | size_type __ip = static_cast<size_type>(__pos - begin()); |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2864 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
| 2865 | if (__n == 0) |
| 2866 | return begin() + __ip; |
| 2867 | |
| 2868 | if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2869 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2870 | return __insert_from_safe_copy(__n, __ip, __first, __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2871 | } |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2872 | else |
| 2873 | { |
| 2874 | const basic_string __temp(__first, __last, __alloc()); |
| 2875 | return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end()); |
| 2876 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2880 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2881 | basic_string<_CharT, _Traits, _Allocator>& |
| 2882 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) |
| 2883 | { |
| 2884 | return insert(__pos1, __str.data(), __str.size()); |
| 2885 | } |
| 2886 | |
| 2887 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2888 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2889 | basic_string<_CharT, _Traits, _Allocator>& |
| 2890 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, |
| 2891 | size_type __pos2, size_type __n) |
| 2892 | { |
| 2893 | size_type __str_sz = __str.size(); |
| 2894 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2895 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2896 | return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2900 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2901 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2902 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2903 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2904 | __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] | 2905 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2906 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2907 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2908 | size_type __pos2, size_type __n) |
| 2909 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2910 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2911 | size_type __str_sz = __sv.size(); |
| 2912 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2913 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2914 | return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2918 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2919 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2920 | 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] | 2921 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2922 | _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2923 | return insert(__pos, __s, traits_type::length(__s)); |
| 2924 | } |
| 2925 | |
| 2926 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2927 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2928 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2929 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) |
| 2930 | { |
Louis Dionne | f4cc6fb | 2022-02-15 15:47:45 -0500 | [diff] [blame] | 2931 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2932 | "string::insert(iterator, character) called with an iterator not" |
| 2933 | " referring to this string"); |
| 2934 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2935 | size_type __ip = static_cast<size_type>(__pos - begin()); |
| 2936 | size_type __sz = size(); |
| 2937 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2938 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2939 | if (__cap == __sz) |
| 2940 | { |
| 2941 | __grow_by(__cap, 1, __sz, __ip, 0, 1); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2942 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2943 | } |
| 2944 | else |
| 2945 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2946 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2947 | size_type __n_move = __sz - __ip; |
| 2948 | if (__n_move != 0) |
| 2949 | traits_type::move(__p + __ip + 1, __p + __ip, __n_move); |
| 2950 | } |
| 2951 | traits_type::assign(__p[__ip], __c); |
| 2952 | traits_type::assign(__p[++__sz], value_type()); |
| 2953 | __set_size(__sz); |
| 2954 | return begin() + static_cast<difference_type>(__ip); |
| 2955 | } |
| 2956 | |
| 2957 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2958 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2959 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2960 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) |
| 2961 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2962 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2963 | "string::insert(iterator, n, value) called with an iterator not" |
| 2964 | " referring to this string"); |
| 2965 | difference_type __p = __pos - begin(); |
| 2966 | insert(static_cast<size_type>(__p), __n, __c); |
| 2967 | return begin() + __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | // replace |
| 2971 | |
| 2972 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2973 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2974 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2975 | 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] | 2976 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2977 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2978 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2979 | size_type __sz = size(); |
| 2980 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2981 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2982 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2983 | size_type __cap = capacity(); |
| 2984 | if (__cap - __sz + __n1 >= __n2) |
| 2985 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2986 | if (__libcpp_is_constant_evaluated()) { |
| 2987 | __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s); |
| 2988 | return *this; |
| 2989 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2990 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | if (__n1 != __n2) |
| 2992 | { |
| 2993 | size_type __n_move = __sz - __pos - __n1; |
| 2994 | if (__n_move != 0) |
| 2995 | { |
| 2996 | if (__n1 > __n2) |
| 2997 | { |
| 2998 | traits_type::move(__p + __pos, __s, __n2); |
| 2999 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3000 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3001 | } |
| 3002 | if (__p + __pos < __s && __s < __p + __sz) |
| 3003 | { |
| 3004 | if (__p + __pos + __n1 <= __s) |
| 3005 | __s += __n2 - __n1; |
| 3006 | else // __p + __pos < __s < __p + __pos + __n1 |
| 3007 | { |
| 3008 | traits_type::move(__p + __pos, __s, __n1); |
| 3009 | __pos += __n1; |
| 3010 | __s += __n2; |
| 3011 | __n2 -= __n1; |
| 3012 | __n1 = 0; |
| 3013 | } |
| 3014 | } |
| 3015 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3016 | } |
| 3017 | } |
| 3018 | traits_type::move(__p + __pos, __s, __n2); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3019 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3020 | } |
| 3021 | else |
| 3022 | __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); |
| 3023 | return *this; |
| 3024 | } |
| 3025 | |
| 3026 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3027 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3028 | basic_string<_CharT, _Traits, _Allocator>& |
| 3029 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) |
| 3030 | { |
| 3031 | size_type __sz = size(); |
| 3032 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3033 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3034 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3035 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3036 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3037 | if (__cap - __sz + __n1 >= __n2) |
| 3038 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3039 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3040 | if (__n1 != __n2) |
| 3041 | { |
| 3042 | size_type __n_move = __sz - __pos - __n1; |
| 3043 | if (__n_move != 0) |
| 3044 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3045 | } |
| 3046 | } |
| 3047 | else |
| 3048 | { |
| 3049 | __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3050 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3051 | } |
| 3052 | traits_type::assign(__p + __pos, __n2, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3053 | return __null_terminate_at(__p, __sz - (__n1 - __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3054 | } |
| 3055 | |
| 3056 | template <class _CharT, class _Traits, class _Allocator> |
| 3057 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3058 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3059 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3060 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3061 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3062 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3063 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3064 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3065 | _InputIterator __j1, _InputIterator __j2) |
| 3066 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 3067 | const basic_string __temp(__j1, __j2, __alloc()); |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3068 | return replace(__i1, __i2, __temp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3072 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3073 | basic_string<_CharT, _Traits, _Allocator>& |
| 3074 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) |
| 3075 | { |
| 3076 | return replace(__pos1, __n1, __str.data(), __str.size()); |
| 3077 | } |
| 3078 | |
| 3079 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3080 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3081 | basic_string<_CharT, _Traits, _Allocator>& |
| 3082 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 3083 | size_type __pos2, size_type __n2) |
| 3084 | { |
| 3085 | size_type __str_sz = __str.size(); |
| 3086 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3087 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3088 | 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] | 3089 | } |
| 3090 | |
| 3091 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3092 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3093 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3094 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3095 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3096 | __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] | 3097 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3098 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3099 | 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] | 3100 | size_type __pos2, size_type __n2) |
| 3101 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3102 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3103 | size_type __str_sz = __sv.size(); |
| 3104 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3105 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3106 | 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] | 3107 | } |
| 3108 | |
| 3109 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3110 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3111 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3112 | 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] | 3113 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3114 | _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3115 | return replace(__pos, __n1, __s, traits_type::length(__s)); |
| 3116 | } |
| 3117 | |
| 3118 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3119 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3120 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3121 | 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] | 3122 | { |
| 3123 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), |
| 3124 | __str.data(), __str.size()); |
| 3125 | } |
| 3126 | |
| 3127 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3128 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3129 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3130 | 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] | 3131 | { |
| 3132 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); |
| 3133 | } |
| 3134 | |
| 3135 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3136 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3137 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3138 | 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] | 3139 | { |
| 3140 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); |
| 3141 | } |
| 3142 | |
| 3143 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3144 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3145 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3146 | 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] | 3147 | { |
| 3148 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); |
| 3149 | } |
| 3150 | |
| 3151 | // erase |
| 3152 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3153 | // 'externally instantiated' erase() implementation, called when __n != npos. |
| 3154 | // Does not check __pos against size() |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3156 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3157 | void |
| 3158 | basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( |
| 3159 | size_type __pos, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3160 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3161 | if (__n) |
| 3162 | { |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3163 | size_type __sz = size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3164 | value_type* __p = std::__to_address(__get_pointer()); |
| 3165 | __n = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3166 | size_type __n_move = __sz - __pos - __n; |
| 3167 | if (__n_move != 0) |
| 3168 | traits_type::move(__p + __pos, __p + __pos + __n, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3169 | __null_terminate_at(__p, __sz - __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3170 | } |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3171 | } |
| 3172 | |
| 3173 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3174 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3175 | basic_string<_CharT, _Traits, _Allocator>& |
| 3176 | basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, |
| 3177 | size_type __n) { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3178 | if (__pos > size()) |
| 3179 | __throw_out_of_range(); |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3180 | if (__n == npos) { |
| 3181 | __erase_to_end(__pos); |
| 3182 | } else { |
| 3183 | __erase_external_with_move(__pos, __n); |
| 3184 | } |
| 3185 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3189 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3190 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3191 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) |
| 3192 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3193 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3194 | "string::erase(iterator) called with an iterator not" |
| 3195 | " referring to this string"); |
| 3196 | |
| 3197 | _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); |
| 3198 | iterator __b = begin(); |
| 3199 | size_type __r = static_cast<size_type>(__pos - __b); |
| 3200 | erase(__r, 1); |
| 3201 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3205 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3206 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3207 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 3208 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3209 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 3210 | "string::erase(iterator, iterator) called with an iterator not" |
| 3211 | " referring to this string"); |
| 3212 | |
| 3213 | _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); |
| 3214 | iterator __b = begin(); |
| 3215 | size_type __r = static_cast<size_type>(__first - __b); |
| 3216 | erase(__r, static_cast<size_type>(__last - __first)); |
| 3217 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3221 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3222 | void |
| 3223 | basic_string<_CharT, _Traits, _Allocator>::pop_back() |
| 3224 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3225 | _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3226 | __erase_to_end(size() - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3230 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3231 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3232 | basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3233 | { |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3234 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3235 | if (__is_long()) |
| 3236 | { |
| 3237 | traits_type::assign(*__get_long_pointer(), value_type()); |
| 3238 | __set_long_size(0); |
| 3239 | } |
| 3240 | else |
| 3241 | { |
| 3242 | traits_type::assign(*__get_short_pointer(), value_type()); |
| 3243 | __set_short_size(0); |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3248 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3249 | void |
| 3250 | basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) |
| 3251 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3252 | __null_terminate_at(std::__to_address(__get_pointer()), __pos); |
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 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3257 | void |
| 3258 | basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) |
| 3259 | { |
| 3260 | size_type __sz = size(); |
| 3261 | if (__n > __sz) |
| 3262 | append(__n - __sz, __c); |
| 3263 | else |
| 3264 | __erase_to_end(__n); |
| 3265 | } |
| 3266 | |
| 3267 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3268 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 3269 | basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) |
| 3270 | { |
| 3271 | size_type __sz = size(); |
| 3272 | if (__n > __sz) { |
| 3273 | __append_default_init(__n - __sz); |
| 3274 | } else |
| 3275 | __erase_to_end(__n); |
| 3276 | } |
| 3277 | |
| 3278 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3279 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3280 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3281 | basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3282 | { |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 3283 | size_type __m = __alloc_traits::max_size(__alloc()); |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 3284 | if (__m <= std::numeric_limits<size_type>::max() / 2) { |
| 3285 | return __m - __alignment; |
| 3286 | } else { |
| 3287 | bool __uses_lsb = __endian_factor == 2; |
| 3288 | return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment; |
| 3289 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3290 | } |
| 3291 | |
| 3292 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3293 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3294 | void |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3295 | basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3296 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3297 | if (__requested_capacity > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3298 | __throw_length_error(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3299 | |
Louis Dionne | 05b6d3e | 2022-01-14 12:30:22 -0500 | [diff] [blame] | 3300 | // Make sure reserve(n) never shrinks. This is technically only required in C++20 |
| 3301 | // and later (since P0966R1), however we provide consistent behavior in all Standard |
| 3302 | // modes because this function is instantiated in the shared library. |
| 3303 | if (__requested_capacity <= capacity()) |
| 3304 | return; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3305 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3306 | size_type __target_capacity = std::max(__requested_capacity, size()); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3307 | __target_capacity = __recommend(__target_capacity); |
| 3308 | if (__target_capacity == capacity()) return; |
| 3309 | |
| 3310 | __shrink_or_extend(__target_capacity); |
| 3311 | } |
| 3312 | |
| 3313 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3314 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3315 | void |
| 3316 | basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT |
| 3317 | { |
| 3318 | size_type __target_capacity = __recommend(size()); |
| 3319 | if (__target_capacity == capacity()) return; |
| 3320 | |
| 3321 | __shrink_or_extend(__target_capacity); |
| 3322 | } |
| 3323 | |
| 3324 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3325 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3326 | void |
| 3327 | basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) |
| 3328 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3329 | size_type __cap = capacity(); |
| 3330 | size_type __sz = size(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3331 | |
| 3332 | pointer __new_data, __p; |
| 3333 | bool __was_long, __now_long; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3334 | if (__fits_in_sso(__target_capacity)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3335 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3336 | __was_long = true; |
| 3337 | __now_long = false; |
| 3338 | __new_data = __get_short_pointer(); |
| 3339 | __p = __get_long_pointer(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3340 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3341 | else |
| 3342 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3343 | if (__target_capacity > __cap) { |
| 3344 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3345 | __new_data = __allocation.ptr; |
| 3346 | __target_capacity = __allocation.count - 1; |
| 3347 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3348 | else |
| 3349 | { |
| 3350 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3351 | try |
| 3352 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3353 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3354 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3355 | __new_data = __allocation.ptr; |
| 3356 | __target_capacity = __allocation.count - 1; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3357 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3358 | } |
| 3359 | catch (...) |
| 3360 | { |
| 3361 | return; |
| 3362 | } |
| 3363 | #else // _LIBCPP_NO_EXCEPTIONS |
| 3364 | if (__new_data == nullptr) |
| 3365 | return; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3366 | #endif // _LIBCPP_NO_EXCEPTIONS |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3367 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3368 | __begin_lifetime(__new_data, __target_capacity + 1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3369 | __now_long = true; |
| 3370 | __was_long = __is_long(); |
| 3371 | __p = __get_pointer(); |
| 3372 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3373 | traits_type::copy(std::__to_address(__new_data), |
| 3374 | std::__to_address(__p), size()+1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3375 | if (__was_long) |
| 3376 | __alloc_traits::deallocate(__alloc(), __p, __cap+1); |
| 3377 | if (__now_long) |
| 3378 | { |
| 3379 | __set_long_cap(__target_capacity+1); |
| 3380 | __set_long_size(__sz); |
| 3381 | __set_long_pointer(__new_data); |
| 3382 | } |
| 3383 | else |
| 3384 | __set_short_size(__sz); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3385 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3389 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3390 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3391 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3392 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3393 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3394 | return *(data() + __pos); |
| 3395 | } |
| 3396 | |
| 3397 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3398 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3399 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3400 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3401 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3402 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3403 | return *(__get_pointer() + __pos); |
| 3404 | } |
| 3405 | |
| 3406 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3407 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3408 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 3409 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const |
| 3410 | { |
| 3411 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3412 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3413 | return (*this)[__n]; |
| 3414 | } |
| 3415 | |
| 3416 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3417 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3418 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 3419 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) |
| 3420 | { |
| 3421 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3422 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3423 | return (*this)[__n]; |
| 3424 | } |
| 3425 | |
| 3426 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3427 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3428 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3429 | basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3430 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3431 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3432 | return *__get_pointer(); |
| 3433 | } |
| 3434 | |
| 3435 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3436 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3437 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3438 | basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3439 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3440 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3441 | return *data(); |
| 3442 | } |
| 3443 | |
| 3444 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3445 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3446 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3447 | basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3448 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3449 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3450 | return *(__get_pointer() + size() - 1); |
| 3451 | } |
| 3452 | |
| 3453 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3454 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3455 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3456 | basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3457 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3458 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3459 | return *(data() + size() - 1); |
| 3460 | } |
| 3461 | |
| 3462 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3463 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3464 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3465 | 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] | 3466 | { |
| 3467 | size_type __sz = size(); |
| 3468 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3469 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3470 | size_type __rlen = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3471 | traits_type::copy(__s, data() + __pos, __rlen); |
| 3472 | return __rlen; |
| 3473 | } |
| 3474 | |
| 3475 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3476 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3477 | basic_string<_CharT, _Traits, _Allocator> |
| 3478 | basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const |
| 3479 | { |
| 3480 | return basic_string(*this, __pos, __n, __alloc()); |
| 3481 | } |
| 3482 | |
| 3483 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3484 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3485 | void |
| 3486 | basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3487 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3488 | _NOEXCEPT |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3489 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3490 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3491 | __is_nothrow_swappable<allocator_type>::value) |
| 3492 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3493 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 3494 | if (!__is_long()) |
| 3495 | std::__debug_db_invalidate_all(this); |
| 3496 | if (!__str.__is_long()) |
| 3497 | std::__debug_db_invalidate_all(&__str); |
| 3498 | std::__debug_db_swap(this, &__str); |
| 3499 | |
Eric Fiselier | 9bf691f | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 3500 | _LIBCPP_ASSERT( |
| 3501 | __alloc_traits::propagate_on_container_swap::value || |
| 3502 | __alloc_traits::is_always_equal::value || |
| 3503 | __alloc() == __str.__alloc(), "swapping non-equal allocators"); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3504 | std::swap(__r_.first(), __str.__r_.first()); |
| 3505 | std::__swap_allocator(__alloc(), __str.__alloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | // find |
| 3509 | |
| 3510 | template <class _Traits> |
| 3511 | struct _LIBCPP_HIDDEN __traits_eq |
| 3512 | { |
| 3513 | typedef typename _Traits::char_type char_type; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3514 | _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3515 | bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT |
| 3516 | {return _Traits::eq(__x, __y);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3517 | }; |
| 3518 | |
| 3519 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3520 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3521 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3522 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3523 | size_type __pos, |
| 3524 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3525 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3526 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3527 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3528 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3529 | } |
| 3530 | |
| 3531 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3532 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3533 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3534 | basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, |
| 3535 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3536 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3537 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3538 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3542 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3543 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3544 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3545 | < |
| 3546 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3547 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3548 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3549 | basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3550 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3551 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3552 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3553 | return __str_find<value_type, size_type, traits_type, npos> |
| 3554 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3555 | } |
| 3556 | |
| 3557 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3558 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3559 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3560 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3561 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3562 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3563 | _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3564 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3565 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
| 3568 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3569 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3570 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3571 | basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, |
| 3572 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3573 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3574 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3575 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | // rfind |
| 3579 | |
| 3580 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3581 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3582 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3583 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3584 | size_type __pos, |
| 3585 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3586 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3587 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3588 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3589 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3593 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3594 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3595 | basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, |
| 3596 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3597 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3598 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3599 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3603 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3604 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3605 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3606 | < |
| 3607 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3608 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3609 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3610 | basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3611 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3612 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3613 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3614 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 3615 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3616 | } |
| 3617 | |
| 3618 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3619 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3620 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3621 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3622 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3623 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3624 | _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3625 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3626 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3627 | } |
| 3628 | |
| 3629 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3630 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3631 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3632 | basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, |
| 3633 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3634 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3635 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3636 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | // find_first_of |
| 3640 | |
| 3641 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3642 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3643 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3644 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3645 | size_type __pos, |
| 3646 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3647 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3648 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3649 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3650 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3654 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3655 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3656 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, |
| 3657 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3658 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3659 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3660 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3661 | } |
| 3662 | |
| 3663 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3664 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3665 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3666 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3667 | < |
| 3668 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3669 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3670 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3671 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3672 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3673 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3674 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3675 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 3676 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3677 | } |
| 3678 | |
| 3679 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3680 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3681 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3682 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3683 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3684 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3685 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3686 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3687 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3691 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3692 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3693 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, |
| 3694 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3695 | { |
| 3696 | return find(__c, __pos); |
| 3697 | } |
| 3698 | |
| 3699 | // find_last_of |
| 3700 | |
| 3701 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3702 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3703 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3704 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3705 | size_type __pos, |
| 3706 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3707 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3708 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3709 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3710 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3714 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3715 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3716 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, |
| 3717 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3718 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3719 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3720 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3721 | } |
| 3722 | |
| 3723 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3724 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3725 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3726 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3727 | < |
| 3728 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3729 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3730 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3731 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3732 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3733 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3734 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3735 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 3736 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3737 | } |
| 3738 | |
| 3739 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3740 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3741 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3742 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3743 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3744 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3745 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3746 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3747 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3751 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3752 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3753 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, |
| 3754 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3755 | { |
| 3756 | return rfind(__c, __pos); |
| 3757 | } |
| 3758 | |
| 3759 | // find_first_not_of |
| 3760 | |
| 3761 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3762 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3763 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3764 | 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] | 3765 | size_type __pos, |
| 3766 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3767 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3768 | _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] | 3769 | 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] | 3770 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3771 | } |
| 3772 | |
| 3773 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3774 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3775 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3776 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, |
| 3777 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3778 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3779 | 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] | 3780 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3784 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3785 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3786 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3787 | < |
| 3788 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3789 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3790 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3791 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3792 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3793 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3794 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3795 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 3796 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3797 | } |
| 3798 | |
| 3799 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3800 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3801 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3802 | 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] | 3803 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3804 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3805 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3806 | 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] | 3807 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3808 | } |
| 3809 | |
| 3810 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3811 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3812 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3813 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, |
| 3814 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3815 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3816 | 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] | 3817 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | // find_last_not_of |
| 3821 | |
| 3822 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3823 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3824 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3825 | 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] | 3826 | size_type __pos, |
| 3827 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3828 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3829 | _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] | 3830 | 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] | 3831 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3835 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3836 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3837 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, |
| 3838 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3839 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3840 | 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] | 3841 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
| 3844 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3845 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3846 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3847 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3848 | < |
| 3849 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3850 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3851 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3852 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3853 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3854 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3855 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3856 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 3857 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3858 | } |
| 3859 | |
| 3860 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3861 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3862 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3863 | 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] | 3864 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3865 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3866 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3867 | 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] | 3868 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3872 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3873 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3874 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, |
| 3875 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3876 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3877 | 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] | 3878 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | // compare |
| 3882 | |
| 3883 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3884 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3885 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3886 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3887 | < |
| 3888 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3889 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3890 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3891 | basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3892 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3893 | __self_view __sv = __t; |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3894 | size_t __lhs_sz = size(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3895 | size_t __rhs_sz = __sv.size(); |
| 3896 | int __result = traits_type::compare(data(), __sv.data(), |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3897 | std::min(__lhs_sz, __rhs_sz)); |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3898 | if (__result != 0) |
| 3899 | return __result; |
| 3900 | if (__lhs_sz < __rhs_sz) |
| 3901 | return -1; |
| 3902 | if (__lhs_sz > __rhs_sz) |
| 3903 | return 1; |
| 3904 | return 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3905 | } |
| 3906 | |
| 3907 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3908 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3909 | int |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3910 | basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3911 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3912 | return compare(__self_view(__str)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3916 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3917 | int |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3918 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3919 | size_type __n1, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3920 | const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3921 | size_type __n2) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3922 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3923 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3924 | size_type __sz = size(); |
| 3925 | if (__pos1 > __sz || __n2 == npos) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3926 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3927 | size_type __rlen = std::min(__n1, __sz - __pos1); |
| 3928 | int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3929 | if (__r == 0) |
| 3930 | { |
| 3931 | if (__rlen < __n2) |
| 3932 | __r = -1; |
| 3933 | else if (__rlen > __n2) |
| 3934 | __r = 1; |
| 3935 | } |
| 3936 | return __r; |
| 3937 | } |
| 3938 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3939 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3940 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3941 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3942 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3943 | < |
| 3944 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3945 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3946 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3947 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3948 | size_type __n1, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3949 | const _Tp& __t) const |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3950 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3951 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3952 | return compare(__pos1, __n1, __sv.data(), __sv.size()); |
| 3953 | } |
| 3954 | |
| 3955 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3956 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3957 | int |
| 3958 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3959 | size_type __n1, |
| 3960 | const basic_string& __str) const |
| 3961 | { |
| 3962 | return compare(__pos1, __n1, __str.data(), __str.size()); |
| 3963 | } |
| 3964 | |
| 3965 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3966 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3967 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3968 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3969 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3970 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 3971 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 3972 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3973 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3974 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3975 | size_type __n1, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3976 | const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3977 | size_type __pos2, |
| 3978 | size_type __n2) const |
| 3979 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3980 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3981 | return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 3982 | } |
| 3983 | |
| 3984 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3985 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3986 | int |
| 3987 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3988 | size_type __n1, |
| 3989 | const basic_string& __str, |
| 3990 | size_type __pos2, |
| 3991 | size_type __n2) const |
| 3992 | { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3993 | return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3997 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3998 | int |
| 3999 | basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT |
| 4000 | { |
| 4001 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4002 | return compare(0, npos, __s, traits_type::length(__s)); |
| 4003 | } |
| 4004 | |
| 4005 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4006 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4007 | int |
| 4008 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4009 | size_type __n1, |
| 4010 | const value_type* __s) const |
| 4011 | { |
| 4012 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4013 | return compare(__pos1, __n1, __s, traits_type::length(__s)); |
| 4014 | } |
| 4015 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4016 | // __invariants |
| 4017 | |
| 4018 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4019 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4020 | bool |
| 4021 | basic_string<_CharT, _Traits, _Allocator>::__invariants() const |
| 4022 | { |
| 4023 | if (size() > capacity()) |
| 4024 | return false; |
| 4025 | if (capacity() < __min_cap - 1) |
| 4026 | return false; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4027 | if (data() == nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4028 | return false; |
Louis Dionne | 663415f | 2020-10-05 16:16:13 -0400 | [diff] [blame] | 4029 | if (data()[size()] != value_type()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4030 | return false; |
| 4031 | return true; |
| 4032 | } |
| 4033 | |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4034 | // __clear_and_shrink |
| 4035 | |
| 4036 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4037 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4038 | void |
Marshall Clow | e60a718 | 2018-05-29 17:04:37 +0000 | [diff] [blame] | 4039 | basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4040 | { |
| 4041 | clear(); |
| 4042 | if(__is_long()) |
| 4043 | { |
| 4044 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); |
Nikolas Klauser | 1821ec3 | 2022-10-01 15:37:24 +0200 | [diff] [blame] | 4045 | __default_init(); |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4046 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4047 | } |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4048 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4049 | // operator== |
| 4050 | |
| 4051 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4052 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4053 | bool |
| 4054 | operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4055 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4056 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4057 | #if _LIBCPP_STD_VER > 17 |
| 4058 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4059 | #else |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4060 | size_t __lhs_sz = __lhs.size(); |
| 4061 | return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), |
| 4062 | __rhs.data(), |
| 4063 | __lhs_sz) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4064 | #endif |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | template<class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4068 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4069 | bool |
| 4070 | operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, |
| 4071 | const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT |
| 4072 | { |
| 4073 | size_t __lhs_sz = __lhs.size(); |
| 4074 | if (__lhs_sz != __rhs.size()) |
| 4075 | return false; |
| 4076 | const char* __lp = __lhs.data(); |
| 4077 | const char* __rp = __rhs.data(); |
| 4078 | if (__lhs.__is_long()) |
| 4079 | return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; |
| 4080 | for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) |
| 4081 | if (*__lp != *__rp) |
| 4082 | return false; |
| 4083 | return true; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4084 | } |
| 4085 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4086 | #if _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4087 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4088 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4089 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4090 | operator==(const _CharT* __lhs, |
| 4091 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4092 | { |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4093 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4094 | _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); |
| 4095 | size_t __lhs_len = _Traits::length(__lhs); |
| 4096 | if (__lhs_len != __rhs.size()) return false; |
| 4097 | return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4098 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4099 | #endif // _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4100 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4101 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4102 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4103 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4104 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
| 4105 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4106 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4107 | #if _LIBCPP_STD_VER > 17 |
| 4108 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4109 | #else |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4110 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4111 | _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); |
| 4112 | size_t __rhs_len = _Traits::length(__rhs); |
| 4113 | if (__rhs_len != __lhs.size()) return false; |
| 4114 | return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4115 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4118 | #if _LIBCPP_STD_VER > 17 |
| 4119 | |
| 4120 | template <class _CharT, class _Traits, class _Allocator> |
| 4121 | _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>( |
| 4122 | const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4123 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) noexcept { |
| 4124 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4125 | } |
| 4126 | |
| 4127 | template <class _CharT, class _Traits, class _Allocator> |
| 4128 | _LIBCPP_HIDE_FROM_ABI constexpr auto |
| 4129 | operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) { |
| 4130 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4131 | } |
| 4132 | |
| 4133 | #else // _LIBCPP_STD_VER > 17 |
| 4134 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4135 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4136 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4137 | bool |
| 4138 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4139 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4140 | { |
| 4141 | return !(__lhs == __rhs); |
| 4142 | } |
| 4143 | |
| 4144 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4145 | inline _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 _CharT* __lhs, |
| 4148 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4149 | { |
| 4150 | return !(__lhs == __rhs); |
| 4151 | } |
| 4152 | |
| 4153 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4154 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4155 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4156 | operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4157 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4158 | { |
| 4159 | return !(__lhs == __rhs); |
| 4160 | } |
| 4161 | |
| 4162 | // operator< |
| 4163 | |
| 4164 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4165 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4166 | bool |
| 4167 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4168 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4169 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4170 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4174 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4175 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4176 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4177 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4178 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4179 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4183 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4184 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4185 | operator< (const _CharT* __lhs, |
| 4186 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4187 | { |
| 4188 | return __rhs.compare(__lhs) > 0; |
| 4189 | } |
| 4190 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4191 | // operator> |
| 4192 | |
| 4193 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4194 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4195 | bool |
| 4196 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4197 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4198 | { |
| 4199 | return __rhs < __lhs; |
| 4200 | } |
| 4201 | |
| 4202 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4203 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4204 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4205 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4206 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4207 | { |
| 4208 | return __rhs < __lhs; |
| 4209 | } |
| 4210 | |
| 4211 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4212 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4213 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4214 | operator> (const _CharT* __lhs, |
| 4215 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4216 | { |
| 4217 | return __rhs < __lhs; |
| 4218 | } |
| 4219 | |
| 4220 | // operator<= |
| 4221 | |
| 4222 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4223 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4224 | bool |
| 4225 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4226 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4227 | { |
| 4228 | return !(__rhs < __lhs); |
| 4229 | } |
| 4230 | |
| 4231 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4232 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4233 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4234 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4235 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4236 | { |
| 4237 | return !(__rhs < __lhs); |
| 4238 | } |
| 4239 | |
| 4240 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4241 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4242 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4243 | operator<=(const _CharT* __lhs, |
| 4244 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4245 | { |
| 4246 | return !(__rhs < __lhs); |
| 4247 | } |
| 4248 | |
| 4249 | // operator>= |
| 4250 | |
| 4251 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4252 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4253 | bool |
| 4254 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4255 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4256 | { |
| 4257 | return !(__lhs < __rhs); |
| 4258 | } |
| 4259 | |
| 4260 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4261 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4262 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4263 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4264 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4265 | { |
| 4266 | return !(__lhs < __rhs); |
| 4267 | } |
| 4268 | |
| 4269 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4270 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4271 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4272 | operator>=(const _CharT* __lhs, |
| 4273 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4274 | { |
| 4275 | return !(__lhs < __rhs); |
| 4276 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4277 | #endif // _LIBCPP_STD_VER > 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4278 | |
| 4279 | // operator + |
| 4280 | |
| 4281 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4282 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4283 | basic_string<_CharT, _Traits, _Allocator> |
| 4284 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4285 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4286 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4287 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4288 | auto __lhs_sz = __lhs.size(); |
| 4289 | auto __rhs_sz = __rhs.size(); |
| 4290 | _String __r(__uninitialized_size_tag(), |
| 4291 | __lhs_sz + __rhs_sz, |
| 4292 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4293 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4294 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4295 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4296 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4297 | return __r; |
| 4298 | } |
| 4299 | |
| 4300 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4301 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4302 | basic_string<_CharT, _Traits, _Allocator> |
| 4303 | operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4304 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4305 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4306 | auto __lhs_sz = _Traits::length(__lhs); |
| 4307 | auto __rhs_sz = __rhs.size(); |
| 4308 | _String __r(__uninitialized_size_tag(), |
| 4309 | __lhs_sz + __rhs_sz, |
| 4310 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4311 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4312 | _Traits::copy(__ptr, __lhs, __lhs_sz); |
| 4313 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4314 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4315 | return __r; |
| 4316 | } |
| 4317 | |
| 4318 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4319 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4320 | basic_string<_CharT, _Traits, _Allocator> |
| 4321 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4322 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4323 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4324 | typename _String::size_type __rhs_sz = __rhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4325 | _String __r(__uninitialized_size_tag(), |
| 4326 | __rhs_sz + 1, |
| 4327 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4328 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4329 | _Traits::assign(__ptr, 1, __lhs); |
| 4330 | _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz); |
| 4331 | _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4332 | return __r; |
| 4333 | } |
| 4334 | |
| 4335 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4336 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4337 | basic_string<_CharT, _Traits, _Allocator> |
| 4338 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) |
| 4339 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4340 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4341 | typename _String::size_type __lhs_sz = __lhs.size(); |
| 4342 | typename _String::size_type __rhs_sz = _Traits::length(__rhs); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4343 | _String __r(__uninitialized_size_tag(), |
| 4344 | __lhs_sz + __rhs_sz, |
| 4345 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4346 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4347 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4348 | _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz); |
| 4349 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4350 | return __r; |
| 4351 | } |
| 4352 | |
| 4353 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4354 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4355 | basic_string<_CharT, _Traits, _Allocator> |
| 4356 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) |
| 4357 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4358 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4359 | typename _String::size_type __lhs_sz = __lhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4360 | _String __r(__uninitialized_size_tag(), |
| 4361 | __lhs_sz + 1, |
| 4362 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4363 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4364 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4365 | _Traits::assign(__ptr + __lhs_sz, 1, __rhs); |
| 4366 | _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4367 | return __r; |
| 4368 | } |
| 4369 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 4370 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4371 | |
| 4372 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4373 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4374 | basic_string<_CharT, _Traits, _Allocator> |
| 4375 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4376 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4377 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4381 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4382 | basic_string<_CharT, _Traits, _Allocator> |
| 4383 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4384 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4385 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4389 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4390 | basic_string<_CharT, _Traits, _Allocator> |
| 4391 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4392 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4393 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4397 | inline _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 _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4400 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4401 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4405 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4406 | basic_string<_CharT, _Traits, _Allocator> |
| 4407 | operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4408 | { |
| 4409 | __rhs.insert(__rhs.begin(), __lhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4410 | return std::move(__rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4411 | } |
| 4412 | |
| 4413 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4414 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4415 | basic_string<_CharT, _Traits, _Allocator> |
| 4416 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) |
| 4417 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4418 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4422 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4423 | basic_string<_CharT, _Traits, _Allocator> |
| 4424 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) |
| 4425 | { |
| 4426 | __lhs.push_back(__rhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4427 | return std::move(__lhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4430 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4431 | |
| 4432 | // swap |
| 4433 | |
| 4434 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4435 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4436 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4437 | swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 4438 | basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4439 | _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4440 | { |
| 4441 | __lhs.swap(__rhs); |
| 4442 | } |
| 4443 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4444 | _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4445 | _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4446 | _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4447 | _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4448 | _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] | 4449 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4450 | _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr); |
| 4451 | _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr); |
| 4452 | _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] | 4453 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4454 | _LIBCPP_FUNC_VIS string to_string(int __val); |
| 4455 | _LIBCPP_FUNC_VIS string to_string(unsigned __val); |
| 4456 | _LIBCPP_FUNC_VIS string to_string(long __val); |
| 4457 | _LIBCPP_FUNC_VIS string to_string(unsigned long __val); |
| 4458 | _LIBCPP_FUNC_VIS string to_string(long long __val); |
| 4459 | _LIBCPP_FUNC_VIS string to_string(unsigned long long __val); |
| 4460 | _LIBCPP_FUNC_VIS string to_string(float __val); |
| 4461 | _LIBCPP_FUNC_VIS string to_string(double __val); |
| 4462 | _LIBCPP_FUNC_VIS string to_string(long double __val); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4463 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4464 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4465 | _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4466 | _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4467 | _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4468 | _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4469 | _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] | 4470 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4471 | _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr); |
| 4472 | _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr); |
| 4473 | _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] | 4474 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4475 | _LIBCPP_FUNC_VIS wstring to_wstring(int __val); |
| 4476 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); |
| 4477 | _LIBCPP_FUNC_VIS wstring to_wstring(long __val); |
| 4478 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); |
| 4479 | _LIBCPP_FUNC_VIS wstring to_wstring(long long __val); |
| 4480 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); |
| 4481 | _LIBCPP_FUNC_VIS wstring to_wstring(float __val); |
| 4482 | _LIBCPP_FUNC_VIS wstring to_wstring(double __val); |
| 4483 | _LIBCPP_FUNC_VIS wstring to_wstring(long double __val); |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4484 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4485 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4486 | template<class _CharT, class _Traits, class _Allocator> |
Martin Storsjö | 88890c2 | 2021-02-22 01:13:13 +0200 | [diff] [blame] | 4487 | _LIBCPP_TEMPLATE_DATA_VIS |
Eric Fiselier | c9fdaf1 | 2020-01-15 17:02:17 -0500 | [diff] [blame] | 4488 | const typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4489 | basic_string<_CharT, _Traits, _Allocator>::npos; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4490 | |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4491 | template <class _CharT, class _Allocator> |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4492 | 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] | 4493 | { |
| 4494 | size_t |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4495 | operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT |
| 4496 | { return __do_string_hash(__val.data(), __val.data() + __val.size()); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4497 | }; |
| 4498 | |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4499 | template <class _Allocator> |
| 4500 | struct hash<basic_string<char, char_traits<char>, _Allocator> > : __string_hash<char, _Allocator> {}; |
| 4501 | |
| 4502 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
| 4503 | template <class _Allocator> |
| 4504 | struct hash<basic_string<char8_t, char_traits<char8_t>, _Allocator> > : __string_hash<char8_t, _Allocator> {}; |
| 4505 | #endif |
| 4506 | |
| 4507 | template <class _Allocator> |
| 4508 | struct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __string_hash<char16_t, _Allocator> {}; |
| 4509 | |
| 4510 | template <class _Allocator> |
| 4511 | struct hash<basic_string<char32_t, char_traits<char32_t>, _Allocator> > : __string_hash<char32_t, _Allocator> {}; |
| 4512 | |
| 4513 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4514 | template <class _Allocator> |
| 4515 | struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Allocator> > : __string_hash<wchar_t, _Allocator> {}; |
| 4516 | #endif |
| 4517 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4518 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4519 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4520 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4521 | const basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4522 | |
| 4523 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4524 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4525 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4526 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4527 | |
| 4528 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4529 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4530 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4531 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4532 | |
| 4533 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4534 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4535 | basic_istream<_CharT, _Traits>& |
| 4536 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4537 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4538 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4539 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4540 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4541 | basic_istream<_CharT, _Traits>& |
| 4542 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4543 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4544 | |
| 4545 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4546 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4547 | basic_istream<_CharT, _Traits>& |
| 4548 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4549 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4550 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4551 | #if _LIBCPP_STD_VER > 17 |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4552 | template <class _CharT, class _Traits, class _Allocator, class _Up> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4553 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4554 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4555 | erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) { |
| 4556 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4557 | __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end()); |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4558 | return __old_size - __str.size(); |
| 4559 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4560 | |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4561 | template <class _CharT, class _Traits, class _Allocator, class _Predicate> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4562 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4563 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4564 | erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, |
| 4565 | _Predicate __pred) { |
| 4566 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4567 | __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4568 | __str.end()); |
| 4569 | return __old_size - __str.size(); |
| 4570 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4571 | #endif |
| 4572 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4573 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4574 | |
| 4575 | template<class _CharT, class _Traits, class _Allocator> |
| 4576 | bool |
| 4577 | basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 4578 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4579 | return data() <= std::__to_address(__i->base()) && |
| 4580 | std::__to_address(__i->base()) < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4581 | } |
| 4582 | |
| 4583 | template<class _CharT, class _Traits, class _Allocator> |
| 4584 | bool |
| 4585 | basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const |
| 4586 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4587 | return data() < std::__to_address(__i->base()) && |
| 4588 | std::__to_address(__i->base()) <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | template<class _CharT, class _Traits, class _Allocator> |
| 4592 | bool |
| 4593 | basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 4594 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4595 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4596 | return data() <= __p && __p <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | template<class _CharT, class _Traits, class _Allocator> |
| 4600 | bool |
| 4601 | basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 4602 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4603 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4604 | return data() <= __p && __p < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4607 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4608 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4609 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4610 | // Literal suffixes for basic_string [basic.string.literals] |
Marshall Clow | ac86837 | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 4611 | inline namespace literals |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4612 | { |
| 4613 | inline namespace string_literals |
| 4614 | { |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4615 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4616 | basic_string<char> operator "" s( const char *__str, size_t __len ) |
| 4617 | { |
| 4618 | return basic_string<char> (__str, __len); |
| 4619 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4620 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4621 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4622 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4623 | basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) |
| 4624 | { |
| 4625 | return basic_string<wchar_t> (__str, __len); |
| 4626 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4627 | #endif |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4628 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 4629 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4630 | inline _LIBCPP_HIDE_FROM_ABI constexpr |
Nikolas Klauser | 5da956d | 2022-09-02 16:20:28 +0200 | [diff] [blame] | 4631 | 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] | 4632 | { |
| 4633 | return basic_string<char8_t> (__str, __len); |
| 4634 | } |
| 4635 | #endif |
| 4636 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4637 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4638 | basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) |
| 4639 | { |
| 4640 | return basic_string<char16_t> (__str, __len); |
| 4641 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4642 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4643 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4644 | basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) |
| 4645 | { |
| 4646 | return basic_string<char32_t> (__str, __len); |
| 4647 | } |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 4648 | } // namespace string_literals |
| 4649 | } // namespace literals |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 4650 | |
| 4651 | #if _LIBCPP_STD_VER > 17 |
| 4652 | template <> |
| 4653 | inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true; |
| 4654 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4655 | template <> |
| 4656 | inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true; |
| 4657 | #endif |
| 4658 | #endif |
| 4659 | |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4660 | #endif |
| 4661 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4662 | _LIBCPP_END_NAMESPACE_STD |
| 4663 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 4664 | _LIBCPP_POP_MACROS |
| 4665 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 4666 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 4667 | # include <algorithm> |
| 4668 | # include <functional> |
| 4669 | # include <iterator> |
| 4670 | # include <new> |
| 4671 | # include <typeinfo> |
| 4672 | # include <utility> |
| 4673 | # include <vector> |
| 4674 | #endif |
| 4675 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4676 | #endif // _LIBCPP_STRING |