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 | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 542 | #include <__ios/fpos.h> |
Nikolas Klauser | fb1b067 | 2022-06-10 19:53:10 +0200 | [diff] [blame] | 543 | #include <__iterator/distance.h> |
| 544 | #include <__iterator/iterator_traits.h> |
| 545 | #include <__iterator/reverse_iterator.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 546 | #include <__iterator/wrap_iter.h> |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 547 | #include <__memory/allocate_at_least.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 548 | #include <__memory/allocator.h> |
| 549 | #include <__memory/allocator_traits.h> |
| 550 | #include <__memory/compressed_pair.h> |
| 551 | #include <__memory/construct_at.h> |
| 552 | #include <__memory/pointer_traits.h> |
Nikolas Klauser | 35080b4 | 2022-07-26 16:13:56 +0200 | [diff] [blame] | 553 | #include <__memory/swap_allocator.h> |
Nikolas Klauser | 11a0ff3 | 2022-06-06 23:35:24 +0200 | [diff] [blame] | 554 | #include <__string/char_traits.h> |
| 555 | #include <__string/extern_template_lists.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 556 | #include <__type_traits/is_allocator.h> |
| 557 | #include <__type_traits/noexcept_move_assign_container.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 558 | #include <__utility/auto_cast.h> |
| 559 | #include <__utility/move.h> |
| 560 | #include <__utility/swap.h> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 561 | #include <__utility/unreachable.h> |
| 562 | #include <climits> |
Louis Dionne | 44962c3 | 2022-06-13 11:21:16 -0400 | [diff] [blame] | 563 | #include <cstdint> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 564 | #include <cstdio> // EOF |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 565 | #include <cstdlib> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 566 | #include <cstring> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 567 | #include <iosfwd> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 568 | #include <limits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 569 | #include <stdexcept> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 570 | #include <string_view> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 571 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 572 | #include <version> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 573 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 574 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 575 | # include <cwchar> |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 576 | #endif |
| 577 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 578 | // standard-mandated includes |
| 579 | |
| 580 | // [iterator.range] |
| 581 | #include <__iterator/access.h> |
| 582 | #include <__iterator/data.h> |
| 583 | #include <__iterator/empty.h> |
| 584 | #include <__iterator/reverse_access.h> |
| 585 | #include <__iterator/size.h> |
| 586 | |
| 587 | // [string.syn] |
| 588 | #include <compare> |
| 589 | #include <initializer_list> |
| 590 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 591 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 592 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 593 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 595 | _LIBCPP_PUSH_MACROS |
| 596 | #include <__undef_macros> |
| 597 | |
| 598 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 600 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 601 | // basic_string |
| 602 | |
| 603 | template<class _CharT, class _Traits, class _Allocator> |
| 604 | basic_string<_CharT, _Traits, _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 605 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 606 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, |
| 607 | const basic_string<_CharT, _Traits, _Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 608 | |
| 609 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 610 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 611 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 612 | operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 613 | |
| 614 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 615 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 616 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 617 | operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 618 | |
| 619 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 620 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 621 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 622 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 623 | |
| 624 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 625 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 627 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 628 | |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 629 | 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] | 630 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 631 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 632 | struct __string_is_trivial_iterator : public false_type {}; |
| 633 | |
| 634 | template <class _Tp> |
| 635 | struct __string_is_trivial_iterator<_Tp*> |
| 636 | : public is_arithmetic<_Tp> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 637 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 638 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 639 | struct __string_is_trivial_iterator<__wrap_iter<_Iter> > |
| 640 | : public __string_is_trivial_iterator<_Iter> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 641 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 642 | template <class _CharT, class _Traits, class _Tp> |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 643 | struct __can_be_converted_to_string_view : public _BoolConstant< |
| 644 | is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && |
| 645 | !is_convertible<const _Tp&, const _CharT*>::value |
| 646 | > {}; |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 647 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 648 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 649 | typedef basic_string<char8_t> u8string; |
| 650 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 651 | typedef basic_string<char16_t> u16string; |
| 652 | typedef basic_string<char32_t> u32string; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 653 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 654 | struct __uninitialized_size_tag {}; |
| 655 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 656 | template<class _CharT, class _Traits, class _Allocator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 657 | class |
| 658 | _LIBCPP_TEMPLATE_VIS |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 659 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 660 | _LIBCPP_PREFERRED_NAME(u8string) |
| 661 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 662 | _LIBCPP_PREFERRED_NAME(u16string) |
| 663 | _LIBCPP_PREFERRED_NAME(u32string) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 664 | basic_string |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 665 | { |
| 666 | public: |
| 667 | typedef basic_string __self; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 668 | typedef basic_string_view<_CharT, _Traits> __self_view; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | typedef _Traits traits_type; |
Marshall Clow | a3a74e0 | 2017-03-15 18:41:11 +0000 | [diff] [blame] | 670 | typedef _CharT value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 671 | typedef _Allocator allocator_type; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 672 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 673 | typedef typename __alloc_traits::size_type size_type; |
| 674 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 675 | typedef value_type& reference; |
| 676 | typedef const value_type& const_reference; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 677 | typedef typename __alloc_traits::pointer pointer; |
| 678 | typedef typename __alloc_traits::const_pointer const_pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 679 | |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 680 | static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); |
| 681 | static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); |
| 682 | static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); |
| 683 | static_assert(( is_same<_CharT, typename traits_type::char_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 684 | "traits_type::char_type must be the same type as CharT"); |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 685 | static_assert(( is_same<typename allocator_type::value_type, value_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 686 | "Allocator::value_type must be same type as value_type"); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 687 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 688 | typedef __wrap_iter<pointer> iterator; |
| 689 | typedef __wrap_iter<const_pointer> const_iterator; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 690 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 691 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 692 | |
| 693 | private: |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 694 | 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] | 695 | |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 696 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 697 | |
| 698 | struct __long |
| 699 | { |
| 700 | pointer __data_; |
| 701 | size_type __size_; |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 702 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 703 | size_type __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 704 | }; |
| 705 | |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 706 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 707 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 708 | |
| 709 | struct __short |
| 710 | { |
| 711 | value_type __data_[__min_cap]; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 712 | unsigned char __padding_[sizeof(value_type) - 1]; |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 713 | unsigned char __size_ : 7; |
| 714 | unsigned char __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 715 | }; |
| 716 | |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 717 | // 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] | 718 | // 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] | 719 | // |
| 720 | // If the LSB is used to store the short-flag in the short string representation, |
| 721 | // we have to multiply the size by two when it is stored and divide it by two when |
| 722 | // it is loaded to make sure that we always store an even number. In the long string |
| 723 | // representation, we can ignore this because we can assume that we always allocate |
| 724 | // an even amount of value_types. |
| 725 | // |
| 726 | // If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2. |
| 727 | // This does not impact the short string representation, since we never need the MSB |
| 728 | // for representing the size of a short string anyway. |
| 729 | |
| 730 | #ifdef _LIBCPP_BIG_ENDIAN |
| 731 | static const size_type __endian_factor = 2; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 732 | #else |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 733 | static const size_type __endian_factor = 1; |
| 734 | #endif |
| 735 | |
| 736 | #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 737 | |
| 738 | #ifdef _LIBCPP_BIG_ENDIAN |
| 739 | static const size_type __endian_factor = 1; |
| 740 | #else |
| 741 | static const size_type __endian_factor = 2; |
| 742 | #endif |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 743 | |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 744 | // Attribute 'packed' is used to keep the layout compatible with the |
| 745 | // previous definition that did not use bit fields. This is because on |
| 746 | // some platforms bit fields have a default size rather than the actual |
| 747 | // 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] | 748 | struct __long |
| 749 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 750 | struct _LIBCPP_PACKED { |
| 751 | size_type __is_long_ : 1; |
| 752 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 753 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 754 | size_type __size_; |
| 755 | pointer __data_; |
| 756 | }; |
| 757 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 758 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 759 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 760 | |
| 761 | struct __short |
| 762 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 763 | struct _LIBCPP_PACKED { |
| 764 | unsigned char __is_long_ : 1; |
| 765 | unsigned char __size_ : 7; |
| 766 | }; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 767 | char __padding_[sizeof(value_type) - 1]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 768 | value_type __data_[__min_cap]; |
| 769 | }; |
| 770 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 771 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 772 | |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 773 | static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size."); |
| 774 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 775 | union __ulx{__long __lx; __short __lxx;}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 776 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 777 | enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 778 | |
| 779 | struct __raw |
| 780 | { |
| 781 | size_type __words[__n_words]; |
| 782 | }; |
| 783 | |
| 784 | struct __rep |
| 785 | { |
| 786 | union |
| 787 | { |
| 788 | __long __l; |
| 789 | __short __s; |
| 790 | __raw __r; |
| 791 | }; |
| 792 | }; |
| 793 | |
| 794 | __compressed_pair<__rep, allocator_type> __r_; |
| 795 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 796 | // Construct a string with the given allocator and enough storage to hold `__size` characters, but |
| 797 | // don't initialize the characters. The contents of the string, including the null terminator, must be |
| 798 | // initialized separately. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 799 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 800 | 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] | 801 | : __r_(__default_init_tag(), __a) { |
| 802 | if (__size > max_size()) |
| 803 | __throw_length_error(); |
| 804 | if (__fits_in_sso(__size)) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 805 | __r_.first() = __rep(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 806 | __set_short_size(__size); |
| 807 | } else { |
| 808 | auto __capacity = __recommend(__size) + 1; |
| 809 | auto __allocation = __alloc_traits::allocate(__alloc(), __capacity); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 810 | __begin_lifetime(__allocation, __capacity); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 811 | __set_long_cap(__capacity); |
| 812 | __set_long_pointer(__allocation); |
| 813 | __set_long_size(__size); |
| 814 | } |
| 815 | std::__debug_db_insert_c(this); |
| 816 | } |
| 817 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 818 | public: |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 819 | _LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 820 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 821 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() |
| 822 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
| 823 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 824 | std::__debug_db_insert_c(this); |
| 825 | __default_init(); |
| 826 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 827 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 828 | _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] | 829 | #if _LIBCPP_STD_VER <= 14 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 830 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 831 | #else |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 832 | _NOEXCEPT |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 833 | #endif |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 834 | : __r_(__default_init_tag(), __a) { |
| 835 | std::__debug_db_insert_c(this); |
| 836 | __default_init(); |
| 837 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 838 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 839 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str); |
| 840 | _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] | 841 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 842 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 843 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str) |
| 844 | # if _LIBCPP_STD_VER <= 14 |
| 845 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
| 846 | # else |
| 847 | _NOEXCEPT |
| 848 | # endif |
| 849 | : __r_(std::move(__str.__r_)) { |
| 850 | __str.__default_init(); |
| 851 | std::__debug_db_insert_c(this); |
| 852 | if (__is_long()) |
| 853 | std::__debug_db_swap(this, &__str); |
| 854 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 855 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 856 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a) |
| 857 | : __r_(__default_init_tag(), __a) { |
| 858 | if (__str.__is_long() && __a != __str.__alloc()) // copy, not move |
| 859 | __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); |
| 860 | else { |
| 861 | if (__libcpp_is_constant_evaluated()) |
| 862 | __r_.first() = __rep(); |
| 863 | __r_.first() = __str.__r_.first(); |
| 864 | __str.__default_init(); |
| 865 | } |
| 866 | std::__debug_db_insert_c(this); |
| 867 | if (__is_long()) |
| 868 | std::__debug_db_swap(this, &__str); |
| 869 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 870 | #endif // _LIBCPP_CXX03_LANG |
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) |
| 874 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 875 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); |
| 876 | __init(__s, traits_type::length(__s)); |
| 877 | std::__debug_db_insert_c(this); |
| 878 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 879 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 880 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 881 | _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] | 882 | |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 883 | #if _LIBCPP_STD_VER > 20 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 884 | basic_string(nullptr_t) = delete; |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 885 | #endif |
| 886 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 887 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) |
| 888 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 889 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) 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 |
| 895 | basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) |
| 896 | : __r_(__default_init_tag(), __a) { |
| 897 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); |
| 898 | __init(__s, __n); |
| 899 | std::__debug_db_insert_c(this); |
| 900 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 901 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 902 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) |
| 903 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 904 | __init(__n, __c); |
| 905 | std::__debug_db_insert_c(this); |
| 906 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 907 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 908 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 909 | _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] | 910 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 911 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 912 | 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] | 913 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 914 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 915 | basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator()) |
| 916 | : __r_(__default_init_tag(), __a) { |
| 917 | size_type __str_sz = __str.size(); |
| 918 | if (__pos > __str_sz) |
| 919 | __throw_out_of_range(); |
| 920 | __init(__str.data() + __pos, __str_sz - __pos); |
| 921 | std::__debug_db_insert_c(this); |
| 922 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 923 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 924 | template <class _Tp, |
| 925 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 926 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 927 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 928 | basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()); |
| 929 | |
| 930 | template <class _Tp, |
| 931 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 932 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 933 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 934 | const _Tp& __t); |
| 935 | |
| 936 | template <class _Tp, |
| 937 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 938 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 939 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 940 | const _Tp& __t, const allocator_type& __a); |
| 941 | |
| 942 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 943 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) |
| 944 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 945 | __init(__first, __last); |
| 946 | std::__debug_db_insert_c(this); |
| 947 | } |
| 948 | |
| 949 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 950 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 951 | basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) |
| 952 | : __r_(__default_init_tag(), __a) { |
| 953 | __init(__first, __last); |
| 954 | std::__debug_db_insert_c(this); |
| 955 | } |
| 956 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 957 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 958 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) |
| 959 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 960 | __init(__il.begin(), __il.end()); |
| 961 | std::__debug_db_insert_c(this); |
| 962 | } |
| 963 | |
| 964 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a) |
| 965 | : __r_(__default_init_tag(), __a) { |
| 966 | __init(__il.begin(), __il.end()); |
| 967 | std::__debug_db_insert_c(this); |
| 968 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 969 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 970 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 971 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 972 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 973 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 974 | operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } |
| 975 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 976 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const basic_string& __str); |
Eric Fiselier | 5ec13b1 | 2017-01-23 21:24:58 +0000 | [diff] [blame] | 977 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 978 | template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 979 | !__is_same_uncvref<_Tp, basic_string>::value> > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 980 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 981 | __self_view __sv = __t; |
| 982 | return assign(__sv); |
| 983 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 984 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 985 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 986 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 987 | basic_string& operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 988 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 989 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 990 | 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] | 991 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 992 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 993 | basic_string& operator=(const value_type* __s) {return assign(__s);} |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 994 | #if _LIBCPP_STD_VER > 20 |
| 995 | basic_string& operator=(nullptr_t) = delete; |
| 996 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 997 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 998 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 999 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1000 | iterator begin() _NOEXCEPT |
| 1001 | {return iterator(this, __get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1002 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1003 | const_iterator begin() const _NOEXCEPT |
| 1004 | {return const_iterator(this, __get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1005 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1006 | iterator end() _NOEXCEPT |
| 1007 | {return iterator(this, __get_pointer() + size());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1008 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1009 | const_iterator end() const _NOEXCEPT |
| 1010 | {return const_iterator(this, __get_pointer() + size());} |
Louis Dionne | e554e10 | 2022-06-03 15:17:03 -0400 | [diff] [blame] | 1011 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1012 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1013 | reverse_iterator rbegin() _NOEXCEPT |
| 1014 | {return reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1015 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1016 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1017 | {return const_reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1018 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1019 | reverse_iterator rend() _NOEXCEPT |
| 1020 | {return reverse_iterator(begin());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1021 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1022 | const_reverse_iterator rend() const _NOEXCEPT |
| 1023 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1024 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1025 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1026 | const_iterator cbegin() const _NOEXCEPT |
| 1027 | {return begin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1028 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1029 | const_iterator cend() const _NOEXCEPT |
| 1030 | {return end();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1031 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1032 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 1033 | {return rbegin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1034 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1035 | const_reverse_iterator crend() const _NOEXCEPT |
| 1036 | {return rend();} |
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_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1039 | {return __is_long() ? __get_long_size() : __get_short_size();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1040 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT {return size();} |
| 1041 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT; |
| 1042 | _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] | 1043 | return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1; |
| 1044 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1045 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1046 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n, value_type __c); |
| 1047 | _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] | 1048 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1049 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __requested_capacity); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1050 | |
| 1051 | #if _LIBCPP_STD_VER > 20 |
| 1052 | template <class _Op> |
| 1053 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1054 | void resize_and_overwrite(size_type __n, _Op __op) { |
| 1055 | __resize_default_init(__n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1056 | __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n))); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1057 | } |
| 1058 | #endif |
| 1059 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1060 | _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] | 1061 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1062 | _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] | 1063 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT; |
| 1064 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1065 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1066 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1067 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1068 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1069 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1070 | const_reference operator[](size_type __pos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1071 | _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] | 1072 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1073 | _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const; |
| 1074 | _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1075 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1076 | _LIBCPP_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] | 1077 | return append(__str); |
| 1078 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1079 | |
| 1080 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1081 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1082 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1083 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1084 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1085 | && !__is_same_uncvref<_Tp, basic_string >::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1086 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1087 | > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1088 | operator+=(const _Tp& __t) { |
| 1089 | __self_view __sv = __t; return append(__sv); |
| 1090 | } |
| 1091 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1092 | _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] | 1093 | return append(__s); |
| 1094 | } |
| 1095 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1096 | _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] | 1097 | push_back(__c); |
| 1098 | return *this; |
| 1099 | } |
| 1100 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1101 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1102 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1103 | basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1104 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1105 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1106 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1107 | basic_string& append(const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1108 | |
| 1109 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1110 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1111 | __enable_if_t< |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1112 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1113 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1114 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1115 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1116 | 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] | 1117 | _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] | 1118 | |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 1119 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1120 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1121 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1122 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1123 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1124 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1125 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1126 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1127 | append(const _Tp& __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1128 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n); |
| 1129 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s); |
| 1130 | _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] | 1131 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1132 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1133 | void __append_default_init(size_type __n); |
| 1134 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1135 | template<class _InputIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1136 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1137 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1138 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1139 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1140 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1141 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1142 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1143 | append(_InputIterator __first, _InputIterator __last) { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1144 | const basic_string __temp(__first, __last, __alloc()); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1145 | append(__temp.data(), __temp.size()); |
| 1146 | return *this; |
| 1147 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1148 | template<class _ForwardIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1149 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1150 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1151 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1152 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1153 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1154 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1155 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1156 | append(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1157 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1158 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1159 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1160 | 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] | 1161 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1162 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1163 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(value_type __c); |
| 1164 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back(); |
| 1165 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() _NOEXCEPT; |
| 1166 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _NOEXCEPT; |
| 1167 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _NOEXCEPT; |
| 1168 | _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] | 1169 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1170 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1171 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1172 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1173 | < |
| 1174 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1175 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1176 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1177 | 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] | 1178 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 95d5e9a | 2016-03-09 18:08:29 +0000 | [diff] [blame] | 1179 | basic_string& assign(const basic_string& __str) { return *this = __str; } |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1180 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1181 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1182 | basic_string& assign(basic_string&& __str) |
Marshall Clow | 5aa9e94 | 2015-10-05 16:17:34 +0000 | [diff] [blame] | 1183 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1184 | {*this = std::move(__str); return *this;} |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1185 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1186 | _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] | 1187 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1188 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1189 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1190 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1191 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1192 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1193 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1194 | > |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1195 | assign(const _Tp & __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1196 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s, size_type __n); |
| 1197 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s); |
| 1198 | _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] | 1199 | template<class _InputIterator> |
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_exactly_cpp17_input_iterator<_InputIterator>::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(_InputIterator __first, _InputIterator __last); |
| 1207 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1208 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1209 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1210 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1211 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1212 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1213 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1214 | assign(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1215 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1216 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1217 | 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] | 1218 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1219 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1220 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1221 | basic_string& insert(size_type __pos1, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1222 | |
| 1223 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1224 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1225 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1226 | < |
| 1227 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1228 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1229 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1230 | insert(size_type __pos1, const _Tp& __t) |
| 1231 | { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); } |
| 1232 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1233 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1234 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1235 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1236 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1237 | __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] | 1238 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1239 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1240 | 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] | 1241 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1242 | 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] | 1243 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s, size_type __n); |
| 1244 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s); |
| 1245 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c); |
| 1246 | _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c); |
| 1247 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1248 | iterator insert(const_iterator __pos, size_type __n, value_type __c); |
| 1249 | template<class _InputIterator> |
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_exactly_cpp17_input_iterator<_InputIterator>::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, _InputIterator __first, _InputIterator __last); |
| 1257 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1258 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1259 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1260 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1261 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1263 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1264 | insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1265 | #ifndef _LIBCPP_CXX03_LANG |
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 insert(const_iterator __pos, initializer_list<value_type> __il) |
| 1268 | {return insert(__pos, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1269 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1270 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1271 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos); |
| 1272 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1273 | iterator erase(const_iterator __pos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1274 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1275 | iterator erase(const_iterator __first, const_iterator __last); |
| 1276 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1277 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | 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] | 1279 | |
| 1280 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1281 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1282 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1283 | < |
| 1284 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1285 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1286 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1287 | 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] | 1288 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1289 | 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] | 1290 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1291 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1292 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1293 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1294 | __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] | 1295 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1296 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1297 | 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] | 1298 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1299 | 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] | 1300 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); |
| 1301 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); |
| 1302 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1303 | 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] | 1304 | |
| 1305 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1306 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1307 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1308 | < |
| 1309 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1310 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1311 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1312 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); } |
| 1313 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1314 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1315 | 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] | 1316 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1317 | 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] | 1318 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1319 | 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] | 1320 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1321 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1322 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1323 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1324 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1326 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1327 | replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1328 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1329 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1330 | basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1331 | {return replace(__i1, __i2, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1332 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1333 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1334 | _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; |
| 1335 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1336 | basic_string substr(size_type __pos = 0, size_type __n = npos) const; |
| 1337 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1338 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1339 | void swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1340 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1341 | _NOEXCEPT; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1342 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1343 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1344 | __is_nothrow_swappable<allocator_type>::value); |
| 1345 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1346 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1347 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1348 | const value_type* c_str() const _NOEXCEPT {return data();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1349 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1350 | const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());} |
Eric Fiselier | 4ee2a89 | 2017-11-20 20:23:27 +0000 | [diff] [blame] | 1351 | #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1352 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1353 | value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());} |
Marshall Clow | d3c2239 | 2016-03-08 15:44:30 +0000 | [diff] [blame] | 1354 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1355 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1356 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1357 | allocator_type get_allocator() const _NOEXCEPT {return __alloc();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1358 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1359 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1360 | 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] | 1361 | |
| 1362 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1363 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1364 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1365 | < |
| 1366 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1367 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1368 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1369 | find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1370 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1371 | 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] | 1372 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1373 | 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] | 1374 | _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] | 1375 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1376 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1377 | 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] | 1378 | |
| 1379 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1380 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1381 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1382 | < |
| 1383 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1384 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1385 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1386 | rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1387 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1388 | 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] | 1389 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1390 | 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] | 1391 | _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] | 1392 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1393 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1394 | 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] | 1395 | |
| 1396 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1397 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1398 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1399 | < |
| 1400 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1401 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1402 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1403 | find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1404 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1405 | 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] | 1406 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1407 | 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] | 1408 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1409 | 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] | 1410 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1411 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1412 | 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] | 1413 | |
| 1414 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1415 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1416 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1417 | < |
| 1418 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1419 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1420 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1421 | find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1422 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1423 | 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] | 1424 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1425 | 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] | 1426 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1427 | 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] | 1428 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1429 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1430 | 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] | 1431 | |
| 1432 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1433 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1434 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1435 | < |
| 1436 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1437 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1438 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1439 | 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] | 1440 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1441 | 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] | 1442 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1443 | 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] | 1444 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1445 | size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
| 1446 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1447 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1448 | 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] | 1449 | |
| 1450 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1451 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1452 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1453 | < |
| 1454 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1455 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1456 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1457 | 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] | 1458 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1459 | 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] | 1460 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1461 | 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] | 1462 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1463 | size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
| 1464 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1465 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1466 | int compare(const basic_string& __str) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1467 | |
| 1468 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1469 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1470 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1471 | < |
| 1472 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1473 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1474 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1475 | compare(const _Tp &__t) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1476 | |
| 1477 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1478 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1479 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1480 | < |
| 1481 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1482 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1483 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1484 | compare(size_type __pos1, size_type __n1, const _Tp& __t) const; |
| 1485 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1486 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1487 | 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] | 1488 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1489 | int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, |
| 1490 | size_type __n2 = npos) const; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1491 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1492 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1493 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1494 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1495 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1496 | __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] | 1497 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1498 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1499 | 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] | 1500 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* __s) const _NOEXCEPT; |
| 1501 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(size_type __pos1, size_type __n1, const value_type* __s) const; |
| 1502 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1503 | 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] | 1504 | |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1505 | #if _LIBCPP_STD_VER > 17 |
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(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1508 | { return __self_view(data(), size()).starts_with(__sv); } |
| 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 starts_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1512 | { return !empty() && _Traits::eq(front(), __c); } |
| 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 starts_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1516 | { return starts_with(__self_view(__s)); } |
| 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(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1520 | { return __self_view(data(), size()).ends_with( __sv); } |
| 1521 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1522 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1523 | bool ends_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1524 | { return !empty() && _Traits::eq(back(), __c); } |
| 1525 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1526 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1527 | bool ends_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1528 | { return ends_with(__self_view(__s)); } |
| 1529 | #endif |
| 1530 | |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1531 | #if _LIBCPP_STD_VER > 20 |
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(__self_view __sv) const noexcept |
| 1534 | { return __self_view(data(), size()).contains(__sv); } |
| 1535 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1536 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1537 | bool contains(value_type __c) const noexcept |
| 1538 | { return __self_view(data(), size()).contains(__c); } |
| 1539 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1540 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1541 | bool contains(const value_type* __s) const |
| 1542 | { return __self_view(data(), size()).contains(__s); } |
| 1543 | #endif |
| 1544 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1545 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1546 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1547 | _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] | 1548 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1549 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1550 | |
| 1551 | bool __dereferenceable(const const_iterator* __i) const; |
| 1552 | bool __decrementable(const const_iterator* __i) const; |
| 1553 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1554 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1555 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1556 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1557 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1558 | private: |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1559 | template<class _Alloc> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1560 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1561 | bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs, |
| 1562 | const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT; |
| 1563 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1564 | _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] | 1565 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1566 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1567 | bool __is_long() const _NOEXCEPT { |
| 1568 | if (__libcpp_is_constant_evaluated()) |
| 1569 | return true; |
| 1570 | return __r_.first().__s.__is_long_; |
| 1571 | } |
| 1572 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1573 | 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] | 1574 | #if _LIBCPP_STD_VER > 17 |
| 1575 | if (__libcpp_is_constant_evaluated()) { |
| 1576 | for (size_type __i = 0; __i != __n; ++__i) |
| 1577 | std::construct_at(std::addressof(__begin[__i])); |
| 1578 | } |
| 1579 | #else |
| 1580 | (void)__begin; |
| 1581 | (void)__n; |
| 1582 | #endif // _LIBCPP_STD_VER > 17 |
| 1583 | } |
| 1584 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1585 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init() { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1586 | __r_.first() = __rep(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1587 | if (__libcpp_is_constant_evaluated()) { |
| 1588 | size_type __sz = __recommend(0) + 1; |
| 1589 | pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); |
| 1590 | __begin_lifetime(__ptr, __sz); |
| 1591 | __set_long_pointer(__ptr); |
| 1592 | __set_long_cap(__sz); |
| 1593 | __set_long_size(0); |
| 1594 | } |
| 1595 | } |
| 1596 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1597 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_constexpr() { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1598 | if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr) |
| 1599 | __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap()); |
| 1600 | } |
| 1601 | |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1602 | _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { |
| 1603 | // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly |
| 1604 | return !__libcpp_is_constant_evaluated() && (__sz < __min_cap); |
| 1605 | } |
| 1606 | |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1607 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1608 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1609 | iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) { |
| 1610 | size_type __sz = size(); |
| 1611 | size_type __cap = capacity(); |
| 1612 | value_type* __p; |
| 1613 | if (__cap - __sz >= __n) |
| 1614 | { |
| 1615 | __p = std::__to_address(__get_pointer()); |
| 1616 | size_type __n_move = __sz - __ip; |
| 1617 | if (__n_move != 0) |
| 1618 | traits_type::move(__p + __ip + __n, __p + __ip, __n_move); |
| 1619 | } |
| 1620 | else |
| 1621 | { |
| 1622 | __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); |
| 1623 | __p = std::__to_address(__get_long_pointer()); |
| 1624 | } |
| 1625 | __sz += __n; |
| 1626 | __set_size(__sz); |
| 1627 | traits_type::assign(__p[__sz], value_type()); |
| 1628 | for (__p += __ip; __first != __last; ++__p, ++__first) |
| 1629 | traits_type::assign(*__p, *__first); |
| 1630 | |
| 1631 | return begin() + __ip; |
| 1632 | } |
| 1633 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1634 | _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] | 1635 | _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] | 1636 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1637 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1638 | void __set_short_size(size_type __s) _NOEXCEPT { |
| 1639 | _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity"); |
| 1640 | __r_.first().__s.__size_ = __s; |
| 1641 | __r_.first().__s.__is_long_ = false; |
| 1642 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1643 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1644 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1645 | size_type __get_short_size() const _NOEXCEPT { |
| 1646 | _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); |
| 1647 | return __r_.first().__s.__size_; |
| 1648 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1649 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1650 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1651 | void __set_long_size(size_type __s) _NOEXCEPT |
| 1652 | {__r_.first().__l.__size_ = __s;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1653 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1654 | size_type __get_long_size() const _NOEXCEPT |
| 1655 | {return __r_.first().__l.__size_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1656 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1657 | void __set_size(size_type __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1658 | {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} |
| 1659 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1660 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1661 | void __set_long_cap(size_type __s) _NOEXCEPT { |
| 1662 | __r_.first().__l.__cap_ = __s / __endian_factor; |
| 1663 | __r_.first().__l.__is_long_ = true; |
| 1664 | } |
| 1665 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1666 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1667 | size_type __get_long_cap() const _NOEXCEPT { |
| 1668 | return __r_.first().__l.__cap_ * __endian_factor; |
| 1669 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1670 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1671 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1672 | void __set_long_pointer(pointer __p) _NOEXCEPT |
| 1673 | {__r_.first().__l.__data_ = __p;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1674 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1675 | pointer __get_long_pointer() _NOEXCEPT |
| 1676 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1677 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1678 | const_pointer __get_long_pointer() const _NOEXCEPT |
| 1679 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1680 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1681 | pointer __get_short_pointer() _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1682 | {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1683 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1684 | const_pointer __get_short_pointer() const _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1685 | {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1686 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1687 | pointer __get_pointer() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1688 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1689 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1690 | const_pointer __get_pointer() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1691 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
| 1692 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | template <size_type __a> static |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1694 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 1695 | size_type __align_it(size_type __s) _NOEXCEPT |
Eric Fiselier | 8599fcc | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 1696 | {return (__s + (__a-1)) & ~(__a-1);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1697 | enum {__alignment = 16}; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1698 | static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1699 | size_type __recommend(size_type __s) _NOEXCEPT |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1700 | { |
| 1701 | if (__s < __min_cap) { |
| 1702 | if (__libcpp_is_constant_evaluated()) |
| 1703 | return static_cast<size_type>(__min_cap); |
| 1704 | else |
| 1705 | return static_cast<size_type>(__min_cap) - 1; |
| 1706 | } |
Marshall Clow | 8058452 | 2018-02-07 21:30:17 +0000 | [diff] [blame] | 1707 | size_type __guess = __align_it<sizeof(value_type) < __alignment ? |
| 1708 | __alignment/sizeof(value_type) : 1 > (__s+1) - 1; |
| 1709 | if (__guess == __min_cap) ++__guess; |
| 1710 | return __guess; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1711 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1712 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1713 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1714 | void __init(const value_type* __s, size_type __sz, size_type __reserve); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1715 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1716 | void __init(const value_type* __s, size_type __sz); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1717 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | void __init(size_type __n, value_type __c); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1719 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 1720 | // Slow path for the (inlined) copy constructor for 'long' strings. |
| 1721 | // Always externally instantiated and not inlined. |
| 1722 | // Requires that __s is zero terminated. |
| 1723 | // The main reason for this function to exist is because for unstable, we |
| 1724 | // want to allow inlining of the copy constructor. However, we don't want |
| 1725 | // to call the __init() functions as those are marked as inline which may |
| 1726 | // result in over-aggressive inlining by the compiler, where our aim is |
| 1727 | // to only inline the fast path code directly in the ctor. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1728 | _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] | 1729 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1730 | template <class _InputIterator> |
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_exactly_cpp17_input_iterator<_InputIterator>::value |
| 1735 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1736 | __init(_InputIterator __first, _InputIterator __last); |
| 1737 | |
| 1738 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1739 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1740 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1741 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1742 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 1743 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1744 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 1745 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1746 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1747 | 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] | 1748 | 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] | 1749 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1750 | void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 1751 | size_type __n_copy, size_type __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1752 | size_type __n_add, const value_type* __p_new_stuff); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1753 | |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 1754 | // __assign_no_alias is invoked for assignment operations where we |
| 1755 | // have proof that the input does not alias the current instance. |
| 1756 | // For example, operator=(basic_string) performs a 'self' check. |
| 1757 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1758 | _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] | 1759 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1760 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | void __erase_to_end(size_type __pos); |
| 1762 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 1763 | // __erase_external_with_move is invoked for erase() invocations where |
| 1764 | // `n ~= npos`, likely requiring memory moves on the string data. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1765 | _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] | 1766 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1767 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1768 | void __copy_assign_alloc(const basic_string& __str) |
| 1769 | {__copy_assign_alloc(__str, integral_constant<bool, |
| 1770 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 1771 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1772 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1773 | void __copy_assign_alloc(const basic_string& __str, true_type) |
| 1774 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1775 | if (__alloc() == __str.__alloc()) |
| 1776 | __alloc() = __str.__alloc(); |
| 1777 | else |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1778 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1779 | if (!__str.__is_long()) |
| 1780 | { |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 1781 | __clear_and_shrink(); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1782 | __alloc() = __str.__alloc(); |
| 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | allocator_type __a = __str.__alloc(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1787 | auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap()); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1788 | __begin_lifetime(__allocation.ptr, __allocation.count); |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 1789 | __clear_and_shrink(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1790 | __alloc() = std::move(__a); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1791 | __set_long_pointer(__allocation.ptr); |
| 1792 | __set_long_cap(__allocation.count); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1793 | __set_long_size(__str.size()); |
| 1794 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1795 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1798 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1799 | void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1800 | {} |
| 1801 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1802 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1803 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1804 | void __move_assign(basic_string& __str, false_type) |
| 1805 | _NOEXCEPT_(__alloc_traits::is_always_equal::value); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1806 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1807 | void __move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1808 | #if _LIBCPP_STD_VER > 14 |
| 1809 | _NOEXCEPT; |
| 1810 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1811 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1812 | #endif |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1813 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1814 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1815 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1816 | void |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1817 | __move_assign_alloc(basic_string& __str) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1818 | _NOEXCEPT_( |
| 1819 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 1820 | is_nothrow_move_assignable<allocator_type>::value) |
| 1821 | {__move_assign_alloc(__str, integral_constant<bool, |
| 1822 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 1823 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1824 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1825 | void __move_assign_alloc(basic_string& __c, true_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1826 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
| 1827 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1828 | __alloc() = std::move(__c.__alloc()); |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1829 | } |
| 1830 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1831 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1832 | void __move_assign_alloc(basic_string&, false_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1833 | _NOEXCEPT |
| 1834 | {} |
| 1835 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1836 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s); |
| 1837 | _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] | 1838 | |
| 1839 | // Assigns the value in __s, guaranteed to be __n < __min_cap in length. |
| 1840 | inline basic_string& __assign_short(const value_type* __s, size_type __n) { |
| 1841 | pointer __p = __is_long() |
| 1842 | ? (__set_long_size(__n), __get_long_pointer()) |
| 1843 | : (__set_short_size(__n), __get_short_pointer()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1844 | traits_type::move(std::__to_address(__p), __s, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 1845 | traits_type::assign(__p[__n], 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 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1850 | basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 1851 | __set_size(__newsz); |
| 1852 | __invalidate_iterators_past(__newsz); |
| 1853 | traits_type::assign(__p[__newsz], value_type()); |
| 1854 | return *this; |
| 1855 | } |
| 1856 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1857 | _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] | 1858 | |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1859 | template<class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1860 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1861 | bool __addr_in_range(_Tp&& __t) const { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1862 | // assume that the ranges overlap, because we can't check during constant evaluation |
| 1863 | if (__libcpp_is_constant_evaluated()) |
| 1864 | return true; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1865 | const volatile void *__p = std::addressof(__t); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1866 | return data() <= __p && __p <= data() + size(); |
| 1867 | } |
| 1868 | |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1869 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1870 | void __throw_length_error() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1871 | std::__throw_length_error("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1875 | void __throw_out_of_range() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1876 | std::__throw_out_of_range("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1877 | } |
| 1878 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1879 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const basic_string&); |
| 1880 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const value_type*, const basic_string&); |
| 1881 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(value_type, const basic_string&); |
| 1882 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const value_type*); |
| 1883 | 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] | 1884 | }; |
| 1885 | |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1886 | // These declarations must appear before any functions are implicitly used |
| 1887 | // so that they have the correct visibility specifier. |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1888 | #define _LIBCPP_DECLARE(...) extern template __VA_ARGS__; |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1889 | #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1890 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1891 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1892 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1893 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1894 | #else |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1895 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1896 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1897 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1898 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1899 | #endif |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 1900 | #undef _LIBCPP_DECLARE |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1901 | |
| 1902 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 1903 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1904 | template<class _InputIterator, |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 1905 | class _CharT = __iter_value_type<_InputIterator>, |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1906 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1907 | class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
| 1908 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1909 | > |
| 1910 | basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 1911 | -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 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 | > |
| 1918 | explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) |
| 1919 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 1920 | |
| 1921 | template<class _CharT, |
| 1922 | class _Traits, |
| 1923 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1924 | class = enable_if_t<__is_allocator<_Allocator>::value>, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1925 | class _Sz = typename allocator_traits<_Allocator>::size_type |
| 1926 | > |
| 1927 | basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) |
| 1928 | -> basic_string<_CharT, _Traits, _Allocator>; |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1929 | #endif |
| 1930 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1932 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1933 | void |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1934 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1935 | { |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1936 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1937 | if (!__libcpp_is_constant_evaluated()) { |
| 1938 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1939 | if (__c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1940 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1941 | const_pointer __new_last = __get_pointer() + __pos; |
| 1942 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1943 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1944 | --__p; |
| 1945 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 1946 | if (__i->base() > __new_last) |
| 1947 | { |
| 1948 | (*__p)->__c_ = nullptr; |
| 1949 | if (--__c->end_ != __p) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1950 | std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1951 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1952 | } |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1953 | __get_db()->unlock(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1954 | } |
| 1955 | } |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1956 | #else |
| 1957 | (void)__pos; |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1958 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1962 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1963 | void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, |
| 1964 | size_type __sz, |
| 1965 | size_type __reserve) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1966 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1967 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1968 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1969 | if (__reserve > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 1970 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1971 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1972 | if (__fits_in_sso(__reserve)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1973 | { |
| 1974 | __set_short_size(__sz); |
| 1975 | __p = __get_short_pointer(); |
| 1976 | } |
| 1977 | else |
| 1978 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1979 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1); |
| 1980 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1981 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1982 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1983 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1984 | __set_long_size(__sz); |
| 1985 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1986 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1987 | traits_type::assign(__p[__sz], value_type()); |
| 1988 | } |
| 1989 | |
| 1990 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1991 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | void |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1993 | 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] | 1994 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1995 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1996 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 1998 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1999 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2000 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2001 | { |
| 2002 | __set_short_size(__sz); |
| 2003 | __p = __get_short_pointer(); |
| 2004 | } |
| 2005 | else |
| 2006 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2007 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2008 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2009 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2010 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2011 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2012 | __set_long_size(__sz); |
| 2013 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2014 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2015 | traits_type::assign(__p[__sz], value_type()); |
| 2016 | } |
| 2017 | |
| 2018 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2019 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2020 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2021 | 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] | 2022 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2023 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2024 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2025 | __init(__s, traits_type::length(__s)); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2026 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2030 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2031 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2032 | : __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] | 2033 | { |
| 2034 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2035 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2036 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2037 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2038 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2039 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2043 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2044 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
| 2045 | const basic_string& __str, const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2046 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2047 | { |
| 2048 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2049 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2050 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2051 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2052 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2053 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2056 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2057 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2058 | void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( |
| 2059 | const value_type* __s, size_type __sz) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2060 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2061 | __r_.first() = __rep(); |
| 2062 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2063 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2064 | if (__fits_in_sso(__sz)) { |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2065 | __p = __get_short_pointer(); |
| 2066 | __set_short_size(__sz); |
| 2067 | } else { |
| 2068 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2069 | __throw_length_error(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2070 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2071 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2072 | __begin_lifetime(__p, __allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2073 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2074 | __set_long_cap(__allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2075 | __set_long_size(__sz); |
| 2076 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2077 | traits_type::copy(std::__to_address(__p), __s, __sz + 1); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2078 | } |
| 2079 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2080 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2081 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2082 | void |
| 2083 | basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) |
| 2084 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2085 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2086 | __r_.first() = __rep(); |
| 2087 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2088 | if (__n > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2089 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2090 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2091 | if (__fits_in_sso(__n)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2092 | { |
| 2093 | __set_short_size(__n); |
| 2094 | __p = __get_short_pointer(); |
| 2095 | } |
| 2096 | else |
| 2097 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2098 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1); |
| 2099 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2100 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2101 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2102 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2103 | __set_long_size(__n); |
| 2104 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2105 | traits_type::assign(std::__to_address(__p), __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2106 | traits_type::assign(__p[__n], value_type()); |
| 2107 | } |
| 2108 | |
| 2109 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2110 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2111 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2112 | 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] | 2113 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2114 | { |
| 2115 | __init(__n, __c); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2116 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2119 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2120 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2121 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, |
| 2122 | size_type __pos, size_type __n, |
| 2123 | const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2124 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2125 | { |
| 2126 | size_type __str_sz = __str.size(); |
| 2127 | if (__pos > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2128 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2129 | __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); |
| 2130 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2134 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2135 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2136 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2137 | 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] | 2138 | : __r_(__default_init_tag(), __a) |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2139 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2140 | __self_view __sv0 = __t; |
| 2141 | __self_view __sv = __sv0.substr(__pos, __n); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2142 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2143 | std::__debug_db_insert_c(this); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2147 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2148 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2149 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2150 | : __r_(__default_init_tag(), __default_init_tag()) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2151 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2152 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2153 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2154 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2158 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2159 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2160 | 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] | 2161 | : __r_(__default_init_tag(), __a) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2162 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2163 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2164 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2165 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
| 2168 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2169 | template <class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2170 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2171 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2172 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2173 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 2174 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2175 | basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) |
| 2176 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2177 | __default_init(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2178 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2179 | try |
| 2180 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2181 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2182 | for (; __first != __last; ++__first) |
| 2183 | push_back(*__first); |
| 2184 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2185 | } |
| 2186 | catch (...) |
| 2187 | { |
| 2188 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2189 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2190 | throw; |
| 2191 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2192 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | template <class _CharT, class _Traits, class _Allocator> |
| 2196 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2197 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2198 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2199 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2200 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 2201 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2202 | basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 2203 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2204 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2205 | __r_.first() = __rep(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2206 | size_type __sz = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2207 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2208 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2209 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2210 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2211 | { |
| 2212 | __set_short_size(__sz); |
| 2213 | __p = __get_short_pointer(); |
| 2214 | } |
| 2215 | else |
| 2216 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2217 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2218 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2219 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2220 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2221 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2222 | __set_long_size(__sz); |
| 2223 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2224 | |
| 2225 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2226 | try |
| 2227 | { |
| 2228 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | a09a3b4 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 2229 | for (; __first != __last; ++__first, (void) ++__p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2230 | traits_type::assign(*__p, *__first); |
| 2231 | traits_type::assign(*__p, value_type()); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2232 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2233 | } |
| 2234 | catch (...) |
| 2235 | { |
| 2236 | if (__is_long()) |
| 2237 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
| 2238 | throw; |
| 2239 | } |
| 2240 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2244 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2245 | basic_string<_CharT, _Traits, _Allocator>::~basic_string() |
| 2246 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 2247 | std::__debug_db_erase_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2248 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2249 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2253 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2254 | void |
| 2255 | basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace |
| 2256 | (size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2257 | 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] | 2258 | { |
| 2259 | size_type __ms = max_size(); |
| 2260 | if (__delta_cap > __ms - __old_cap - 1) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2261 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2262 | pointer __old_p = __get_pointer(); |
| 2263 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2264 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2265 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2266 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2267 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2268 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2269 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2270 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2271 | traits_type::copy(std::__to_address(__p), |
| 2272 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2273 | if (__n_add != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2274 | 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] | 2275 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2276 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2277 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2278 | std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2279 | if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2280 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2281 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2282 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2283 | __old_sz = __n_copy + __n_add + __sec_cp_sz; |
| 2284 | __set_long_size(__old_sz); |
| 2285 | traits_type::assign(__p[__old_sz], value_type()); |
| 2286 | } |
| 2287 | |
| 2288 | template <class _CharT, class _Traits, class _Allocator> |
| 2289 | void |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2290 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2291 | basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 2292 | size_type __n_copy, size_type __n_del, size_type __n_add) |
| 2293 | { |
| 2294 | size_type __ms = max_size(); |
Marshall Clow | 2267c5d | 2013-11-06 14:24:38 +0000 | [diff] [blame] | 2295 | if (__delta_cap > __ms - __old_cap) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2296 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2297 | pointer __old_p = __get_pointer(); |
| 2298 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2299 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2300 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2301 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2302 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2303 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2304 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2305 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2306 | traits_type::copy(std::__to_address(__p), |
| 2307 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2308 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2309 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2310 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2311 | std::__to_address(__old_p) + __n_copy + __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2312 | __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2313 | if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap) |
| 2314 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2315 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2316 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | // assign |
| 2320 | |
| 2321 | template <class _CharT, class _Traits, class _Allocator> |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2322 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2323 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2324 | basic_string<_CharT, _Traits, _Allocator>& |
| 2325 | basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias( |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2326 | const value_type* __s, size_type __n) { |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2327 | 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] | 2328 | if (__n < __cap) { |
| 2329 | pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer(); |
| 2330 | __is_short ? __set_short_size(__n) : __set_long_size(__n); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2331 | traits_type::copy(std::__to_address(__p), __s, __n); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2332 | traits_type::assign(__p[__n], value_type()); |
| 2333 | __invalidate_iterators_past(__n); |
| 2334 | } else { |
| 2335 | size_type __sz = __is_short ? __get_short_size() : __get_long_size(); |
| 2336 | __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s); |
| 2337 | } |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2338 | return *this; |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2342 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2344 | basic_string<_CharT, _Traits, _Allocator>::__assign_external( |
| 2345 | const value_type* __s, size_type __n) { |
| 2346 | size_type __cap = capacity(); |
| 2347 | if (__cap >= __n) { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2348 | value_type* __p = std::__to_address(__get_pointer()); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2349 | traits_type::move(__p, __s, __n); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2350 | return __null_terminate_at(__p, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2351 | } else { |
| 2352 | size_type __sz = size(); |
| 2353 | __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2354 | return *this; |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2355 | } |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2356 | } |
| 2357 | |
| 2358 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2359 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2360 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2361 | 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] | 2362 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2363 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2364 | return (__builtin_constant_p(__n) && __fits_in_sso(__n)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2365 | ? __assign_short(__s, __n) |
| 2366 | : __assign_external(__s, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2370 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2371 | basic_string<_CharT, _Traits, _Allocator>& |
| 2372 | basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) |
| 2373 | { |
| 2374 | size_type __cap = capacity(); |
| 2375 | if (__cap < __n) |
| 2376 | { |
| 2377 | size_type __sz = size(); |
| 2378 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2379 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2380 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2381 | traits_type::assign(__p, __n, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2382 | return __null_terminate_at(__p, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2386 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2387 | basic_string<_CharT, _Traits, _Allocator>& |
| 2388 | basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) |
| 2389 | { |
| 2390 | pointer __p; |
| 2391 | if (__is_long()) |
| 2392 | { |
| 2393 | __p = __get_long_pointer(); |
| 2394 | __set_long_size(1); |
| 2395 | } |
| 2396 | else |
| 2397 | { |
| 2398 | __p = __get_short_pointer(); |
| 2399 | __set_short_size(1); |
| 2400 | } |
| 2401 | traits_type::assign(*__p, __c); |
| 2402 | traits_type::assign(*++__p, value_type()); |
| 2403 | __invalidate_iterators_past(1); |
| 2404 | return *this; |
| 2405 | } |
| 2406 | |
| 2407 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2408 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2409 | basic_string<_CharT, _Traits, _Allocator>& |
| 2410 | basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) |
| 2411 | { |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2412 | if (this != &__str) { |
| 2413 | __copy_assign_alloc(__str); |
| 2414 | if (!__is_long()) { |
| 2415 | if (!__str.__is_long()) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2416 | __r_.first() = __str.__r_.first(); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2417 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2418 | return __assign_no_alias<true>(__str.data(), __str.size()); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2419 | } |
| 2420 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2421 | return __assign_no_alias<false>(__str.data(), __str.size()); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2422 | } |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2423 | } |
| 2424 | return *this; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 2427 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2428 | |
| 2429 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2430 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2431 | void |
| 2432 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2433 | _NOEXCEPT_(__alloc_traits::is_always_equal::value) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2434 | { |
| 2435 | if (__alloc() != __str.__alloc()) |
| 2436 | assign(__str); |
| 2437 | else |
| 2438 | __move_assign(__str, true_type()); |
| 2439 | } |
| 2440 | |
| 2441 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2442 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2443 | void |
| 2444 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2445 | #if _LIBCPP_STD_VER > 14 |
| 2446 | _NOEXCEPT |
| 2447 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2448 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2449 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2450 | { |
marshall | 2ed4162 | 2019-11-27 07:13:00 -0800 | [diff] [blame] | 2451 | if (__is_long()) { |
| 2452 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), |
| 2453 | __get_long_cap()); |
| 2454 | #if _LIBCPP_STD_VER <= 14 |
| 2455 | if (!is_nothrow_move_assignable<allocator_type>::value) { |
| 2456 | __set_short_size(0); |
| 2457 | traits_type::assign(__get_short_pointer()[0], value_type()); |
| 2458 | } |
| 2459 | #endif |
| 2460 | } |
| 2461 | __move_assign_alloc(__str); |
| 2462 | __r_.first() = __str.__r_.first(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2463 | if (__libcpp_is_constant_evaluated()) { |
| 2464 | __str.__default_init(); |
| 2465 | } else { |
| 2466 | __str.__set_short_size(0); |
| 2467 | traits_type::assign(__str.__get_short_pointer()[0], value_type()); |
| 2468 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2472 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2473 | basic_string<_CharT, _Traits, _Allocator>& |
| 2474 | basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2475 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2476 | { |
| 2477 | __move_assign(__str, integral_constant<bool, |
| 2478 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 2479 | return *this; |
| 2480 | } |
| 2481 | |
| 2482 | #endif |
| 2483 | |
| 2484 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2485 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2486 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2487 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2488 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2489 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2490 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2491 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2492 | basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2493 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2494 | const basic_string __temp(__first, __last, __alloc()); |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2495 | assign(__temp.data(), __temp.size()); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2496 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | template <class _CharT, class _Traits, class _Allocator> |
| 2500 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2501 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2502 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2503 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2504 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2505 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2506 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2507 | basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2508 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2509 | size_type __cap = capacity(); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2510 | size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2511 | static_cast<size_type>(std::distance(__first, __last)) : 0; |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2512 | |
| 2513 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2514 | (__cap >= __n || !__addr_in_range(*__first))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2515 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2516 | if (__cap < __n) |
| 2517 | { |
| 2518 | size_type __sz = size(); |
| 2519 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2520 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2521 | pointer __p = __get_pointer(); |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2522 | for (; __first != __last; ++__p, (void) ++__first) |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2523 | traits_type::assign(*__p, *__first); |
| 2524 | traits_type::assign(*__p, value_type()); |
| 2525 | __set_size(__n); |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 2526 | __invalidate_iterators_past(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2527 | } |
| 2528 | else |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2529 | { |
| 2530 | const basic_string __temp(__first, __last, __alloc()); |
| 2531 | assign(__temp.data(), __temp.size()); |
| 2532 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2533 | return *this; |
| 2534 | } |
| 2535 | |
| 2536 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2537 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2538 | basic_string<_CharT, _Traits, _Allocator>& |
| 2539 | basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) |
| 2540 | { |
| 2541 | size_type __sz = __str.size(); |
| 2542 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2543 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2544 | return assign(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| 2547 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2548 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2549 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2550 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2551 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2552 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 2553 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 2554 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2555 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2556 | 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] | 2557 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2558 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2559 | size_type __sz = __sv.size(); |
| 2560 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2561 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2562 | return assign(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | |
| 2566 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2567 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2568 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2569 | basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) { |
| 2570 | return __assign_external(__s, traits_type::length(__s)); |
| 2571 | } |
| 2572 | |
| 2573 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2574 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2575 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2576 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2577 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2578 | _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); |
Louis Dionne | 3e0c433 | 2021-08-31 10:49:06 -0400 | [diff] [blame] | 2579 | return __builtin_constant_p(*__s) |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2580 | ? (__fits_in_sso(traits_type::length(__s)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2581 | ? __assign_short(__s, traits_type::length(__s)) |
| 2582 | : __assign_external(__s, traits_type::length(__s))) |
| 2583 | : __assign_external(__s); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2584 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2585 | // append |
| 2586 | |
| 2587 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2588 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2589 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2590 | 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] | 2591 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2592 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2593 | size_type __cap = capacity(); |
| 2594 | size_type __sz = size(); |
| 2595 | if (__cap - __sz >= __n) |
| 2596 | { |
| 2597 | if (__n) |
| 2598 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2599 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2600 | traits_type::copy(__p + __sz, __s, __n); |
| 2601 | __sz += __n; |
| 2602 | __set_size(__sz); |
| 2603 | traits_type::assign(__p[__sz], value_type()); |
| 2604 | } |
| 2605 | } |
| 2606 | else |
| 2607 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); |
| 2608 | return *this; |
| 2609 | } |
| 2610 | |
| 2611 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2612 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2613 | basic_string<_CharT, _Traits, _Allocator>& |
| 2614 | basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) |
| 2615 | { |
| 2616 | if (__n) |
| 2617 | { |
| 2618 | size_type __cap = capacity(); |
| 2619 | size_type __sz = size(); |
| 2620 | if (__cap - __sz < __n) |
| 2621 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2622 | pointer __p = __get_pointer(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2623 | traits_type::assign(std::__to_address(__p) + __sz, __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2624 | __sz += __n; |
| 2625 | __set_size(__sz); |
| 2626 | traits_type::assign(__p[__sz], value_type()); |
| 2627 | } |
| 2628 | return *this; |
| 2629 | } |
| 2630 | |
| 2631 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2632 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 2633 | basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) |
| 2634 | { |
| 2635 | if (__n) |
| 2636 | { |
| 2637 | size_type __cap = capacity(); |
| 2638 | size_type __sz = size(); |
| 2639 | if (__cap - __sz < __n) |
| 2640 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2641 | pointer __p = __get_pointer(); |
| 2642 | __sz += __n; |
| 2643 | __set_size(__sz); |
| 2644 | traits_type::assign(__p[__sz], value_type()); |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2649 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2650 | void |
| 2651 | basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) |
| 2652 | { |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2653 | bool __is_short = !__is_long(); |
| 2654 | size_type __cap; |
| 2655 | size_type __sz; |
| 2656 | if (__is_short) |
| 2657 | { |
| 2658 | __cap = __min_cap - 1; |
| 2659 | __sz = __get_short_size(); |
| 2660 | } |
| 2661 | else |
| 2662 | { |
| 2663 | __cap = __get_long_cap() - 1; |
| 2664 | __sz = __get_long_size(); |
| 2665 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2666 | if (__sz == __cap) |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2667 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2668 | __grow_by(__cap, 1, __sz, __sz, 0); |
Louis Dionne | 82d2b2c | 2021-11-16 11:26:56 -0500 | [diff] [blame] | 2669 | __is_short = false; // the string is always long after __grow_by |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2670 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2671 | pointer __p = __get_pointer(); |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2672 | if (__is_short) |
| 2673 | { |
| 2674 | __p = __get_short_pointer() + __sz; |
| 2675 | __set_short_size(__sz+1); |
| 2676 | } |
| 2677 | else |
| 2678 | { |
| 2679 | __p = __get_long_pointer() + __sz; |
| 2680 | __set_long_size(__sz+1); |
| 2681 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2682 | traits_type::assign(*__p, __c); |
| 2683 | traits_type::assign(*++__p, value_type()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2686 | template <class _CharT, class _Traits, class _Allocator> |
| 2687 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2688 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2689 | __enable_if_t |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2690 | < |
| 2691 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
| 2692 | basic_string<_CharT, _Traits, _Allocator>& |
| 2693 | > |
| 2694 | basic_string<_CharT, _Traits, _Allocator>::append( |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 2695 | _ForwardIterator __first, _ForwardIterator __last) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2696 | { |
| 2697 | size_type __sz = size(); |
| 2698 | size_type __cap = capacity(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2699 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2700 | if (__n) |
| 2701 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2702 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2703 | !__addr_in_range(*__first)) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2704 | { |
| 2705 | if (__cap - __sz < __n) |
| 2706 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2707 | pointer __p = __get_pointer() + __sz; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2708 | for (; __first != __last; ++__p, (void) ++__first) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2709 | traits_type::assign(*__p, *__first); |
| 2710 | traits_type::assign(*__p, value_type()); |
| 2711 | __set_size(__sz + __n); |
| 2712 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2713 | else |
| 2714 | { |
| 2715 | const basic_string __temp(__first, __last, __alloc()); |
| 2716 | append(__temp.data(), __temp.size()); |
| 2717 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2718 | } |
| 2719 | return *this; |
| 2720 | } |
| 2721 | |
| 2722 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2723 | inline _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) |
| 2726 | { |
| 2727 | return append(__str.data(), __str.size()); |
| 2728 | } |
| 2729 | |
| 2730 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2731 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2732 | basic_string<_CharT, _Traits, _Allocator>& |
| 2733 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) |
| 2734 | { |
| 2735 | size_type __sz = __str.size(); |
| 2736 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2737 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2738 | return append(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 2742 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2743 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2744 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2745 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2746 | __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] | 2747 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2748 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2749 | 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] | 2750 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2751 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2752 | size_type __sz = __sv.size(); |
| 2753 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2754 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2755 | return append(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2759 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2760 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2761 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2762 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2763 | _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2764 | return append(__s, traits_type::length(__s)); |
| 2765 | } |
| 2766 | |
| 2767 | // insert |
| 2768 | |
| 2769 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2770 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2771 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2772 | 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] | 2773 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2774 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2775 | size_type __sz = size(); |
| 2776 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2777 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2778 | size_type __cap = capacity(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2779 | if (__libcpp_is_constant_evaluated()) { |
| 2780 | if (__cap - __sz >= __n) |
| 2781 | __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s); |
| 2782 | else |
| 2783 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2784 | return *this; |
| 2785 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2786 | if (__cap - __sz >= __n) |
| 2787 | { |
| 2788 | if (__n) |
| 2789 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2790 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2791 | size_type __n_move = __sz - __pos; |
| 2792 | if (__n_move != 0) |
| 2793 | { |
| 2794 | if (__p + __pos <= __s && __s < __p + __sz) |
| 2795 | __s += __n; |
| 2796 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2797 | } |
| 2798 | traits_type::move(__p + __pos, __s, __n); |
| 2799 | __sz += __n; |
| 2800 | __set_size(__sz); |
| 2801 | traits_type::assign(__p[__sz], value_type()); |
| 2802 | } |
| 2803 | } |
| 2804 | else |
| 2805 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2806 | return *this; |
| 2807 | } |
| 2808 | |
| 2809 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2810 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2811 | basic_string<_CharT, _Traits, _Allocator>& |
| 2812 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) |
| 2813 | { |
| 2814 | size_type __sz = size(); |
| 2815 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2816 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2817 | if (__n) |
| 2818 | { |
| 2819 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2820 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2821 | if (__cap - __sz >= __n) |
| 2822 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2823 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2824 | size_type __n_move = __sz - __pos; |
| 2825 | if (__n_move != 0) |
| 2826 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2827 | } |
| 2828 | else |
| 2829 | { |
| 2830 | __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2831 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2832 | } |
| 2833 | traits_type::assign(__p + __pos, __n, __c); |
| 2834 | __sz += __n; |
| 2835 | __set_size(__sz); |
| 2836 | traits_type::assign(__p[__sz], value_type()); |
| 2837 | } |
| 2838 | return *this; |
| 2839 | } |
| 2840 | |
| 2841 | template <class _CharT, class _Traits, class _Allocator> |
| 2842 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2843 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2844 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2845 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2846 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2847 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2848 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2849 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) |
| 2850 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2851 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2852 | "string::insert(iterator, range) called with an iterator not" |
| 2853 | " referring to this string"); |
| 2854 | const basic_string __temp(__first, __last, __alloc()); |
| 2855 | return insert(__pos, __temp.data(), __temp.data() + __temp.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | template <class _CharT, class _Traits, class _Allocator> |
| 2859 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2860 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2861 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2862 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2863 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2864 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2865 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2866 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) |
| 2867 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2868 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2869 | "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] | 2870 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2871 | size_type __ip = static_cast<size_type>(__pos - begin()); |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2872 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
| 2873 | if (__n == 0) |
| 2874 | return begin() + __ip; |
| 2875 | |
| 2876 | if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2877 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2878 | return __insert_from_safe_copy(__n, __ip, __first, __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2879 | } |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2880 | else |
| 2881 | { |
| 2882 | const basic_string __temp(__first, __last, __alloc()); |
| 2883 | return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end()); |
| 2884 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2888 | inline _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 | { |
| 2892 | return insert(__pos1, __str.data(), __str.size()); |
| 2893 | } |
| 2894 | |
| 2895 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2896 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2897 | basic_string<_CharT, _Traits, _Allocator>& |
| 2898 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, |
| 2899 | size_type __pos2, size_type __n) |
| 2900 | { |
| 2901 | size_type __str_sz = __str.size(); |
| 2902 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2903 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2904 | return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2908 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2909 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2910 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2911 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2912 | __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] | 2913 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2914 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2915 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2916 | size_type __pos2, size_type __n) |
| 2917 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2918 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2919 | size_type __str_sz = __sv.size(); |
| 2920 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2921 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2922 | return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2926 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2927 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2928 | 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] | 2929 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2930 | _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2931 | return insert(__pos, __s, traits_type::length(__s)); |
| 2932 | } |
| 2933 | |
| 2934 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2935 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2936 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2937 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) |
| 2938 | { |
Louis Dionne | f4cc6fb | 2022-02-15 15:47:45 -0500 | [diff] [blame] | 2939 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2940 | "string::insert(iterator, character) called with an iterator not" |
| 2941 | " referring to this string"); |
| 2942 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2943 | size_type __ip = static_cast<size_type>(__pos - begin()); |
| 2944 | size_type __sz = size(); |
| 2945 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2946 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2947 | if (__cap == __sz) |
| 2948 | { |
| 2949 | __grow_by(__cap, 1, __sz, __ip, 0, 1); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2950 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2951 | } |
| 2952 | else |
| 2953 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2954 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2955 | size_type __n_move = __sz - __ip; |
| 2956 | if (__n_move != 0) |
| 2957 | traits_type::move(__p + __ip + 1, __p + __ip, __n_move); |
| 2958 | } |
| 2959 | traits_type::assign(__p[__ip], __c); |
| 2960 | traits_type::assign(__p[++__sz], value_type()); |
| 2961 | __set_size(__sz); |
| 2962 | return begin() + static_cast<difference_type>(__ip); |
| 2963 | } |
| 2964 | |
| 2965 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2966 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2967 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 2968 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) |
| 2969 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2970 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2971 | "string::insert(iterator, n, value) called with an iterator not" |
| 2972 | " referring to this string"); |
| 2973 | difference_type __p = __pos - begin(); |
| 2974 | insert(static_cast<size_type>(__p), __n, __c); |
| 2975 | return begin() + __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | // replace |
| 2979 | |
| 2980 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2981 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2982 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2983 | 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] | 2984 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2985 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2986 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2987 | size_type __sz = size(); |
| 2988 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2989 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2990 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | size_type __cap = capacity(); |
| 2992 | if (__cap - __sz + __n1 >= __n2) |
| 2993 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2994 | if (__libcpp_is_constant_evaluated()) { |
| 2995 | __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s); |
| 2996 | return *this; |
| 2997 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2998 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2999 | if (__n1 != __n2) |
| 3000 | { |
| 3001 | size_type __n_move = __sz - __pos - __n1; |
| 3002 | if (__n_move != 0) |
| 3003 | { |
| 3004 | if (__n1 > __n2) |
| 3005 | { |
| 3006 | traits_type::move(__p + __pos, __s, __n2); |
| 3007 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3008 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3009 | } |
| 3010 | if (__p + __pos < __s && __s < __p + __sz) |
| 3011 | { |
| 3012 | if (__p + __pos + __n1 <= __s) |
| 3013 | __s += __n2 - __n1; |
| 3014 | else // __p + __pos < __s < __p + __pos + __n1 |
| 3015 | { |
| 3016 | traits_type::move(__p + __pos, __s, __n1); |
| 3017 | __pos += __n1; |
| 3018 | __s += __n2; |
| 3019 | __n2 -= __n1; |
| 3020 | __n1 = 0; |
| 3021 | } |
| 3022 | } |
| 3023 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3024 | } |
| 3025 | } |
| 3026 | traits_type::move(__p + __pos, __s, __n2); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3027 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3028 | } |
| 3029 | else |
| 3030 | __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); |
| 3031 | return *this; |
| 3032 | } |
| 3033 | |
| 3034 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3035 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3036 | basic_string<_CharT, _Traits, _Allocator>& |
| 3037 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) |
| 3038 | { |
| 3039 | size_type __sz = size(); |
| 3040 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3041 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3042 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3043 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3044 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3045 | if (__cap - __sz + __n1 >= __n2) |
| 3046 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3047 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3048 | if (__n1 != __n2) |
| 3049 | { |
| 3050 | size_type __n_move = __sz - __pos - __n1; |
| 3051 | if (__n_move != 0) |
| 3052 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3053 | } |
| 3054 | } |
| 3055 | else |
| 3056 | { |
| 3057 | __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3058 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3059 | } |
| 3060 | traits_type::assign(__p + __pos, __n2, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3061 | return __null_terminate_at(__p, __sz - (__n1 - __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | template <class _CharT, class _Traits, class _Allocator> |
| 3065 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3066 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3067 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3068 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3069 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3070 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3071 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3072 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3073 | _InputIterator __j1, _InputIterator __j2) |
| 3074 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 3075 | const basic_string __temp(__j1, __j2, __alloc()); |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3076 | return replace(__i1, __i2, __temp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3080 | inline _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 | { |
| 3084 | return replace(__pos1, __n1, __str.data(), __str.size()); |
| 3085 | } |
| 3086 | |
| 3087 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3088 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3089 | basic_string<_CharT, _Traits, _Allocator>& |
| 3090 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 3091 | size_type __pos2, size_type __n2) |
| 3092 | { |
| 3093 | size_type __str_sz = __str.size(); |
| 3094 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3095 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3096 | 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] | 3097 | } |
| 3098 | |
| 3099 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3100 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3101 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3102 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3103 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3104 | __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] | 3105 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3106 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3107 | 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] | 3108 | size_type __pos2, size_type __n2) |
| 3109 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3110 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3111 | size_type __str_sz = __sv.size(); |
| 3112 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3113 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3114 | 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] | 3115 | } |
| 3116 | |
| 3117 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3118 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3119 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3120 | 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] | 3121 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3122 | _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3123 | return replace(__pos, __n1, __s, traits_type::length(__s)); |
| 3124 | } |
| 3125 | |
| 3126 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3127 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3128 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3129 | 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] | 3130 | { |
| 3131 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), |
| 3132 | __str.data(), __str.size()); |
| 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, size_type __n) |
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, __n); |
| 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 | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3146 | 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] | 3147 | { |
| 3148 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); |
| 3149 | } |
| 3150 | |
| 3151 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3152 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3153 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3154 | 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] | 3155 | { |
| 3156 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); |
| 3157 | } |
| 3158 | |
| 3159 | // erase |
| 3160 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3161 | // 'externally instantiated' erase() implementation, called when __n != npos. |
| 3162 | // Does not check __pos against size() |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3163 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3164 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3165 | void |
| 3166 | basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( |
| 3167 | size_type __pos, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3168 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3169 | if (__n) |
| 3170 | { |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3171 | size_type __sz = size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3172 | value_type* __p = std::__to_address(__get_pointer()); |
| 3173 | __n = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3174 | size_type __n_move = __sz - __pos - __n; |
| 3175 | if (__n_move != 0) |
| 3176 | traits_type::move(__p + __pos, __p + __pos + __n, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3177 | __null_terminate_at(__p, __sz - __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3178 | } |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3182 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3183 | basic_string<_CharT, _Traits, _Allocator>& |
| 3184 | basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, |
| 3185 | size_type __n) { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3186 | if (__pos > size()) |
| 3187 | __throw_out_of_range(); |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3188 | if (__n == npos) { |
| 3189 | __erase_to_end(__pos); |
| 3190 | } else { |
| 3191 | __erase_external_with_move(__pos, __n); |
| 3192 | } |
| 3193 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3197 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3198 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3199 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) |
| 3200 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3201 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3202 | "string::erase(iterator) called with an iterator not" |
| 3203 | " referring to this string"); |
| 3204 | |
| 3205 | _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); |
| 3206 | iterator __b = begin(); |
| 3207 | size_type __r = static_cast<size_type>(__pos - __b); |
| 3208 | erase(__r, 1); |
| 3209 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3213 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3214 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3215 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 3216 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3217 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 3218 | "string::erase(iterator, iterator) called with an iterator not" |
| 3219 | " referring to this string"); |
| 3220 | |
| 3221 | _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); |
| 3222 | iterator __b = begin(); |
| 3223 | size_type __r = static_cast<size_type>(__first - __b); |
| 3224 | erase(__r, static_cast<size_type>(__last - __first)); |
| 3225 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3229 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3230 | void |
| 3231 | basic_string<_CharT, _Traits, _Allocator>::pop_back() |
| 3232 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3233 | _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3234 | __erase_to_end(size() - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3235 | } |
| 3236 | |
| 3237 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3238 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3239 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3240 | basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3241 | { |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3242 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3243 | if (__is_long()) |
| 3244 | { |
| 3245 | traits_type::assign(*__get_long_pointer(), value_type()); |
| 3246 | __set_long_size(0); |
| 3247 | } |
| 3248 | else |
| 3249 | { |
| 3250 | traits_type::assign(*__get_short_pointer(), value_type()); |
| 3251 | __set_short_size(0); |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3256 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3257 | void |
| 3258 | basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) |
| 3259 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3260 | __null_terminate_at(std::__to_address(__get_pointer()), __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3264 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3265 | void |
| 3266 | basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) |
| 3267 | { |
| 3268 | size_type __sz = size(); |
| 3269 | if (__n > __sz) |
| 3270 | append(__n - __sz, __c); |
| 3271 | else |
| 3272 | __erase_to_end(__n); |
| 3273 | } |
| 3274 | |
| 3275 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3276 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 3277 | basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) |
| 3278 | { |
| 3279 | size_type __sz = size(); |
| 3280 | if (__n > __sz) { |
| 3281 | __append_default_init(__n - __sz); |
| 3282 | } else |
| 3283 | __erase_to_end(__n); |
| 3284 | } |
| 3285 | |
| 3286 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3287 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3288 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3289 | basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3290 | { |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 3291 | size_type __m = __alloc_traits::max_size(__alloc()); |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 3292 | if (__m <= std::numeric_limits<size_type>::max() / 2) { |
| 3293 | return __m - __alignment; |
| 3294 | } else { |
| 3295 | bool __uses_lsb = __endian_factor == 2; |
| 3296 | return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment; |
| 3297 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3301 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3302 | void |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3303 | basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3304 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3305 | if (__requested_capacity > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3306 | __throw_length_error(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3307 | |
Louis Dionne | 05b6d3e | 2022-01-14 12:30:22 -0500 | [diff] [blame] | 3308 | // Make sure reserve(n) never shrinks. This is technically only required in C++20 |
| 3309 | // and later (since P0966R1), however we provide consistent behavior in all Standard |
| 3310 | // modes because this function is instantiated in the shared library. |
| 3311 | if (__requested_capacity <= capacity()) |
| 3312 | return; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3313 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3314 | size_type __target_capacity = std::max(__requested_capacity, size()); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3315 | __target_capacity = __recommend(__target_capacity); |
| 3316 | if (__target_capacity == capacity()) return; |
| 3317 | |
| 3318 | __shrink_or_extend(__target_capacity); |
| 3319 | } |
| 3320 | |
| 3321 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3322 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3323 | void |
| 3324 | basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT |
| 3325 | { |
| 3326 | size_type __target_capacity = __recommend(size()); |
| 3327 | if (__target_capacity == capacity()) return; |
| 3328 | |
| 3329 | __shrink_or_extend(__target_capacity); |
| 3330 | } |
| 3331 | |
| 3332 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3333 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3334 | void |
| 3335 | basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) |
| 3336 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3337 | size_type __cap = capacity(); |
| 3338 | size_type __sz = size(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3339 | |
| 3340 | pointer __new_data, __p; |
| 3341 | bool __was_long, __now_long; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3342 | if (__fits_in_sso(__target_capacity)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3343 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3344 | __was_long = true; |
| 3345 | __now_long = false; |
| 3346 | __new_data = __get_short_pointer(); |
| 3347 | __p = __get_long_pointer(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3348 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3349 | else |
| 3350 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3351 | if (__target_capacity > __cap) { |
| 3352 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3353 | __new_data = __allocation.ptr; |
| 3354 | __target_capacity = __allocation.count - 1; |
| 3355 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3356 | else |
| 3357 | { |
| 3358 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3359 | try |
| 3360 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3361 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3362 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3363 | __new_data = __allocation.ptr; |
| 3364 | __target_capacity = __allocation.count - 1; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3365 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3366 | } |
| 3367 | catch (...) |
| 3368 | { |
| 3369 | return; |
| 3370 | } |
| 3371 | #else // _LIBCPP_NO_EXCEPTIONS |
| 3372 | if (__new_data == nullptr) |
| 3373 | return; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3374 | #endif // _LIBCPP_NO_EXCEPTIONS |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3375 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3376 | __begin_lifetime(__new_data, __target_capacity + 1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3377 | __now_long = true; |
| 3378 | __was_long = __is_long(); |
| 3379 | __p = __get_pointer(); |
| 3380 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3381 | traits_type::copy(std::__to_address(__new_data), |
| 3382 | std::__to_address(__p), size()+1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3383 | if (__was_long) |
| 3384 | __alloc_traits::deallocate(__alloc(), __p, __cap+1); |
| 3385 | if (__now_long) |
| 3386 | { |
| 3387 | __set_long_cap(__target_capacity+1); |
| 3388 | __set_long_size(__sz); |
| 3389 | __set_long_pointer(__new_data); |
| 3390 | } |
| 3391 | else |
| 3392 | __set_short_size(__sz); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3393 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3397 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3398 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3399 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3400 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3401 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3402 | return *(data() + __pos); |
| 3403 | } |
| 3404 | |
| 3405 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3406 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3407 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3408 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3409 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3410 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3411 | return *(__get_pointer() + __pos); |
| 3412 | } |
| 3413 | |
| 3414 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3415 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3416 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 3417 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const |
| 3418 | { |
| 3419 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3420 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3421 | return (*this)[__n]; |
| 3422 | } |
| 3423 | |
| 3424 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3425 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3426 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 3427 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) |
| 3428 | { |
| 3429 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3430 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3431 | return (*this)[__n]; |
| 3432 | } |
| 3433 | |
| 3434 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3435 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3436 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3437 | basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3438 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3439 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3440 | return *__get_pointer(); |
| 3441 | } |
| 3442 | |
| 3443 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3444 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3445 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3446 | basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3447 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3448 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3449 | return *data(); |
| 3450 | } |
| 3451 | |
| 3452 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3453 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3454 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3455 | basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3456 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3457 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3458 | return *(__get_pointer() + size() - 1); |
| 3459 | } |
| 3460 | |
| 3461 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3462 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3463 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3464 | basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3465 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3466 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3467 | return *(data() + size() - 1); |
| 3468 | } |
| 3469 | |
| 3470 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3471 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3472 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3473 | 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] | 3474 | { |
| 3475 | size_type __sz = size(); |
| 3476 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3477 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3478 | size_type __rlen = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3479 | traits_type::copy(__s, data() + __pos, __rlen); |
| 3480 | return __rlen; |
| 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 | basic_string<_CharT, _Traits, _Allocator> |
| 3486 | basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const |
| 3487 | { |
| 3488 | return basic_string(*this, __pos, __n, __alloc()); |
| 3489 | } |
| 3490 | |
| 3491 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3492 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3493 | void |
| 3494 | basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3495 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3496 | _NOEXCEPT |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3497 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3498 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3499 | __is_nothrow_swappable<allocator_type>::value) |
| 3500 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3501 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 3502 | if (!__is_long()) |
| 3503 | std::__debug_db_invalidate_all(this); |
| 3504 | if (!__str.__is_long()) |
| 3505 | std::__debug_db_invalidate_all(&__str); |
| 3506 | std::__debug_db_swap(this, &__str); |
| 3507 | |
Eric Fiselier | 9bf691f | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 3508 | _LIBCPP_ASSERT( |
| 3509 | __alloc_traits::propagate_on_container_swap::value || |
| 3510 | __alloc_traits::is_always_equal::value || |
| 3511 | __alloc() == __str.__alloc(), "swapping non-equal allocators"); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3512 | std::swap(__r_.first(), __str.__r_.first()); |
| 3513 | std::__swap_allocator(__alloc(), __str.__alloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | // find |
| 3517 | |
| 3518 | template <class _Traits> |
| 3519 | struct _LIBCPP_HIDDEN __traits_eq |
| 3520 | { |
| 3521 | typedef typename _Traits::char_type char_type; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3522 | _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3523 | bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT |
| 3524 | {return _Traits::eq(__x, __y);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3525 | }; |
| 3526 | |
| 3527 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3528 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3529 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3530 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3531 | size_type __pos, |
| 3532 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3533 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3534 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3535 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3536 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3540 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3541 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3542 | basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, |
| 3543 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3544 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3545 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3546 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3550 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3551 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3552 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3553 | < |
| 3554 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3555 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3556 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3557 | basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3558 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3559 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3560 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3561 | return __str_find<value_type, size_type, traits_type, npos> |
| 3562 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3563 | } |
| 3564 | |
| 3565 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3566 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3567 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3568 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3569 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3570 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3571 | _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3572 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3573 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3577 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3578 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3579 | basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, |
| 3580 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3581 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3582 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3583 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
| 3586 | // rfind |
| 3587 | |
| 3588 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3589 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3590 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3591 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3592 | size_type __pos, |
| 3593 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3594 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3595 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3596 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3597 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3601 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3602 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3603 | basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, |
| 3604 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3605 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3606 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3607 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3611 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3612 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3613 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3614 | < |
| 3615 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3616 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3617 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3618 | basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3619 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3620 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3621 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3622 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 3623 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3624 | } |
| 3625 | |
| 3626 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3627 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3628 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3629 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3630 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3631 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3632 | _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3633 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3634 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3638 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3639 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3640 | basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, |
| 3641 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3642 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3643 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3644 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | // find_first_of |
| 3648 | |
| 3649 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3650 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3651 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3652 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3653 | size_type __pos, |
| 3654 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3655 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3656 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3657 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3658 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
| 3661 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3662 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3663 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3664 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, |
| 3665 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3666 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3667 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3668 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3672 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3673 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3674 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3675 | < |
| 3676 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3677 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3678 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3679 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3680 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3681 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3682 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3683 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 3684 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3685 | } |
| 3686 | |
| 3687 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3688 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3689 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3690 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3691 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3692 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3693 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3694 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3695 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3699 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3700 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3701 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, |
| 3702 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3703 | { |
| 3704 | return find(__c, __pos); |
| 3705 | } |
| 3706 | |
| 3707 | // find_last_of |
| 3708 | |
| 3709 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3710 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3711 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3712 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3713 | size_type __pos, |
| 3714 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3715 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3716 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3717 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3718 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3719 | } |
| 3720 | |
| 3721 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3722 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3723 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3724 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, |
| 3725 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3726 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3727 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3728 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
| 3731 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3732 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3733 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3734 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3735 | < |
| 3736 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3737 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3738 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3739 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3740 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3741 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3742 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3743 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 3744 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3745 | } |
| 3746 | |
| 3747 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3748 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3749 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3750 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3751 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3752 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3753 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3754 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3755 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3756 | } |
| 3757 | |
| 3758 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3759 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3760 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3761 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, |
| 3762 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3763 | { |
| 3764 | return rfind(__c, __pos); |
| 3765 | } |
| 3766 | |
| 3767 | // find_first_not_of |
| 3768 | |
| 3769 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3770 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3771 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3772 | 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] | 3773 | size_type __pos, |
| 3774 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3775 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3776 | _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] | 3777 | 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] | 3778 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3782 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3783 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3784 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, |
| 3785 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3786 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3787 | 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] | 3788 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3792 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3793 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3794 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3795 | < |
| 3796 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3797 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3798 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3799 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3800 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3801 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3802 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3803 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 3804 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3805 | } |
| 3806 | |
| 3807 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3808 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3809 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3810 | 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] | 3811 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3812 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3813 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3814 | 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] | 3815 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3819 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3820 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3821 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, |
| 3822 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3823 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3824 | 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] | 3825 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | // find_last_not_of |
| 3829 | |
| 3830 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3831 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3832 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3833 | 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] | 3834 | size_type __pos, |
| 3835 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3836 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3837 | _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] | 3838 | 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] | 3839 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3840 | } |
| 3841 | |
| 3842 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3843 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3844 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3845 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, |
| 3846 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3847 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3848 | 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] | 3849 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3853 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3854 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3855 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3856 | < |
| 3857 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3858 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3859 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3860 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3861 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3862 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3863 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3864 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 3865 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3866 | } |
| 3867 | |
| 3868 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3869 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3870 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3871 | 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] | 3872 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3873 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3874 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3875 | 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] | 3876 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
| 3879 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3880 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3881 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3882 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, |
| 3883 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3884 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3885 | 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] | 3886 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | // compare |
| 3890 | |
| 3891 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3892 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3893 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3894 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3895 | < |
| 3896 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3897 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3898 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3899 | basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3900 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3901 | __self_view __sv = __t; |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3902 | size_t __lhs_sz = size(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3903 | size_t __rhs_sz = __sv.size(); |
| 3904 | int __result = traits_type::compare(data(), __sv.data(), |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3905 | std::min(__lhs_sz, __rhs_sz)); |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3906 | if (__result != 0) |
| 3907 | return __result; |
| 3908 | if (__lhs_sz < __rhs_sz) |
| 3909 | return -1; |
| 3910 | if (__lhs_sz > __rhs_sz) |
| 3911 | return 1; |
| 3912 | return 0; |
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 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3918 | basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3919 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3920 | return compare(__self_view(__str)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3924 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3925 | int |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3926 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3927 | size_type __n1, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3928 | const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3929 | size_type __n2) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3930 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3931 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3932 | size_type __sz = size(); |
| 3933 | if (__pos1 > __sz || __n2 == npos) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3934 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3935 | size_type __rlen = std::min(__n1, __sz - __pos1); |
| 3936 | int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3937 | if (__r == 0) |
| 3938 | { |
| 3939 | if (__rlen < __n2) |
| 3940 | __r = -1; |
| 3941 | else if (__rlen > __n2) |
| 3942 | __r = 1; |
| 3943 | } |
| 3944 | return __r; |
| 3945 | } |
| 3946 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3947 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3948 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3949 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3950 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3951 | < |
| 3952 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3953 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3954 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3955 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3956 | size_type __n1, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3957 | const _Tp& __t) const |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3958 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3959 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3960 | return compare(__pos1, __n1, __sv.data(), __sv.size()); |
| 3961 | } |
| 3962 | |
| 3963 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3964 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3965 | int |
| 3966 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3967 | size_type __n1, |
| 3968 | const basic_string& __str) const |
| 3969 | { |
| 3970 | return compare(__pos1, __n1, __str.data(), __str.size()); |
| 3971 | } |
| 3972 | |
| 3973 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3974 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3975 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3976 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3977 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3978 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 3979 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 3980 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3981 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3982 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3983 | size_type __n1, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3984 | const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3985 | size_type __pos2, |
| 3986 | size_type __n2) const |
| 3987 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3988 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3989 | return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 3990 | } |
| 3991 | |
| 3992 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3993 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3994 | int |
| 3995 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3996 | size_type __n1, |
| 3997 | const basic_string& __str, |
| 3998 | size_type __pos2, |
| 3999 | size_type __n2) const |
| 4000 | { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4001 | return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4005 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4006 | int |
| 4007 | basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT |
| 4008 | { |
| 4009 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4010 | return compare(0, npos, __s, traits_type::length(__s)); |
| 4011 | } |
| 4012 | |
| 4013 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4014 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4015 | int |
| 4016 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4017 | size_type __n1, |
| 4018 | const value_type* __s) const |
| 4019 | { |
| 4020 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4021 | return compare(__pos1, __n1, __s, traits_type::length(__s)); |
| 4022 | } |
| 4023 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4024 | // __invariants |
| 4025 | |
| 4026 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4027 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4028 | bool |
| 4029 | basic_string<_CharT, _Traits, _Allocator>::__invariants() const |
| 4030 | { |
| 4031 | if (size() > capacity()) |
| 4032 | return false; |
| 4033 | if (capacity() < __min_cap - 1) |
| 4034 | return false; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4035 | if (data() == nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4036 | return false; |
Louis Dionne | 663415f | 2020-10-05 16:16:13 -0400 | [diff] [blame] | 4037 | if (data()[size()] != value_type()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4038 | return false; |
| 4039 | return true; |
| 4040 | } |
| 4041 | |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4042 | // __clear_and_shrink |
| 4043 | |
| 4044 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4045 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4046 | void |
Marshall Clow | e60a718 | 2018-05-29 17:04:37 +0000 | [diff] [blame] | 4047 | basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4048 | { |
| 4049 | clear(); |
| 4050 | if(__is_long()) |
| 4051 | { |
| 4052 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); |
| 4053 | __set_long_cap(0); |
| 4054 | __set_short_size(0); |
Louis Dionne | 663415f | 2020-10-05 16:16:13 -0400 | [diff] [blame] | 4055 | traits_type::assign(*__get_short_pointer(), value_type()); |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4056 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4057 | } |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4058 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4059 | // operator== |
| 4060 | |
| 4061 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4062 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4063 | bool |
| 4064 | operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4065 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4066 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4067 | #if _LIBCPP_STD_VER > 17 |
| 4068 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4069 | #else |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4070 | size_t __lhs_sz = __lhs.size(); |
| 4071 | return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), |
| 4072 | __rhs.data(), |
| 4073 | __lhs_sz) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4074 | #endif |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4075 | } |
| 4076 | |
| 4077 | template<class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4078 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4079 | bool |
| 4080 | operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, |
| 4081 | const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT |
| 4082 | { |
| 4083 | size_t __lhs_sz = __lhs.size(); |
| 4084 | if (__lhs_sz != __rhs.size()) |
| 4085 | return false; |
| 4086 | const char* __lp = __lhs.data(); |
| 4087 | const char* __rp = __rhs.data(); |
| 4088 | if (__lhs.__is_long()) |
| 4089 | return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; |
| 4090 | for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) |
| 4091 | if (*__lp != *__rp) |
| 4092 | return false; |
| 4093 | return true; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4094 | } |
| 4095 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4096 | #if _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4097 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4098 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4099 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4100 | operator==(const _CharT* __lhs, |
| 4101 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4102 | { |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4103 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4104 | _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); |
| 4105 | size_t __lhs_len = _Traits::length(__lhs); |
| 4106 | if (__lhs_len != __rhs.size()) return false; |
| 4107 | return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4108 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4109 | #endif // _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4110 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4111 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4112 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4113 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4114 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
| 4115 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4116 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4117 | #if _LIBCPP_STD_VER > 17 |
| 4118 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4119 | #else |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4120 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4121 | _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); |
| 4122 | size_t __rhs_len = _Traits::length(__rhs); |
| 4123 | if (__rhs_len != __lhs.size()) return false; |
| 4124 | return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4125 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4126 | } |
| 4127 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4128 | #if _LIBCPP_STD_VER > 17 |
| 4129 | |
| 4130 | template <class _CharT, class _Traits, class _Allocator> |
| 4131 | _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>( |
| 4132 | const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4133 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) noexcept { |
| 4134 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4135 | } |
| 4136 | |
| 4137 | template <class _CharT, class _Traits, class _Allocator> |
| 4138 | _LIBCPP_HIDE_FROM_ABI constexpr auto |
| 4139 | operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) { |
| 4140 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4141 | } |
| 4142 | |
| 4143 | #else // _LIBCPP_STD_VER > 17 |
| 4144 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4145 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4146 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4147 | bool |
| 4148 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4149 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4150 | { |
| 4151 | return !(__lhs == __rhs); |
| 4152 | } |
| 4153 | |
| 4154 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4155 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4156 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4157 | operator!=(const _CharT* __lhs, |
| 4158 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4159 | { |
| 4160 | return !(__lhs == __rhs); |
| 4161 | } |
| 4162 | |
| 4163 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4164 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4165 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4166 | operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4167 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4168 | { |
| 4169 | return !(__lhs == __rhs); |
| 4170 | } |
| 4171 | |
| 4172 | // operator< |
| 4173 | |
| 4174 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4175 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4176 | bool |
| 4177 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4178 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4179 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4180 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4181 | } |
| 4182 | |
| 4183 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4184 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4185 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4186 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4187 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4188 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4189 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4193 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4194 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4195 | operator< (const _CharT* __lhs, |
| 4196 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4197 | { |
| 4198 | return __rhs.compare(__lhs) > 0; |
| 4199 | } |
| 4200 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4201 | // operator> |
| 4202 | |
| 4203 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4204 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4205 | bool |
| 4206 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4207 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4208 | { |
| 4209 | return __rhs < __lhs; |
| 4210 | } |
| 4211 | |
| 4212 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4213 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4214 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4215 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4216 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4217 | { |
| 4218 | return __rhs < __lhs; |
| 4219 | } |
| 4220 | |
| 4221 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4222 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4223 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4224 | operator> (const _CharT* __lhs, |
| 4225 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4226 | { |
| 4227 | return __rhs < __lhs; |
| 4228 | } |
| 4229 | |
| 4230 | // operator<= |
| 4231 | |
| 4232 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4233 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4234 | bool |
| 4235 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4236 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4237 | { |
| 4238 | return !(__rhs < __lhs); |
| 4239 | } |
| 4240 | |
| 4241 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4242 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4243 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4244 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4245 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4246 | { |
| 4247 | return !(__rhs < __lhs); |
| 4248 | } |
| 4249 | |
| 4250 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4251 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4252 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4253 | operator<=(const _CharT* __lhs, |
| 4254 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4255 | { |
| 4256 | return !(__rhs < __lhs); |
| 4257 | } |
| 4258 | |
| 4259 | // operator>= |
| 4260 | |
| 4261 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4262 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4263 | bool |
| 4264 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4265 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4266 | { |
| 4267 | return !(__lhs < __rhs); |
| 4268 | } |
| 4269 | |
| 4270 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4271 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4272 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4273 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4274 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4275 | { |
| 4276 | return !(__lhs < __rhs); |
| 4277 | } |
| 4278 | |
| 4279 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4280 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4281 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4282 | operator>=(const _CharT* __lhs, |
| 4283 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4284 | { |
| 4285 | return !(__lhs < __rhs); |
| 4286 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4287 | #endif // _LIBCPP_STD_VER > 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4288 | |
| 4289 | // operator + |
| 4290 | |
| 4291 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4292 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4293 | basic_string<_CharT, _Traits, _Allocator> |
| 4294 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4295 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4296 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4297 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4298 | auto __lhs_sz = __lhs.size(); |
| 4299 | auto __rhs_sz = __rhs.size(); |
| 4300 | _String __r(__uninitialized_size_tag(), |
| 4301 | __lhs_sz + __rhs_sz, |
| 4302 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4303 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4304 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4305 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4306 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4307 | return __r; |
| 4308 | } |
| 4309 | |
| 4310 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4311 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4312 | basic_string<_CharT, _Traits, _Allocator> |
| 4313 | operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4314 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4315 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4316 | auto __lhs_sz = _Traits::length(__lhs); |
| 4317 | auto __rhs_sz = __rhs.size(); |
| 4318 | _String __r(__uninitialized_size_tag(), |
| 4319 | __lhs_sz + __rhs_sz, |
| 4320 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4321 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4322 | _Traits::copy(__ptr, __lhs, __lhs_sz); |
| 4323 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4324 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4325 | return __r; |
| 4326 | } |
| 4327 | |
| 4328 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4329 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4330 | basic_string<_CharT, _Traits, _Allocator> |
| 4331 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4332 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4333 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4334 | typename _String::size_type __rhs_sz = __rhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4335 | _String __r(__uninitialized_size_tag(), |
| 4336 | __rhs_sz + 1, |
| 4337 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4338 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4339 | _Traits::assign(__ptr, 1, __lhs); |
| 4340 | _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz); |
| 4341 | _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4342 | return __r; |
| 4343 | } |
| 4344 | |
| 4345 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4346 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4347 | basic_string<_CharT, _Traits, _Allocator> |
| 4348 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) |
| 4349 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4350 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4351 | typename _String::size_type __lhs_sz = __lhs.size(); |
| 4352 | typename _String::size_type __rhs_sz = _Traits::length(__rhs); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4353 | _String __r(__uninitialized_size_tag(), |
| 4354 | __lhs_sz + __rhs_sz, |
| 4355 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4356 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4357 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4358 | _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz); |
| 4359 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4360 | return __r; |
| 4361 | } |
| 4362 | |
| 4363 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4364 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4365 | basic_string<_CharT, _Traits, _Allocator> |
| 4366 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) |
| 4367 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4368 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4369 | typename _String::size_type __lhs_sz = __lhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4370 | _String __r(__uninitialized_size_tag(), |
| 4371 | __lhs_sz + 1, |
| 4372 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4373 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4374 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4375 | _Traits::assign(__ptr + __lhs_sz, 1, __rhs); |
| 4376 | _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4377 | return __r; |
| 4378 | } |
| 4379 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 4380 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4381 | |
| 4382 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4383 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4384 | basic_string<_CharT, _Traits, _Allocator> |
| 4385 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4386 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4387 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4388 | } |
| 4389 | |
| 4390 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4391 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4392 | basic_string<_CharT, _Traits, _Allocator> |
| 4393 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4394 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4395 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4399 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4400 | basic_string<_CharT, _Traits, _Allocator> |
| 4401 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4402 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4403 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
| 4406 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4407 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4408 | basic_string<_CharT, _Traits, _Allocator> |
| 4409 | operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4410 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4411 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4412 | } |
| 4413 | |
| 4414 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4415 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4416 | basic_string<_CharT, _Traits, _Allocator> |
| 4417 | operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4418 | { |
| 4419 | __rhs.insert(__rhs.begin(), __lhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4420 | return std::move(__rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4424 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4425 | basic_string<_CharT, _Traits, _Allocator> |
| 4426 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) |
| 4427 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4428 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4432 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4433 | basic_string<_CharT, _Traits, _Allocator> |
| 4434 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) |
| 4435 | { |
| 4436 | __lhs.push_back(__rhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4437 | return std::move(__lhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4438 | } |
| 4439 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4440 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4441 | |
| 4442 | // swap |
| 4443 | |
| 4444 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4445 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4446 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4447 | swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 4448 | basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4449 | _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4450 | { |
| 4451 | __lhs.swap(__rhs); |
| 4452 | } |
| 4453 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4454 | _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4455 | _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4456 | _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4457 | _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4458 | _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] | 4459 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4460 | _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr); |
| 4461 | _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr); |
| 4462 | _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] | 4463 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4464 | _LIBCPP_FUNC_VIS string to_string(int __val); |
| 4465 | _LIBCPP_FUNC_VIS string to_string(unsigned __val); |
| 4466 | _LIBCPP_FUNC_VIS string to_string(long __val); |
| 4467 | _LIBCPP_FUNC_VIS string to_string(unsigned long __val); |
| 4468 | _LIBCPP_FUNC_VIS string to_string(long long __val); |
| 4469 | _LIBCPP_FUNC_VIS string to_string(unsigned long long __val); |
| 4470 | _LIBCPP_FUNC_VIS string to_string(float __val); |
| 4471 | _LIBCPP_FUNC_VIS string to_string(double __val); |
| 4472 | _LIBCPP_FUNC_VIS string to_string(long double __val); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4473 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4474 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4475 | _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4476 | _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4477 | _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4478 | _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4479 | _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] | 4480 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4481 | _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr); |
| 4482 | _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr); |
| 4483 | _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] | 4484 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4485 | _LIBCPP_FUNC_VIS wstring to_wstring(int __val); |
| 4486 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); |
| 4487 | _LIBCPP_FUNC_VIS wstring to_wstring(long __val); |
| 4488 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); |
| 4489 | _LIBCPP_FUNC_VIS wstring to_wstring(long long __val); |
| 4490 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); |
| 4491 | _LIBCPP_FUNC_VIS wstring to_wstring(float __val); |
| 4492 | _LIBCPP_FUNC_VIS wstring to_wstring(double __val); |
| 4493 | _LIBCPP_FUNC_VIS wstring to_wstring(long double __val); |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4494 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4495 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4496 | template<class _CharT, class _Traits, class _Allocator> |
Martin Storsjö | 88890c2 | 2021-02-22 01:13:13 +0200 | [diff] [blame] | 4497 | _LIBCPP_TEMPLATE_DATA_VIS |
Eric Fiselier | c9fdaf1 | 2020-01-15 17:02:17 -0500 | [diff] [blame] | 4498 | const typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4499 | basic_string<_CharT, _Traits, _Allocator>::npos; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4500 | |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4501 | template <class _CharT, class _Allocator> |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4502 | 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] | 4503 | { |
| 4504 | size_t |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4505 | operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT |
| 4506 | { return __do_string_hash(__val.data(), __val.data() + __val.size()); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4507 | }; |
| 4508 | |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4509 | template <class _Allocator> |
| 4510 | struct hash<basic_string<char, char_traits<char>, _Allocator> > : __string_hash<char, _Allocator> {}; |
| 4511 | |
| 4512 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
| 4513 | template <class _Allocator> |
| 4514 | struct hash<basic_string<char8_t, char_traits<char8_t>, _Allocator> > : __string_hash<char8_t, _Allocator> {}; |
| 4515 | #endif |
| 4516 | |
| 4517 | template <class _Allocator> |
| 4518 | struct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __string_hash<char16_t, _Allocator> {}; |
| 4519 | |
| 4520 | template <class _Allocator> |
| 4521 | struct hash<basic_string<char32_t, char_traits<char32_t>, _Allocator> > : __string_hash<char32_t, _Allocator> {}; |
| 4522 | |
| 4523 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4524 | template <class _Allocator> |
| 4525 | struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Allocator> > : __string_hash<wchar_t, _Allocator> {}; |
| 4526 | #endif |
| 4527 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 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_ostream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4530 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4531 | const basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4532 | |
| 4533 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4534 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4535 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4536 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4537 | |
| 4538 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4539 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4540 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4541 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4542 | |
| 4543 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4544 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4545 | basic_istream<_CharT, _Traits>& |
| 4546 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4547 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4548 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4549 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4550 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4551 | basic_istream<_CharT, _Traits>& |
| 4552 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4553 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4554 | |
| 4555 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4556 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4557 | basic_istream<_CharT, _Traits>& |
| 4558 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4559 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4560 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4561 | #if _LIBCPP_STD_VER > 17 |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4562 | template <class _CharT, class _Traits, class _Allocator, class _Up> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4563 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4564 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4565 | erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) { |
| 4566 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4567 | __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end()); |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4568 | return __old_size - __str.size(); |
| 4569 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4570 | |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4571 | template <class _CharT, class _Traits, class _Allocator, class _Predicate> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4572 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4573 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4574 | erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, |
| 4575 | _Predicate __pred) { |
| 4576 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4577 | __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4578 | __str.end()); |
| 4579 | return __old_size - __str.size(); |
| 4580 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4581 | #endif |
| 4582 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4583 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4584 | |
| 4585 | template<class _CharT, class _Traits, class _Allocator> |
| 4586 | bool |
| 4587 | basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 4588 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4589 | return data() <= std::__to_address(__i->base()) && |
| 4590 | std::__to_address(__i->base()) < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | template<class _CharT, class _Traits, class _Allocator> |
| 4594 | bool |
| 4595 | basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const |
| 4596 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4597 | return data() < std::__to_address(__i->base()) && |
| 4598 | std::__to_address(__i->base()) <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | template<class _CharT, class _Traits, class _Allocator> |
| 4602 | bool |
| 4603 | basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 4604 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4605 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4606 | return data() <= __p && __p <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4607 | } |
| 4608 | |
| 4609 | template<class _CharT, class _Traits, class _Allocator> |
| 4610 | bool |
| 4611 | basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 4612 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4613 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4614 | return data() <= __p && __p < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4615 | } |
| 4616 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4617 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4618 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4619 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4620 | // Literal suffixes for basic_string [basic.string.literals] |
Marshall Clow | ac86837 | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 4621 | inline namespace literals |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4622 | { |
| 4623 | inline namespace string_literals |
| 4624 | { |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4625 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4626 | basic_string<char> operator "" s( const char *__str, size_t __len ) |
| 4627 | { |
| 4628 | return basic_string<char> (__str, __len); |
| 4629 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4630 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4631 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4632 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4633 | basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) |
| 4634 | { |
| 4635 | return basic_string<wchar_t> (__str, __len); |
| 4636 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4637 | #endif |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4638 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 4639 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4640 | inline _LIBCPP_HIDE_FROM_ABI constexpr |
Nikolas Klauser | 5da956d | 2022-09-02 16:20:28 +0200 | [diff] [blame] | 4641 | 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] | 4642 | { |
| 4643 | return basic_string<char8_t> (__str, __len); |
| 4644 | } |
| 4645 | #endif |
| 4646 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4647 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4648 | basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) |
| 4649 | { |
| 4650 | return basic_string<char16_t> (__str, __len); |
| 4651 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4652 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4653 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4654 | basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) |
| 4655 | { |
| 4656 | return basic_string<char32_t> (__str, __len); |
| 4657 | } |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 4658 | } // namespace string_literals |
| 4659 | } // namespace literals |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 4660 | |
| 4661 | #if _LIBCPP_STD_VER > 17 |
| 4662 | template <> |
| 4663 | inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true; |
| 4664 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4665 | template <> |
| 4666 | inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true; |
| 4667 | #endif |
| 4668 | #endif |
| 4669 | |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4670 | #endif |
| 4671 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4672 | _LIBCPP_END_NAMESPACE_STD |
| 4673 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 4674 | _LIBCPP_POP_MACROS |
| 4675 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 4676 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 4677 | # include <algorithm> |
| 4678 | # include <functional> |
| 4679 | # include <iterator> |
| 4680 | # include <new> |
| 4681 | # include <typeinfo> |
| 4682 | # include <utility> |
| 4683 | # include <vector> |
| 4684 | #endif |
| 4685 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4686 | #endif // _LIBCPP_STRING |