Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | 7642bb1 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_STRING |
| 11 | #define _LIBCPP_STRING |
| 12 | |
| 13 | /* |
| 14 | string synopsis |
| 15 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 16 | #include <compare> |
| 17 | #include <initializer_list> |
| 18 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | namespace std |
| 20 | { |
| 21 | |
| 22 | template <class stateT> |
| 23 | class fpos |
| 24 | { |
| 25 | private: |
| 26 | stateT st; |
| 27 | public: |
| 28 | fpos(streamoff = streamoff()); |
| 29 | |
| 30 | operator streamoff() const; |
| 31 | |
| 32 | stateT state() const; |
| 33 | void state(stateT); |
| 34 | |
| 35 | fpos& operator+=(streamoff); |
| 36 | fpos operator+ (streamoff) const; |
| 37 | fpos& operator-=(streamoff); |
| 38 | fpos operator- (streamoff) const; |
| 39 | }; |
| 40 | |
| 41 | template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); |
| 42 | |
| 43 | template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); |
| 44 | template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); |
| 45 | |
| 46 | template <class charT> |
| 47 | struct char_traits |
| 48 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 49 | using char_type = charT; |
| 50 | using int_type = ...; |
| 51 | using off_type = streamoff; |
| 52 | using pos_type = streampos; |
| 53 | using state_type = mbstate_t; |
| 54 | using comparison_category = strong_ordering; // Since C++20 only for the specializations |
| 55 | // char, wchar_t, char8_t, char16_t, and char32_t. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 57 | static void assign(char_type& c1, const char_type& c2) noexcept; |
Howard Hinnant | 270c00e | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 58 | static constexpr bool eq(char_type c1, char_type c2) noexcept; |
| 59 | static constexpr bool lt(char_type c1, char_type c2) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 60 | |
| 61 | static int compare(const char_type* s1, const char_type* s2, size_t n); |
| 62 | static size_t length(const char_type* s); |
| 63 | static const char_type* find(const char_type* s, size_t n, const char_type& a); |
| 64 | static char_type* move(char_type* s1, const char_type* s2, size_t n); |
| 65 | static char_type* copy(char_type* s1, const char_type* s2, size_t n); |
| 66 | static char_type* assign(char_type* s, size_t n, char_type a); |
| 67 | |
Howard Hinnant | 270c00e | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 68 | static constexpr int_type not_eof(int_type c) noexcept; |
| 69 | static constexpr char_type to_char_type(int_type c) noexcept; |
| 70 | static constexpr int_type to_int_type(char_type c) noexcept; |
| 71 | static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; |
| 72 | static constexpr int_type eof() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | template <> struct char_traits<char>; |
| 76 | template <> struct char_traits<wchar_t>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 77 | template <> struct char_traits<char8_t>; // C++20 |
| 78 | template <> struct char_traits<char16_t>; |
| 79 | template <> struct char_traits<char32_t>; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 81 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | class basic_string |
| 83 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 84 | public: |
| 85 | // types: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 86 | typedef traits traits_type; |
| 87 | typedef typename traits_type::char_type value_type; |
| 88 | typedef Allocator allocator_type; |
| 89 | typedef typename allocator_type::size_type size_type; |
| 90 | typedef typename allocator_type::difference_type difference_type; |
| 91 | typedef typename allocator_type::reference reference; |
| 92 | typedef typename allocator_type::const_reference const_reference; |
| 93 | typedef typename allocator_type::pointer pointer; |
| 94 | typedef typename allocator_type::const_pointer const_pointer; |
| 95 | typedef implementation-defined iterator; |
| 96 | typedef implementation-defined const_iterator; |
| 97 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 98 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 99 | |
| 100 | static const size_type npos = -1; |
| 101 | |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 102 | basic_string() |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 103 | noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20 |
| 104 | explicit basic_string(const allocator_type& a); // constexpr since C++20 |
| 105 | basic_string(const basic_string& str); // constexpr since C++20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 106 | basic_string(basic_string&& str) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 107 | noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 108 | basic_string(const basic_string& str, size_type pos, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 109 | const allocator_type& a = allocator_type()); // constexpr since C++20 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 110 | basic_string(const basic_string& str, size_type pos, size_type n, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 111 | const Allocator& a = Allocator()); // constexpr since C++20 |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 112 | constexpr basic_string( |
| 113 | basic_string&& str, size_type pos, const Allocator& a = Allocator()); // since C++23 |
| 114 | constexpr basic_string( |
| 115 | basic_string&& str, size_type pos, size_type n, const Allocator& a = Allocator()); // since C++23 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 116 | template<class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 117 | basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17, constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 118 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 119 | explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20 |
| 120 | basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 121 | basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type()); // constexpr since C++20 |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 122 | basic_string(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 123 | basic_string(size_type n, value_type c, const allocator_type& a = allocator_type()); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 | template<class InputIterator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 125 | basic_string(InputIterator begin, InputIterator end, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 126 | const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 127 | basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20 |
| 128 | basic_string(const basic_string&, const Allocator&); // constexpr since C++20 |
| 129 | basic_string(basic_string&&, const Allocator&); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 130 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 131 | ~basic_string(); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 132 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 133 | operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 134 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 135 | basic_string& operator=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 136 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 137 | basic_string& operator=(const T& t); // C++17, constexpr since C++20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 138 | basic_string& operator=(basic_string&& str) |
| 139 | noexcept( |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 140 | allocator_type::propagate_on_container_move_assignment::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 141 | allocator_type::is_always_equal::value ); // C++17, constexpr since C++20 |
| 142 | basic_string& operator=(const value_type* s); // constexpr since C++20 |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 143 | basic_string& operator=(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 144 | basic_string& operator=(value_type c); // constexpr since C++20 |
| 145 | basic_string& operator=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 146 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 147 | iterator begin() noexcept; // constexpr since C++20 |
| 148 | const_iterator begin() const noexcept; // constexpr since C++20 |
| 149 | iterator end() noexcept; // constexpr since C++20 |
| 150 | const_iterator end() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 151 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 152 | reverse_iterator rbegin() noexcept; // constexpr since C++20 |
| 153 | const_reverse_iterator rbegin() const noexcept; // constexpr since C++20 |
| 154 | reverse_iterator rend() noexcept; // constexpr since C++20 |
| 155 | const_reverse_iterator rend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 156 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 157 | const_iterator cbegin() const noexcept; // constexpr since C++20 |
| 158 | const_iterator cend() const noexcept; // constexpr since C++20 |
| 159 | const_reverse_iterator crbegin() const noexcept; // constexpr since C++20 |
| 160 | const_reverse_iterator crend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 161 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 162 | size_type size() const noexcept; // constexpr since C++20 |
| 163 | size_type length() const noexcept; // constexpr since C++20 |
| 164 | size_type max_size() const noexcept; // constexpr since C++20 |
| 165 | size_type capacity() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 167 | void resize(size_type n, value_type c); // constexpr since C++20 |
| 168 | void resize(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 170 | template<class Operation> |
| 171 | constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23 |
| 172 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 173 | void reserve(size_type res_arg); // constexpr since C++20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 174 | void reserve(); // deprecated in C++20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 175 | void shrink_to_fit(); // constexpr since C++20 |
| 176 | void clear() noexcept; // constexpr since C++20 |
| 177 | bool empty() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 178 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 179 | const_reference operator[](size_type pos) const; // constexpr since C++20 |
| 180 | reference operator[](size_type pos); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 181 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 182 | const_reference at(size_type n) const; // constexpr since C++20 |
| 183 | reference at(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 184 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 185 | basic_string& operator+=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 186 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 187 | basic_string& operator+=(const T& t); // C++17, constexpr since C++20 |
| 188 | basic_string& operator+=(const value_type* s); // constexpr since C++20 |
| 189 | basic_string& operator+=(value_type c); // constexpr since C++20 |
| 190 | basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 191 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 192 | basic_string& append(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 193 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 194 | basic_string& append(const T& t); // C++17, constexpr since C++20 |
| 195 | basic_string& append(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 196 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 197 | basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 198 | basic_string& append(const value_type* s, size_type n); // constexpr since C++20 |
| 199 | basic_string& append(const value_type* s); // constexpr since C++20 |
| 200 | basic_string& append(size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 201 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 202 | basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20 |
| 203 | basic_string& append(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 204 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 205 | void push_back(value_type c); // constexpr since C++20 |
| 206 | void pop_back(); // constexpr since C++20 |
| 207 | reference front(); // constexpr since C++20 |
| 208 | const_reference front() const; // constexpr since C++20 |
| 209 | reference back(); // constexpr since C++20 |
| 210 | const_reference back() const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 211 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 212 | basic_string& assign(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 213 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 214 | basic_string& assign(const T& t); // C++17, constexpr since C++20 |
| 215 | basic_string& assign(basic_string&& str); // constexpr since C++20 |
| 216 | basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 217 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 218 | basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 219 | basic_string& assign(const value_type* s, size_type n); // constexpr since C++20 |
| 220 | basic_string& assign(const value_type* s); // constexpr since C++20 |
| 221 | basic_string& assign(size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 222 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 223 | basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20 |
| 224 | basic_string& assign(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 225 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 226 | basic_string& insert(size_type pos1, const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 227 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 228 | basic_string& insert(size_type pos1, const T& t); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 229 | basic_string& insert(size_type pos1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 230 | size_type pos2, size_type n); // constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 231 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 232 | basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 233 | basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20 |
| 234 | basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20 |
| 235 | basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20 |
| 236 | iterator insert(const_iterator p, value_type c); // constexpr since C++20 |
| 237 | iterator insert(const_iterator p, size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 238 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 239 | iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20 |
| 240 | iterator insert(const_iterator p, initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 241 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 242 | basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20 |
| 243 | iterator erase(const_iterator position); // constexpr since C++20 |
| 244 | iterator erase(const_iterator first, const_iterator last); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 245 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 246 | basic_string& replace(size_type pos1, size_type n1, const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 247 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 248 | basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17, constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 249 | basic_string& replace(size_type pos1, size_type n1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 250 | size_type pos2, size_type n2=npos); // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 251 | template <class T> |
| 252 | basic_string& replace(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 253 | size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 254 | basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20 |
| 255 | basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20 |
| 256 | basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20 |
| 257 | basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 258 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 259 | basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20 |
| 260 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20 |
| 261 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20 |
| 262 | basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c); // constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 263 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 264 | basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20 |
| 265 | basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 266 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 267 | size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20 |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 268 | basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr in C++20, removed in C++23 |
| 269 | basic_string substr(size_type pos = 0, size_type n = npos) const&; // since C++23 |
| 270 | constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&; // since C++23 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 271 | void swap(basic_string& str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 272 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 273 | allocator_traits<allocator_type>::is_always_equal::value); // C++17, constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 274 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 275 | const value_type* c_str() const noexcept; // constexpr since C++20 |
| 276 | const value_type* data() const noexcept; // constexpr since C++20 |
| 277 | value_type* data() noexcept; // C++17, constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 279 | allocator_type get_allocator() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 281 | size_type find(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 282 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 283 | size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 284 | size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 285 | size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 286 | size_type find(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 287 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 288 | size_type rfind(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 289 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 290 | size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 291 | size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 292 | size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 293 | size_type rfind(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 295 | size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 296 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 297 | size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 298 | size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 299 | size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 300 | size_type find_first_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 302 | size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 303 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 304 | size_type find_last_of(const T& t, size_type pos = npos) const noexcept noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 305 | size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 306 | size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 307 | size_type find_last_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 308 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 309 | size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 310 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 311 | size_type find_first_not_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 312 | size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 313 | size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 314 | size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 315 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 316 | size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 317 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 318 | size_type find_last_not_of(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 319 | size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 320 | size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 321 | size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 322 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 323 | int compare(const basic_string& str) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 324 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 325 | int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 326 | int compare(size_type pos1, size_type n1, const basic_string& str) const; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 327 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 328 | int compare(size_type pos1, size_type n1, const T& t) const; // C++17, constexpr since C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 329 | int compare(size_type pos1, size_type n1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 330 | size_type pos2, size_type n2=npos) const; // C++14, constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 331 | template <class T> |
| 332 | int compare(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 333 | size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20 |
| 334 | int compare(const value_type* s) const noexcept; // constexpr since C++20 |
| 335 | int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20 |
| 336 | int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 337 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 338 | constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 339 | constexpr bool starts_with(charT c) const noexcept; // C++20 |
| 340 | constexpr bool starts_with(const charT* s) const; // C++20 |
| 341 | constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 342 | constexpr bool ends_with(charT c) const noexcept; // C++20 |
| 343 | constexpr bool ends_with(const charT* s) const; // C++20 |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 344 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 345 | constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b |
| 346 | constexpr bool contains(charT c) const noexcept; // C++2b |
| 347 | constexpr bool contains(const charT* s) const; // C++2b |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 348 | }; |
| 349 | |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 350 | template<class InputIterator, |
| 351 | class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> |
| 352 | basic_string(InputIterator, InputIterator, Allocator = Allocator()) |
| 353 | -> basic_string<typename iterator_traits<InputIterator>::value_type, |
| 354 | char_traits<typename iterator_traits<InputIterator>::value_type>, |
| 355 | Allocator>; // C++17 |
| 356 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 357 | template<class charT, class traits, class Allocator> |
| 358 | basic_string<charT, traits, Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 359 | operator+(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 360 | const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 361 | |
| 362 | template<class charT, class traits, class Allocator> |
| 363 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 364 | operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 365 | |
| 366 | template<class charT, class traits, class Allocator> |
| 367 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 368 | operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 369 | |
| 370 | template<class charT, class traits, class Allocator> |
| 371 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 372 | operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 373 | |
| 374 | template<class charT, class traits, class Allocator> |
| 375 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 376 | operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 377 | |
| 378 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 379 | bool operator==(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 380 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 381 | |
| 382 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 383 | bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | |
| 385 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 386 | bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 387 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 388 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 389 | bool operator!=(const basic_string<charT,traits,Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 390 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | |
| 392 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 393 | bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | |
| 395 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 396 | bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 397 | |
| 398 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 399 | bool operator< (const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 400 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | |
| 402 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 403 | bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | |
| 405 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 406 | bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 407 | |
| 408 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 409 | bool operator> (const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 410 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | |
| 412 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 413 | bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 414 | |
| 415 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 416 | bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 417 | |
| 418 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 419 | bool operator<=(const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 420 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | |
| 422 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 423 | bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | |
| 425 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 426 | bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 427 | |
| 428 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 429 | bool operator>=(const basic_string<charT, traits, Allocator>& lhs, |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 430 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 431 | |
| 432 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 433 | bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept; // removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 434 | |
| 435 | template<class charT, class traits, class Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 436 | bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // removed in C++20 |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 437 | |
| 438 | template<class charT, class traits, class Allocator> // since C++20 |
| 439 | constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, |
| 440 | const basic_string<charT, traits, Allocator>& rhs) noexcept; |
| 441 | |
| 442 | template<class charT, class traits, class Allocator> // since C++20 |
| 443 | constexpr see below operator<=>(const basic_string<charT, traits, Allocator>& lhs, |
| 444 | const charT* rhs) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | |
| 446 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 447 | void swap(basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 448 | basic_string<charT, traits, Allocator>& rhs) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 449 | noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 450 | |
| 451 | template<class charT, class traits, class Allocator> |
| 452 | basic_istream<charT, traits>& |
| 453 | operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 454 | |
| 455 | template<class charT, class traits, class Allocator> |
| 456 | basic_ostream<charT, traits>& |
| 457 | operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); |
| 458 | |
| 459 | template<class charT, class traits, class Allocator> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 460 | basic_istream<charT, traits>& |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 461 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, |
| 462 | charT delim); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | |
| 464 | template<class charT, class traits, class Allocator> |
| 465 | basic_istream<charT, traits>& |
| 466 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 467 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 468 | template<class charT, class traits, class Allocator, class U> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 469 | typename basic_string<charT, traits, Allocator>::size_type |
| 470 | erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 471 | template<class charT, class traits, class Allocator, class Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 472 | typename basic_string<charT, traits, Allocator>::size_type |
| 473 | erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 474 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 475 | typedef basic_string<char> string; |
| 476 | typedef basic_string<wchar_t> wstring; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 477 | typedef basic_string<char8_t> u8string; // C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 478 | typedef basic_string<char16_t> u16string; |
| 479 | typedef basic_string<char32_t> u32string; |
| 480 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 481 | int stoi (const string& str, size_t* idx = nullptr, int base = 10); |
| 482 | long stol (const string& str, size_t* idx = nullptr, int base = 10); |
| 483 | unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10); |
| 484 | long long stoll (const string& str, size_t* idx = nullptr, int base = 10); |
| 485 | unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 10); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 486 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 487 | float stof (const string& str, size_t* idx = nullptr); |
| 488 | double stod (const string& str, size_t* idx = nullptr); |
| 489 | long double stold(const string& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 490 | |
| 491 | string to_string(int val); |
| 492 | string to_string(unsigned val); |
| 493 | string to_string(long val); |
| 494 | string to_string(unsigned long val); |
| 495 | string to_string(long long val); |
| 496 | string to_string(unsigned long long val); |
| 497 | string to_string(float val); |
| 498 | string to_string(double val); |
| 499 | string to_string(long double val); |
| 500 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 501 | int stoi (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 502 | long stol (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 503 | unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 504 | long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 505 | unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base = 10); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 506 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 507 | float stof (const wstring& str, size_t* idx = nullptr); |
| 508 | double stod (const wstring& str, size_t* idx = nullptr); |
| 509 | long double stold(const wstring& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 510 | |
| 511 | wstring to_wstring(int val); |
| 512 | wstring to_wstring(unsigned val); |
| 513 | wstring to_wstring(long val); |
| 514 | wstring to_wstring(unsigned long val); |
| 515 | wstring to_wstring(long long val); |
| 516 | wstring to_wstring(unsigned long long val); |
| 517 | wstring to_wstring(float val); |
| 518 | wstring to_wstring(double val); |
| 519 | wstring to_wstring(long double val); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | |
| 521 | template <> struct hash<string>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 522 | template <> struct hash<u8string>; // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 523 | template <> struct hash<u16string>; |
| 524 | template <> struct hash<u32string>; |
| 525 | template <> struct hash<wstring>; |
| 526 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 527 | basic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20 |
| 528 | basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20 |
| 529 | constexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20 |
| 530 | basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20 |
| 531 | basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14, constexpr since C++20 |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 532 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 533 | } // std |
| 534 | |
| 535 | */ |
| 536 | |
Nikolas Klauser | f210d8a | 2022-02-15 18:18:08 +0100 | [diff] [blame] | 537 | #include <__algorithm/max.h> |
| 538 | #include <__algorithm/min.h> |
| 539 | #include <__algorithm/remove.h> |
| 540 | #include <__algorithm/remove_if.h> |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 541 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 542 | #include <__config> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 543 | #include <__debug> |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 544 | #include <__format/enable_insertable.h> |
Nikolas Klauser | 11a0ff3 | 2022-06-06 23:35:24 +0200 | [diff] [blame] | 545 | #include <__functional/hash.h> |
Nikolas Klauser | 24540d3 | 2022-05-21 00:45:51 +0200 | [diff] [blame] | 546 | #include <__functional/unary_function.h> |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 547 | #include <__fwd/string.h> |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 548 | #include <__ios/fpos.h> |
Nikolas Klauser | fb1b067 | 2022-06-10 19:53:10 +0200 | [diff] [blame] | 549 | #include <__iterator/distance.h> |
| 550 | #include <__iterator/iterator_traits.h> |
| 551 | #include <__iterator/reverse_iterator.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 552 | #include <__iterator/wrap_iter.h> |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 553 | #include <__memory/allocate_at_least.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 554 | #include <__memory/allocator.h> |
| 555 | #include <__memory/allocator_traits.h> |
| 556 | #include <__memory/compressed_pair.h> |
| 557 | #include <__memory/construct_at.h> |
| 558 | #include <__memory/pointer_traits.h> |
Nikolas Klauser | 35080b4 | 2022-07-26 16:13:56 +0200 | [diff] [blame] | 559 | #include <__memory/swap_allocator.h> |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 560 | #include <__memory_resource/polymorphic_allocator.h> |
Nikolas Klauser | 11a0ff3 | 2022-06-06 23:35:24 +0200 | [diff] [blame] | 561 | #include <__string/char_traits.h> |
| 562 | #include <__string/extern_template_lists.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 563 | #include <__type_traits/is_allocator.h> |
| 564 | #include <__type_traits/noexcept_move_assign_container.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 565 | #include <__utility/auto_cast.h> |
| 566 | #include <__utility/move.h> |
| 567 | #include <__utility/swap.h> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 568 | #include <__utility/unreachable.h> |
| 569 | #include <climits> |
Louis Dionne | 44962c3 | 2022-06-13 11:21:16 -0400 | [diff] [blame] | 570 | #include <cstdint> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 571 | #include <cstdio> // EOF |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 572 | #include <cstdlib> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 573 | #include <cstring> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 574 | #include <limits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | #include <stdexcept> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 576 | #include <string_view> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 578 | #include <version> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 579 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 580 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 581 | # include <cwchar> |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 582 | #endif |
| 583 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 584 | // standard-mandated includes |
| 585 | |
| 586 | // [iterator.range] |
| 587 | #include <__iterator/access.h> |
| 588 | #include <__iterator/data.h> |
| 589 | #include <__iterator/empty.h> |
| 590 | #include <__iterator/reverse_access.h> |
| 591 | #include <__iterator/size.h> |
| 592 | |
| 593 | // [string.syn] |
| 594 | #include <compare> |
| 595 | #include <initializer_list> |
| 596 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 597 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 598 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 599 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 600 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 601 | _LIBCPP_PUSH_MACROS |
| 602 | #include <__undef_macros> |
| 603 | |
| 604 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 605 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 606 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 607 | // basic_string |
| 608 | |
| 609 | template<class _CharT, class _Traits, class _Allocator> |
| 610 | basic_string<_CharT, _Traits, _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 611 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 612 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, |
| 613 | const basic_string<_CharT, _Traits, _Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 614 | |
| 615 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 616 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 617 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 618 | operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 619 | |
| 620 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 621 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 623 | operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 624 | |
| 625 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 626 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 627 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 628 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 629 | |
| 630 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 631 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 633 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 634 | |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 635 | extern template _LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&); |
Shoaib Meenai | ea36371 | 2017-07-29 02:54:41 +0000 | [diff] [blame] | 636 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 637 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 638 | struct __string_is_trivial_iterator : public false_type {}; |
| 639 | |
| 640 | template <class _Tp> |
| 641 | struct __string_is_trivial_iterator<_Tp*> |
| 642 | : public is_arithmetic<_Tp> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 643 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 644 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 645 | struct __string_is_trivial_iterator<__wrap_iter<_Iter> > |
| 646 | : public __string_is_trivial_iterator<_Iter> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 647 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 648 | template <class _CharT, class _Traits, class _Tp> |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 649 | struct __can_be_converted_to_string_view : public _BoolConstant< |
| 650 | is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && |
| 651 | !is_convertible<const _Tp&, const _CharT*>::value |
| 652 | > {}; |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 653 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 654 | struct __uninitialized_size_tag {}; |
| 655 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 656 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 657 | class basic_string |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 658 | { |
| 659 | public: |
| 660 | typedef basic_string __self; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 661 | typedef basic_string_view<_CharT, _Traits> __self_view; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | typedef _Traits traits_type; |
Marshall Clow | a3a74e0 | 2017-03-15 18:41:11 +0000 | [diff] [blame] | 663 | typedef _CharT value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 664 | typedef _Allocator allocator_type; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 665 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 666 | typedef typename __alloc_traits::size_type size_type; |
| 667 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 668 | typedef value_type& reference; |
| 669 | typedef const value_type& const_reference; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 670 | typedef typename __alloc_traits::pointer pointer; |
| 671 | typedef typename __alloc_traits::const_pointer const_pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 672 | |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 673 | static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); |
| 674 | static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); |
| 675 | static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); |
| 676 | static_assert(( is_same<_CharT, typename traits_type::char_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 677 | "traits_type::char_type must be the same type as CharT"); |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 678 | static_assert(( is_same<typename allocator_type::value_type, value_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 679 | "Allocator::value_type must be same type as value_type"); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 680 | |
Nikolas Klauser | eb116e2 | 2022-10-08 22:17:32 +0200 | [diff] [blame] | 681 | static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value, |
| 682 | "[allocator.requirements] states that rebinding an allocator to the same type should result in the " |
| 683 | "original allocator"); |
| 684 | |
Louis Dionne | dd059fa | 2022-11-14 10:33:03 -1000 | [diff] [blame] | 685 | // TODO: Implement iterator bounds checking without requiring the global database. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 686 | typedef __wrap_iter<pointer> iterator; |
| 687 | typedef __wrap_iter<const_pointer> const_iterator; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 688 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 689 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 690 | |
| 691 | private: |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 692 | 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] | 693 | |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 694 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 695 | |
| 696 | struct __long |
| 697 | { |
| 698 | pointer __data_; |
| 699 | size_type __size_; |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 700 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 701 | size_type __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 702 | }; |
| 703 | |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 704 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 705 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 706 | |
| 707 | struct __short |
| 708 | { |
| 709 | value_type __data_[__min_cap]; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 710 | unsigned char __padding_[sizeof(value_type) - 1]; |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 711 | unsigned char __size_ : 7; |
| 712 | unsigned char __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 713 | }; |
| 714 | |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 715 | // 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] | 716 | // 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] | 717 | // |
| 718 | // If the LSB is used to store the short-flag in the short string representation, |
| 719 | // we have to multiply the size by two when it is stored and divide it by two when |
| 720 | // it is loaded to make sure that we always store an even number. In the long string |
| 721 | // representation, we can ignore this because we can assume that we always allocate |
| 722 | // an even amount of value_types. |
| 723 | // |
| 724 | // If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2. |
| 725 | // This does not impact the short string representation, since we never need the MSB |
| 726 | // for representing the size of a short string anyway. |
| 727 | |
| 728 | #ifdef _LIBCPP_BIG_ENDIAN |
| 729 | static const size_type __endian_factor = 2; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 730 | #else |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 731 | static const size_type __endian_factor = 1; |
| 732 | #endif |
| 733 | |
| 734 | #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 735 | |
| 736 | #ifdef _LIBCPP_BIG_ENDIAN |
| 737 | static const size_type __endian_factor = 1; |
| 738 | #else |
| 739 | static const size_type __endian_factor = 2; |
| 740 | #endif |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 741 | |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 742 | // Attribute 'packed' is used to keep the layout compatible with the |
| 743 | // previous definition that did not use bit fields. This is because on |
| 744 | // some platforms bit fields have a default size rather than the actual |
| 745 | // 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] | 746 | struct __long |
| 747 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 748 | struct _LIBCPP_PACKED { |
| 749 | size_type __is_long_ : 1; |
| 750 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 751 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 752 | size_type __size_; |
| 753 | pointer __data_; |
| 754 | }; |
| 755 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 756 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 757 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 758 | |
| 759 | struct __short |
| 760 | { |
Xing Xue | 38b9fc4 | 2022-06-24 17:25:15 -0400 | [diff] [blame] | 761 | struct _LIBCPP_PACKED { |
| 762 | unsigned char __is_long_ : 1; |
| 763 | unsigned char __size_ : 7; |
| 764 | }; |
Nikolas Klauser | 1aa2111 | 2022-05-14 12:38:00 +0200 | [diff] [blame] | 765 | char __padding_[sizeof(value_type) - 1]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 766 | value_type __data_[__min_cap]; |
| 767 | }; |
| 768 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 769 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 770 | |
Nikolas Klauser | 95cfe62 | 2022-06-11 23:43:00 +0200 | [diff] [blame] | 771 | static_assert(sizeof(__short) == (sizeof(value_type) * (__min_cap + 1)), "__short has an unexpected size."); |
| 772 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 773 | union __ulx{__long __lx; __short __lxx;}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 774 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 775 | enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 776 | |
| 777 | struct __raw |
| 778 | { |
| 779 | size_type __words[__n_words]; |
| 780 | }; |
| 781 | |
| 782 | struct __rep |
| 783 | { |
| 784 | union |
| 785 | { |
| 786 | __long __l; |
| 787 | __short __s; |
| 788 | __raw __r; |
| 789 | }; |
| 790 | }; |
| 791 | |
| 792 | __compressed_pair<__rep, allocator_type> __r_; |
| 793 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 794 | // Construct a string with the given allocator and enough storage to hold `__size` characters, but |
| 795 | // don't initialize the characters. The contents of the string, including the null terminator, must be |
| 796 | // initialized separately. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 797 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 798 | 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] | 799 | : __r_(__default_init_tag(), __a) { |
| 800 | if (__size > max_size()) |
| 801 | __throw_length_error(); |
| 802 | if (__fits_in_sso(__size)) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 803 | __r_.first() = __rep(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 804 | __set_short_size(__size); |
| 805 | } else { |
| 806 | auto __capacity = __recommend(__size) + 1; |
| 807 | auto __allocation = __alloc_traits::allocate(__alloc(), __capacity); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 808 | __begin_lifetime(__allocation, __capacity); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 809 | __set_long_cap(__capacity); |
| 810 | __set_long_pointer(__allocation); |
| 811 | __set_long_size(__size); |
| 812 | } |
| 813 | std::__debug_db_insert_c(this); |
| 814 | } |
| 815 | |
Louis Dionne | cd0a050 | 2022-11-14 11:01:05 -1000 | [diff] [blame] | 816 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator __make_iterator(pointer __p) { |
| 817 | return iterator(this, __p); |
| 818 | } |
| 819 | |
| 820 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_iterator __make_const_iterator(const_pointer __p) const { |
| 821 | return const_iterator(this, __p); |
| 822 | } |
| 823 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 824 | public: |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 825 | _LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 826 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 827 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() |
| 828 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
| 829 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 830 | std::__debug_db_insert_c(this); |
| 831 | __default_init(); |
| 832 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 833 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 834 | _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] | 835 | #if _LIBCPP_STD_VER <= 14 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 836 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 837 | #else |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 838 | _NOEXCEPT |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 839 | #endif |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 840 | : __r_(__default_init_tag(), __a) { |
| 841 | std::__debug_db_insert_c(this); |
| 842 | __default_init(); |
| 843 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 844 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 845 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str); |
| 846 | _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] | 847 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 848 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 849 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str) |
| 850 | # if _LIBCPP_STD_VER <= 14 |
| 851 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
| 852 | # else |
| 853 | _NOEXCEPT |
| 854 | # endif |
| 855 | : __r_(std::move(__str.__r_)) { |
| 856 | __str.__default_init(); |
| 857 | std::__debug_db_insert_c(this); |
| 858 | if (__is_long()) |
| 859 | std::__debug_db_swap(this, &__str); |
| 860 | } |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 861 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 862 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(basic_string&& __str, const allocator_type& __a) |
| 863 | : __r_(__default_init_tag(), __a) { |
| 864 | if (__str.__is_long() && __a != __str.__alloc()) // copy, not move |
| 865 | __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); |
| 866 | else { |
| 867 | if (__libcpp_is_constant_evaluated()) |
| 868 | __r_.first() = __rep(); |
| 869 | __r_.first() = __str.__r_.first(); |
| 870 | __str.__default_init(); |
| 871 | } |
| 872 | std::__debug_db_insert_c(this); |
| 873 | if (__is_long()) |
| 874 | std::__debug_db_swap(this, &__str); |
| 875 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 876 | #endif // _LIBCPP_CXX03_LANG |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 877 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 878 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 879 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s) |
| 880 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 881 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); |
| 882 | __init(__s, traits_type::length(__s)); |
| 883 | std::__debug_db_insert_c(this); |
| 884 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 885 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 886 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 887 | _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] | 888 | |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 889 | #if _LIBCPP_STD_VER > 20 |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 890 | basic_string(nullptr_t) = delete; |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 891 | #endif |
| 892 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 893 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, size_type __n) |
| 894 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 895 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); |
| 896 | __init(__s, __n); |
| 897 | std::__debug_db_insert_c(this); |
| 898 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 899 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 900 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 901 | basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) |
| 902 | : __r_(__default_init_tag(), __a) { |
| 903 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); |
| 904 | __init(__s, __n); |
| 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 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(size_type __n, _CharT __c) |
| 909 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 910 | __init(__n, __c); |
| 911 | std::__debug_db_insert_c(this); |
| 912 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 913 | |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 914 | #if _LIBCPP_STD_VER > 20 |
| 915 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 916 | basic_string(basic_string&& __str, size_type __pos, const _Allocator& __alloc = _Allocator()) |
| 917 | : basic_string(std::move(__str), __pos, npos, __alloc) {} |
| 918 | |
| 919 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 920 | basic_string(basic_string&& __str, size_type __pos, size_type __n, const _Allocator& __alloc = _Allocator()) |
| 921 | : __r_(__default_init_tag(), __alloc) { |
| 922 | if (__pos > __str.size()) |
| 923 | __throw_out_of_range(); |
| 924 | |
| 925 | auto __len = std::min<size_type>(__n, __str.size() - __pos); |
| 926 | if (__alloc_traits::is_always_equal::value || __alloc == __str.__alloc()) { |
| 927 | __r_.first() = __str.__r_.first(); |
| 928 | __str.__default_init(); |
| 929 | |
| 930 | _Traits::move(data(), data() + __pos, __len); |
| 931 | __set_size(__len); |
| 932 | _Traits::assign(data()[__len], value_type()); |
| 933 | } else { |
| 934 | // Perform a copy because the allocators are not compatible. |
| 935 | __init(__str.data() + __pos, __len); |
| 936 | } |
| 937 | |
| 938 | std::__debug_db_insert_c(this); |
| 939 | if (__is_long()) |
| 940 | std::__debug_db_swap(this, &__str); |
| 941 | } |
| 942 | #endif |
| 943 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 944 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
| 945 | _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] | 946 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 947 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 948 | 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] | 949 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 950 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 951 | basic_string(const basic_string& __str, size_type __pos, const _Allocator& __a = _Allocator()) |
| 952 | : __r_(__default_init_tag(), __a) { |
| 953 | size_type __str_sz = __str.size(); |
| 954 | if (__pos > __str_sz) |
| 955 | __throw_out_of_range(); |
| 956 | __init(__str.data() + __pos, __str_sz - __pos); |
| 957 | std::__debug_db_insert_c(this); |
| 958 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 959 | |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 960 | template <class _Tp, |
| 961 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 962 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 963 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 964 | basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()); |
| 965 | |
| 966 | template <class _Tp, |
| 967 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 968 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 969 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 970 | const _Tp& __t); |
| 971 | |
| 972 | template <class _Tp, |
| 973 | class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 974 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 975 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( |
| 976 | const _Tp& __t, const allocator_type& __a); |
| 977 | |
| 978 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 979 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(_InputIterator __first, _InputIterator __last) |
| 980 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 981 | __init(__first, __last); |
| 982 | std::__debug_db_insert_c(this); |
| 983 | } |
| 984 | |
| 985 | template <class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
| 986 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
| 987 | basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a) |
| 988 | : __r_(__default_init_tag(), __a) { |
| 989 | __init(__first, __last); |
| 990 | std::__debug_db_insert_c(this); |
| 991 | } |
| 992 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 993 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | d128f2b | 2022-08-26 18:35:25 +0200 | [diff] [blame] | 994 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il) |
| 995 | : __r_(__default_init_tag(), __default_init_tag()) { |
| 996 | __init(__il.begin(), __il.end()); |
| 997 | std::__debug_db_insert_c(this); |
| 998 | } |
| 999 | |
| 1000 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(initializer_list<_CharT> __il, const _Allocator& __a) |
| 1001 | : __r_(__default_init_tag(), __a) { |
| 1002 | __init(__il.begin(), __il.end()); |
| 1003 | std::__debug_db_insert_c(this); |
| 1004 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1005 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1006 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1007 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1008 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1009 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 1010 | operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } |
| 1011 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1012 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const basic_string& __str); |
Eric Fiselier | 5ec13b1 | 2017-01-23 21:24:58 +0000 | [diff] [blame] | 1013 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1014 | template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 1015 | !__is_same_uncvref<_Tp, basic_string>::value> > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1016 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(const _Tp& __t) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1017 | __self_view __sv = __t; |
| 1018 | return assign(__sv); |
| 1019 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1020 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1021 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1022 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(basic_string&& __str) |
| 1023 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { |
| 1024 | __move_assign(__str, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 1025 | return *this; |
| 1026 | } |
| 1027 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1028 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1029 | 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] | 1030 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1031 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1032 | basic_string& operator=(const value_type* __s) {return assign(__s);} |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 1033 | #if _LIBCPP_STD_VER > 20 |
| 1034 | basic_string& operator=(nullptr_t) = delete; |
| 1035 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1036 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& operator=(value_type __c); |
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 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1039 | iterator begin() _NOEXCEPT |
Louis Dionne | cd0a050 | 2022-11-14 11:01:05 -1000 | [diff] [blame] | 1040 | {return __make_iterator(__get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1041 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1042 | const_iterator begin() const _NOEXCEPT |
Louis Dionne | cd0a050 | 2022-11-14 11:01:05 -1000 | [diff] [blame] | 1043 | {return __make_const_iterator(__get_pointer());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1044 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1045 | iterator end() _NOEXCEPT |
Louis Dionne | cd0a050 | 2022-11-14 11:01:05 -1000 | [diff] [blame] | 1046 | {return __make_iterator(__get_pointer() + size());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1047 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1048 | const_iterator end() const _NOEXCEPT |
Louis Dionne | cd0a050 | 2022-11-14 11:01:05 -1000 | [diff] [blame] | 1049 | {return __make_const_iterator(__get_pointer() + size());} |
Louis Dionne | e554e10 | 2022-06-03 15:17:03 -0400 | [diff] [blame] | 1050 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1051 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1052 | reverse_iterator rbegin() _NOEXCEPT |
| 1053 | {return reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1054 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1055 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 1056 | {return const_reverse_iterator(end());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1057 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1058 | reverse_iterator rend() _NOEXCEPT |
| 1059 | {return reverse_iterator(begin());} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1060 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1061 | const_reverse_iterator rend() const _NOEXCEPT |
| 1062 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1063 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1064 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1065 | const_iterator cbegin() const _NOEXCEPT |
| 1066 | {return begin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1067 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1068 | const_iterator cend() const _NOEXCEPT |
| 1069 | {return end();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1070 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1071 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 1072 | {return rbegin();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1073 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1074 | const_reverse_iterator crend() const _NOEXCEPT |
| 1075 | {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1077 | _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] | 1078 | {return __is_long() ? __get_long_size() : __get_short_size();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1079 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type length() const _NOEXCEPT {return size();} |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1080 | |
| 1081 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type max_size() const _NOEXCEPT { |
| 1082 | size_type __m = __alloc_traits::max_size(__alloc()); |
| 1083 | if (__m <= std::numeric_limits<size_type>::max() / 2) { |
| 1084 | return __m - __alignment; |
| 1085 | } else { |
| 1086 | bool __uses_lsb = __endian_factor == 2; |
| 1087 | return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment; |
| 1088 | } |
| 1089 | } |
| 1090 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1091 | _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] | 1092 | return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1; |
| 1093 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1094 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1095 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void resize(size_type __n, value_type __c); |
| 1096 | _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] | 1097 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1098 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void reserve(size_type __requested_capacity); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1099 | |
| 1100 | #if _LIBCPP_STD_VER > 20 |
| 1101 | template <class _Op> |
| 1102 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1103 | void resize_and_overwrite(size_type __n, _Op __op) { |
| 1104 | __resize_default_init(__n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1105 | __erase_to_end(std::move(__op)(data(), _LIBCPP_AUTO_CAST(__n))); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 1106 | } |
| 1107 | #endif |
| 1108 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1109 | _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] | 1110 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1111 | _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] | 1112 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void shrink_to_fit() _NOEXCEPT; |
| 1113 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void clear() _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1114 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1115 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 1116 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1117 | |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1118 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference operator[](size_type __pos) const _NOEXCEPT { |
| 1119 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
| 1120 | return *(data() + __pos); |
| 1121 | } |
| 1122 | |
| 1123 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference operator[](size_type __pos) _NOEXCEPT { |
| 1124 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
| 1125 | return *(__get_pointer() + __pos); |
| 1126 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1128 | _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference at(size_type __n) const; |
| 1129 | _LIBCPP_CONSTEXPR_SINCE_CXX20 reference at(size_type __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1130 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1131 | _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] | 1132 | return append(__str); |
| 1133 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1134 | |
| 1135 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1136 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1137 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1138 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1139 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1140 | && !__is_same_uncvref<_Tp, basic_string >::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1141 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1142 | > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1143 | operator+=(const _Tp& __t) { |
| 1144 | __self_view __sv = __t; return append(__sv); |
| 1145 | } |
| 1146 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1147 | _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] | 1148 | return append(__s); |
| 1149 | } |
| 1150 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1151 | _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] | 1152 | push_back(__c); |
| 1153 | return *this; |
| 1154 | } |
| 1155 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1156 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1157 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1158 | basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1159 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1160 | |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1161 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const basic_string& __str) { |
| 1162 | return append(__str.data(), __str.size()); |
| 1163 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1164 | |
| 1165 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1166 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1167 | __enable_if_t< |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1168 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1169 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1170 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1171 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1172 | 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] | 1173 | _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] | 1174 | |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 1175 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1176 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1177 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1178 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1179 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1180 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1181 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1182 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1183 | append(const _Tp& __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1184 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s, size_type __n); |
| 1185 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& append(const value_type* __s); |
| 1186 | _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] | 1187 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1188 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1189 | void __append_default_init(size_type __n); |
| 1190 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1191 | template<class _InputIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1192 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1193 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1194 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1195 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1196 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1197 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1198 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1199 | append(_InputIterator __first, _InputIterator __last) { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1200 | const basic_string __temp(__first, __last, __alloc()); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1201 | append(__temp.data(), __temp.size()); |
| 1202 | return *this; |
| 1203 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1204 | template<class _ForwardIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1205 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1206 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1207 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1208 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1209 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1210 | > |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1211 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1212 | append(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1213 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1214 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1215 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1216 | 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] | 1217 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1218 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1219 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void push_back(value_type __c); |
| 1220 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void pop_back(); |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1221 | |
| 1222 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference front() _NOEXCEPT { |
| 1223 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
| 1224 | return *__get_pointer(); |
| 1225 | } |
| 1226 | |
| 1227 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference front() const _NOEXCEPT { |
| 1228 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
| 1229 | return *data(); |
| 1230 | } |
| 1231 | |
| 1232 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 reference back() _NOEXCEPT { |
| 1233 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
| 1234 | return *(__get_pointer() + size() - 1); |
| 1235 | } |
| 1236 | |
| 1237 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 const_reference back() const _NOEXCEPT { |
| 1238 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
| 1239 | return *(data() + size() - 1); |
| 1240 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1241 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1242 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1243 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1244 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1245 | < |
| 1246 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1247 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1248 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1249 | 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] | 1250 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 95d5e9a | 2016-03-09 18:08:29 +0000 | [diff] [blame] | 1251 | basic_string& assign(const basic_string& __str) { return *this = __str; } |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1252 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1253 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1254 | basic_string& assign(basic_string&& __str) |
Marshall Clow | 5aa9e94 | 2015-10-05 16:17:34 +0000 | [diff] [blame] | 1255 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1256 | {*this = std::move(__str); return *this;} |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1257 | #endif |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1258 | _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] | 1259 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1260 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1261 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1262 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1263 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1264 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1265 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1266 | > |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1267 | assign(const _Tp & __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1268 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s, size_type __n); |
| 1269 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& assign(const value_type* __s); |
| 1270 | _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] | 1271 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1272 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1273 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1274 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1275 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1276 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1277 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | assign(_InputIterator __first, _InputIterator __last); |
| 1279 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1280 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1281 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1282 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1283 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1284 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1285 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1286 | assign(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1287 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1288 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | 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] | 1290 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1291 | |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1292 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& |
| 1293 | insert(size_type __pos1, const basic_string& __str) { |
| 1294 | return insert(__pos1, __str.data(), __str.size()); |
| 1295 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1296 | |
| 1297 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1298 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1299 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1300 | < |
| 1301 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1302 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1303 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1304 | insert(size_type __pos1, const _Tp& __t) |
| 1305 | { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); } |
| 1306 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1307 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1308 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1309 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1310 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1311 | __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] | 1312 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1313 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1314 | 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] | 1315 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1316 | 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] | 1317 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s, size_type __n); |
| 1318 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, const value_type* __s); |
| 1319 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& insert(size_type __pos, size_type __n, value_type __c); |
| 1320 | _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator insert(const_iterator __pos, value_type __c); |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1321 | |
| 1322 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 iterator |
| 1323 | insert(const_iterator __pos, size_type __n, value_type __c) { |
| 1324 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 1325 | "string::insert(iterator, n, value) called with an iterator not referring to this string"); |
| 1326 | difference_type __p = __pos - begin(); |
| 1327 | insert(static_cast<size_type>(__p), __n, __c); |
| 1328 | return begin() + __p; |
| 1329 | } |
| 1330 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1331 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1332 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1333 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1335 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1336 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1337 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); |
| 1339 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1340 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1341 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1342 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1343 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1344 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1345 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1346 | insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1347 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1348 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1349 | iterator insert(const_iterator __pos, initializer_list<value_type> __il) |
| 1350 | {return insert(__pos, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1351 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1352 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1353 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& erase(size_type __pos = 0, size_type __n = npos); |
| 1354 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1355 | iterator erase(const_iterator __pos); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1356 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | iterator erase(const_iterator __first, const_iterator __last); |
| 1358 | |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1359 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& |
| 1360 | replace(size_type __pos1, size_type __n1, const basic_string& __str) { |
| 1361 | return replace(__pos1, __n1, __str.data(), __str.size()); |
| 1362 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1363 | |
| 1364 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1365 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1366 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1367 | < |
| 1368 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1369 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1370 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1371 | 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] | 1372 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1373 | 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] | 1374 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1375 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1376 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1377 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1378 | __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] | 1379 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1380 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1381 | 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] | 1382 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1383 | 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] | 1384 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); |
| 1385 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1386 | |
| 1387 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& |
| 1388 | replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) { |
| 1389 | return replace( |
| 1390 | static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __str.data(), __str.size()); |
| 1391 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1392 | |
| 1393 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1394 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1395 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1396 | < |
| 1397 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1398 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1399 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1400 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); } |
| 1401 | |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1402 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& |
| 1403 | replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) { |
| 1404 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); |
| 1405 | } |
| 1406 | |
| 1407 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& |
| 1408 | replace(const_iterator __i1, const_iterator __i2, const value_type* __s) { |
| 1409 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); |
| 1410 | } |
| 1411 | |
| 1412 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& |
| 1413 | replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) { |
| 1414 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); |
| 1415 | } |
| 1416 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1417 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1418 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1419 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1420 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1421 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1423 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1424 | replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1425 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1426 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1427 | 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] | 1428 | {return replace(__i1, __i2, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1429 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1430 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1431 | _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1432 | |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1433 | #if _LIBCPP_STD_VER <= 20 |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1434 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1435 | basic_string substr(size_type __pos = 0, size_type __n = npos) const { |
Nikolas Klauser | 267afcf | 2022-11-29 19:39:29 +0100 | [diff] [blame] | 1436 | return basic_string(*this, __pos, __n); |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1437 | } |
| 1438 | #else |
| 1439 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1440 | basic_string substr(size_type __pos = 0, size_type __n = npos) const& { |
Nikolas Klauser | 267afcf | 2022-11-29 19:39:29 +0100 | [diff] [blame] | 1441 | return basic_string(*this, __pos, __n); |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 1445 | basic_string substr(size_type __pos = 0, size_type __n = npos) && { |
Nikolas Klauser | 267afcf | 2022-11-29 19:39:29 +0100 | [diff] [blame] | 1446 | return basic_string(std::move(*this), __pos, __n); |
Nikolas Klauser | 1b531cf | 2022-08-09 13:17:30 +0200 | [diff] [blame] | 1447 | } |
| 1448 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1449 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1450 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1451 | void swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1452 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1453 | _NOEXCEPT; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1454 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1455 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1456 | __is_nothrow_swappable<allocator_type>::value); |
| 1457 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1458 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1459 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1460 | const value_type* c_str() const _NOEXCEPT {return data();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1461 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1462 | const value_type* data() const _NOEXCEPT {return std::__to_address(__get_pointer());} |
Eric Fiselier | 4ee2a89 | 2017-11-20 20:23:27 +0000 | [diff] [blame] | 1463 | #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1464 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1465 | value_type* data() _NOEXCEPT {return std::__to_address(__get_pointer());} |
Marshall Clow | d3c2239 | 2016-03-08 15:44:30 +0000 | [diff] [blame] | 1466 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1467 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1468 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1469 | allocator_type get_allocator() const _NOEXCEPT {return __alloc();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1470 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1471 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1472 | 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] | 1473 | |
| 1474 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1475 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1476 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1477 | < |
| 1478 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1479 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1480 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1481 | find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1482 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1483 | 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] | 1484 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1485 | 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] | 1486 | _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] | 1487 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1488 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1489 | 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] | 1490 | |
| 1491 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1492 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1493 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1494 | < |
| 1495 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1496 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1497 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1498 | rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1499 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1500 | 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] | 1501 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1502 | 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] | 1503 | _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] | 1504 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1505 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1506 | size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1507 | |
| 1508 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1509 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1510 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1511 | < |
| 1512 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1513 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1514 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1515 | find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1516 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1517 | 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] | 1518 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1519 | 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] | 1520 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1521 | 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] | 1522 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1523 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1524 | 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] | 1525 | |
| 1526 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1527 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1528 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1529 | < |
| 1530 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1531 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1532 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1533 | find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1534 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1535 | 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] | 1536 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1537 | 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] | 1538 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1539 | 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] | 1540 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1541 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1542 | 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] | 1543 | |
| 1544 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1545 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1546 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1547 | < |
| 1548 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1549 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1550 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1551 | 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] | 1552 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1553 | 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] | 1554 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1555 | 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] | 1556 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1557 | size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
| 1558 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1559 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1560 | 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] | 1561 | |
| 1562 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1563 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1564 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1565 | < |
| 1566 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1567 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1568 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1569 | 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] | 1570 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1571 | 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] | 1572 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1573 | 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] | 1574 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1575 | size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
| 1576 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1577 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1578 | int compare(const basic_string& __str) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1579 | |
| 1580 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1581 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1582 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1583 | < |
| 1584 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1585 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1586 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1587 | compare(const _Tp &__t) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1588 | |
| 1589 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1590 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1591 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1592 | < |
| 1593 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1594 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1595 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1596 | compare(size_type __pos1, size_type __n1, const _Tp& __t) const; |
| 1597 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1598 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1599 | 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] | 1600 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1601 | int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, |
| 1602 | size_type __n2 = npos) const; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1603 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1604 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1605 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1606 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1607 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1608 | __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] | 1609 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1610 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1611 | 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] | 1612 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(const value_type* __s) const _NOEXCEPT; |
| 1613 | _LIBCPP_CONSTEXPR_SINCE_CXX20 int compare(size_type __pos1, size_type __n1, const value_type* __s) const; |
| 1614 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1615 | 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] | 1616 | |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1617 | #if _LIBCPP_STD_VER > 17 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1618 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1619 | bool starts_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1620 | { return __self_view(data(), size()).starts_with(__sv); } |
| 1621 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1622 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1623 | bool starts_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1624 | { return !empty() && _Traits::eq(front(), __c); } |
| 1625 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1626 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1627 | bool starts_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1628 | { return starts_with(__self_view(__s)); } |
| 1629 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1630 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1631 | bool ends_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1632 | { return __self_view(data(), size()).ends_with( __sv); } |
| 1633 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1634 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1635 | bool ends_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1636 | { return !empty() && _Traits::eq(back(), __c); } |
| 1637 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1638 | constexpr _LIBCPP_HIDE_FROM_ABI |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1639 | bool ends_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1640 | { return ends_with(__self_view(__s)); } |
| 1641 | #endif |
| 1642 | |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1643 | #if _LIBCPP_STD_VER > 20 |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1644 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1645 | bool contains(__self_view __sv) const noexcept |
| 1646 | { return __self_view(data(), size()).contains(__sv); } |
| 1647 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1648 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1649 | bool contains(value_type __c) const noexcept |
| 1650 | { return __self_view(data(), size()).contains(__c); } |
| 1651 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1652 | constexpr _LIBCPP_HIDE_FROM_ABI |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1653 | bool contains(const value_type* __s) const |
| 1654 | { return __self_view(data(), size()).contains(__s); } |
| 1655 | #endif |
| 1656 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1657 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 bool __invariants() const; |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1658 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1659 | _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] | 1660 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1661 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1662 | |
| 1663 | bool __dereferenceable(const const_iterator* __i) const; |
| 1664 | bool __decrementable(const const_iterator* __i) const; |
| 1665 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1666 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1667 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 1668 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1669 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1670 | private: |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1671 | template<class _Alloc> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1672 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1673 | bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs, |
| 1674 | const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT; |
| 1675 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1676 | _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] | 1677 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1678 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1679 | bool __is_long() const _NOEXCEPT { |
| 1680 | if (__libcpp_is_constant_evaluated()) |
| 1681 | return true; |
| 1682 | return __r_.first().__s.__is_long_; |
| 1683 | } |
| 1684 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1685 | 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] | 1686 | #if _LIBCPP_STD_VER > 17 |
| 1687 | if (__libcpp_is_constant_evaluated()) { |
| 1688 | for (size_type __i = 0; __i != __n; ++__i) |
| 1689 | std::construct_at(std::addressof(__begin[__i])); |
| 1690 | } |
| 1691 | #else |
| 1692 | (void)__begin; |
| 1693 | (void)__n; |
| 1694 | #endif // _LIBCPP_STD_VER > 17 |
| 1695 | } |
| 1696 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1697 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __default_init() { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 1698 | __r_.first() = __rep(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1699 | if (__libcpp_is_constant_evaluated()) { |
| 1700 | size_type __sz = __recommend(0) + 1; |
| 1701 | pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); |
| 1702 | __begin_lifetime(__ptr, __sz); |
| 1703 | __set_long_pointer(__ptr); |
| 1704 | __set_long_cap(__sz); |
| 1705 | __set_long_size(0); |
| 1706 | } |
| 1707 | } |
| 1708 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1709 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __deallocate_constexpr() { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1710 | if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr) |
| 1711 | __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap()); |
| 1712 | } |
| 1713 | |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1714 | _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { |
| 1715 | // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly |
| 1716 | return !__libcpp_is_constant_evaluated() && (__sz < __min_cap); |
| 1717 | } |
| 1718 | |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1719 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1720 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1721 | iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) { |
| 1722 | size_type __sz = size(); |
| 1723 | size_type __cap = capacity(); |
| 1724 | value_type* __p; |
| 1725 | if (__cap - __sz >= __n) |
| 1726 | { |
| 1727 | __p = std::__to_address(__get_pointer()); |
| 1728 | size_type __n_move = __sz - __ip; |
| 1729 | if (__n_move != 0) |
| 1730 | traits_type::move(__p + __ip + __n, __p + __ip, __n_move); |
| 1731 | } |
| 1732 | else |
| 1733 | { |
| 1734 | __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); |
| 1735 | __p = std::__to_address(__get_long_pointer()); |
| 1736 | } |
| 1737 | __sz += __n; |
| 1738 | __set_size(__sz); |
| 1739 | traits_type::assign(__p[__sz], value_type()); |
| 1740 | for (__p += __ip; __first != __last; ++__p, ++__first) |
| 1741 | traits_type::assign(*__p, *__first); |
| 1742 | |
| 1743 | return begin() + __ip; |
| 1744 | } |
| 1745 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1746 | _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] | 1747 | _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] | 1748 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1749 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1750 | void __set_short_size(size_type __s) _NOEXCEPT { |
| 1751 | _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity"); |
| 1752 | __r_.first().__s.__size_ = __s; |
| 1753 | __r_.first().__s.__is_long_ = false; |
| 1754 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1755 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1756 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1757 | size_type __get_short_size() const _NOEXCEPT { |
| 1758 | _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); |
| 1759 | return __r_.first().__s.__size_; |
| 1760 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1761 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1762 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1763 | void __set_long_size(size_type __s) _NOEXCEPT |
| 1764 | {__r_.first().__l.__size_ = __s;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1765 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1766 | size_type __get_long_size() const _NOEXCEPT |
| 1767 | {return __r_.first().__l.__size_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1768 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1769 | void __set_size(size_type __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1770 | {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} |
| 1771 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1772 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1773 | void __set_long_cap(size_type __s) _NOEXCEPT { |
| 1774 | __r_.first().__l.__cap_ = __s / __endian_factor; |
| 1775 | __r_.first().__l.__is_long_ = true; |
| 1776 | } |
| 1777 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1778 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1779 | size_type __get_long_cap() const _NOEXCEPT { |
| 1780 | return __r_.first().__l.__cap_ * __endian_factor; |
| 1781 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1783 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1784 | void __set_long_pointer(pointer __p) _NOEXCEPT |
| 1785 | {__r_.first().__l.__data_ = __p;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1786 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1787 | pointer __get_long_pointer() _NOEXCEPT |
| 1788 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1789 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1790 | const_pointer __get_long_pointer() const _NOEXCEPT |
| 1791 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1792 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1793 | pointer __get_short_pointer() _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1794 | {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1795 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1796 | const_pointer __get_short_pointer() const _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1797 | {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1798 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1799 | pointer __get_pointer() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1800 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1801 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1802 | const_pointer __get_pointer() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1803 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
| 1804 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1805 | template <size_type __a> static |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1806 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 1807 | size_type __align_it(size_type __s) _NOEXCEPT |
Eric Fiselier | 8599fcc | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 1808 | {return (__s + (__a-1)) & ~(__a-1);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1809 | enum {__alignment = 16}; |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1810 | static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1811 | size_type __recommend(size_type __s) _NOEXCEPT |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1812 | { |
| 1813 | if (__s < __min_cap) { |
| 1814 | if (__libcpp_is_constant_evaluated()) |
| 1815 | return static_cast<size_type>(__min_cap); |
| 1816 | else |
| 1817 | return static_cast<size_type>(__min_cap) - 1; |
| 1818 | } |
Marshall Clow | 8058452 | 2018-02-07 21:30:17 +0000 | [diff] [blame] | 1819 | size_type __guess = __align_it<sizeof(value_type) < __alignment ? |
| 1820 | __alignment/sizeof(value_type) : 1 > (__s+1) - 1; |
| 1821 | if (__guess == __min_cap) ++__guess; |
| 1822 | return __guess; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1823 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1824 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1825 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1826 | void __init(const value_type* __s, size_type __sz, size_type __reserve); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1827 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1828 | void __init(const value_type* __s, size_type __sz); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1829 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1830 | void __init(size_type __n, value_type __c); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1831 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 1832 | // Slow path for the (inlined) copy constructor for 'long' strings. |
| 1833 | // Always externally instantiated and not inlined. |
| 1834 | // Requires that __s is zero terminated. |
| 1835 | // The main reason for this function to exist is because for unstable, we |
| 1836 | // want to allow inlining of the copy constructor. However, we don't want |
| 1837 | // to call the __init() functions as those are marked as inline which may |
| 1838 | // result in over-aggressive inlining by the compiler, where our aim is |
| 1839 | // to only inline the fast path code directly in the ctor. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1840 | _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] | 1841 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1842 | template <class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1843 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1844 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1845 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1846 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 1847 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1848 | __init(_InputIterator __first, _InputIterator __last); |
| 1849 | |
| 1850 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1851 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1852 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1853 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1854 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 1855 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1856 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 1857 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1858 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | 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] | 1860 | 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] | 1861 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 1863 | size_type __n_copy, size_type __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1864 | size_type __n_add, const value_type* __p_new_stuff); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 1866 | // __assign_no_alias is invoked for assignment operations where we |
| 1867 | // have proof that the input does not alias the current instance. |
| 1868 | // For example, operator=(basic_string) performs a 'self' check. |
| 1869 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1870 | _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] | 1871 | |
Nikolas Klauser | 0232707 | 2022-10-29 21:04:35 +0200 | [diff] [blame] | 1872 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __erase_to_end(size_type __pos) { |
| 1873 | __null_terminate_at(std::__to_address(__get_pointer()), __pos); |
| 1874 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1875 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 1876 | // __erase_external_with_move is invoked for erase() invocations where |
| 1877 | // `n ~= npos`, likely requiring memory moves on the string data. |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1878 | _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] | 1879 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1880 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1881 | void __copy_assign_alloc(const basic_string& __str) |
| 1882 | {__copy_assign_alloc(__str, integral_constant<bool, |
| 1883 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 1884 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1885 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1886 | void __copy_assign_alloc(const basic_string& __str, true_type) |
| 1887 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1888 | if (__alloc() == __str.__alloc()) |
| 1889 | __alloc() = __str.__alloc(); |
| 1890 | else |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1891 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1892 | if (!__str.__is_long()) |
| 1893 | { |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 1894 | __clear_and_shrink(); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1895 | __alloc() = __str.__alloc(); |
| 1896 | } |
| 1897 | else |
| 1898 | { |
| 1899 | allocator_type __a = __str.__alloc(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1900 | auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap()); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1901 | __begin_lifetime(__allocation.ptr, __allocation.count); |
Nikolas Klauser | 1821ec3 | 2022-10-01 15:37:24 +0200 | [diff] [blame] | 1902 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1903 | __alloc() = std::move(__a); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1904 | __set_long_pointer(__allocation.ptr); |
| 1905 | __set_long_cap(__allocation.count); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1906 | __set_long_size(__str.size()); |
| 1907 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1908 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1909 | } |
| 1910 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1911 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1912 | void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1913 | {} |
| 1914 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1915 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1916 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1917 | void __move_assign(basic_string& __str, false_type) |
| 1918 | _NOEXCEPT_(__alloc_traits::is_always_equal::value); |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1919 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1920 | void __move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1921 | #if _LIBCPP_STD_VER > 14 |
| 1922 | _NOEXCEPT; |
| 1923 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1924 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1925 | #endif |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1926 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1927 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1928 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1929 | void |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1930 | __move_assign_alloc(basic_string& __str) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1931 | _NOEXCEPT_( |
| 1932 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 1933 | is_nothrow_move_assignable<allocator_type>::value) |
| 1934 | {__move_assign_alloc(__str, integral_constant<bool, |
| 1935 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 1936 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1937 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1938 | void __move_assign_alloc(basic_string& __c, true_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1939 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
| 1940 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1941 | __alloc() = std::move(__c.__alloc()); |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1942 | } |
| 1943 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1944 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1945 | void __move_assign_alloc(basic_string&, false_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1946 | _NOEXCEPT |
| 1947 | {} |
| 1948 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1949 | _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string& __assign_external(const value_type* __s); |
| 1950 | _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] | 1951 | |
| 1952 | // Assigns the value in __s, guaranteed to be __n < __min_cap in length. |
| 1953 | inline basic_string& __assign_short(const value_type* __s, size_type __n) { |
| 1954 | pointer __p = __is_long() |
| 1955 | ? (__set_long_size(__n), __get_long_pointer()) |
| 1956 | : (__set_short_size(__n), __get_short_pointer()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1957 | traits_type::move(std::__to_address(__p), __s, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 1958 | traits_type::assign(__p[__n], value_type()); |
| 1959 | return *this; |
| 1960 | } |
| 1961 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1962 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1963 | basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 1964 | __set_size(__newsz); |
| 1965 | __invalidate_iterators_past(__newsz); |
| 1966 | traits_type::assign(__p[__newsz], value_type()); |
| 1967 | return *this; |
| 1968 | } |
| 1969 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1970 | _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] | 1971 | |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1972 | template<class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1973 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1974 | bool __addr_in_range(_Tp&& __t) const { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 1975 | // assume that the ranges overlap, because we can't check during constant evaluation |
| 1976 | if (__libcpp_is_constant_evaluated()) |
| 1977 | return true; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1978 | const volatile void *__p = std::addressof(__t); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1979 | return data() <= __p && __p <= data() + size(); |
| 1980 | } |
| 1981 | |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1982 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1983 | void __throw_length_error() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1984 | std::__throw_length_error("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1988 | void __throw_out_of_range() const { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 1989 | std::__throw_out_of_range("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1990 | } |
| 1991 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 1992 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const basic_string&); |
| 1993 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const value_type*, const basic_string&); |
| 1994 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(value_type, const basic_string&); |
| 1995 | friend _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string operator+<>(const basic_string&, const value_type*); |
| 1996 | 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] | 1997 | }; |
| 1998 | |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1999 | // These declarations must appear before any functions are implicitly used |
| 2000 | // so that they have the correct visibility specifier. |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 2001 | #define _LIBCPP_DECLARE(...) extern template __VA_ARGS__; |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 2002 | #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 2003 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2004 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 2005 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2006 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 2007 | #else |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 2008 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, char) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2009 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 2010 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_DECLARE, wchar_t) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2011 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 2012 | #endif |
Louis Dionne | dc496ec | 2021-06-08 17:25:08 -0400 | [diff] [blame] | 2013 | #undef _LIBCPP_DECLARE |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 2014 | |
| 2015 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 2016 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 2017 | template<class _InputIterator, |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 2018 | class _CharT = __iter_value_type<_InputIterator>, |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 2019 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 2020 | class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
| 2021 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 2022 | > |
| 2023 | basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 2024 | -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2025 | |
| 2026 | template<class _CharT, |
| 2027 | class _Traits, |
| 2028 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 2029 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2030 | > |
| 2031 | explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) |
| 2032 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 2033 | |
| 2034 | template<class _CharT, |
| 2035 | class _Traits, |
| 2036 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 2037 | class = enable_if_t<__is_allocator<_Allocator>::value>, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2038 | class _Sz = typename allocator_traits<_Allocator>::size_type |
| 2039 | > |
| 2040 | basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) |
| 2041 | -> basic_string<_CharT, _Traits, _Allocator>; |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 2042 | #endif |
| 2043 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2044 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2045 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2046 | void |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 2047 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2048 | { |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 2049 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 2050 | if (!__libcpp_is_constant_evaluated()) { |
| 2051 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 2052 | if (__c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2053 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 2054 | const_pointer __new_last = __get_pointer() + __pos; |
| 2055 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2056 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 2057 | --__p; |
| 2058 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 2059 | if (__i->base() > __new_last) |
| 2060 | { |
| 2061 | (*__p)->__c_ = nullptr; |
| 2062 | if (--__c->end_ != __p) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2063 | std::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 2064 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2065 | } |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 2066 | __get_db()->unlock(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2067 | } |
| 2068 | } |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 2069 | #else |
| 2070 | (void)__pos; |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 2071 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2075 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 2076 | void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, |
| 2077 | size_type __sz, |
| 2078 | size_type __reserve) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2079 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2080 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2081 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2082 | if (__reserve > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2083 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2084 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2085 | if (__fits_in_sso(__reserve)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2086 | { |
| 2087 | __set_short_size(__sz); |
| 2088 | __p = __get_short_pointer(); |
| 2089 | } |
| 2090 | else |
| 2091 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2092 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1); |
| 2093 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2094 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2095 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2096 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2097 | __set_long_size(__sz); |
| 2098 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2099 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2100 | traits_type::assign(__p[__sz], value_type()); |
| 2101 | } |
| 2102 | |
| 2103 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2104 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2105 | void |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2106 | 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] | 2107 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2108 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2109 | __r_.first() = __rep(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2110 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2111 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2112 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2113 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2114 | { |
| 2115 | __set_short_size(__sz); |
| 2116 | __p = __get_short_pointer(); |
| 2117 | } |
| 2118 | else |
| 2119 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2120 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2121 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2122 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2123 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2124 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2125 | __set_long_size(__sz); |
| 2126 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2127 | traits_type::copy(std::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2128 | traits_type::assign(__p[__sz], value_type()); |
| 2129 | } |
| 2130 | |
| 2131 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2132 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2133 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2134 | 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] | 2135 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2136 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2137 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2138 | __init(__s, traits_type::length(__s)); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2139 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2143 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2144 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2145 | : __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] | 2146 | { |
| 2147 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2148 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2149 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2150 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2151 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2152 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2156 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2157 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
| 2158 | const basic_string& __str, const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2159 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2160 | { |
| 2161 | if (!__str.__is_long()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2162 | __r_.first() = __str.__r_.first(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2163 | else |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2164 | __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2165 | __str.__get_long_size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2166 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2169 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2170 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2171 | void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( |
| 2172 | const value_type* __s, size_type __sz) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2173 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2174 | __r_.first() = __rep(); |
| 2175 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2176 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2177 | if (__fits_in_sso(__sz)) { |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2178 | __p = __get_short_pointer(); |
| 2179 | __set_short_size(__sz); |
| 2180 | } else { |
| 2181 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2182 | __throw_length_error(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2183 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2184 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2185 | __begin_lifetime(__p, __allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2186 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2187 | __set_long_cap(__allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2188 | __set_long_size(__sz); |
| 2189 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2190 | traits_type::copy(std::__to_address(__p), __s, __sz + 1); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2191 | } |
| 2192 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2193 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2194 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2195 | void |
| 2196 | basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) |
| 2197 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2198 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2199 | __r_.first() = __rep(); |
| 2200 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2201 | if (__n > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2202 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2203 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2204 | if (__fits_in_sso(__n)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2205 | { |
| 2206 | __set_short_size(__n); |
| 2207 | __p = __get_short_pointer(); |
| 2208 | } |
| 2209 | else |
| 2210 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2211 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1); |
| 2212 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2213 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2214 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2215 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2216 | __set_long_size(__n); |
| 2217 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2218 | traits_type::assign(std::__to_address(__p), __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2219 | traits_type::assign(__p[__n], value_type()); |
| 2220 | } |
| 2221 | |
| 2222 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2223 | template <class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2224 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2225 | 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] | 2226 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2227 | { |
| 2228 | __init(__n, __c); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2229 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2232 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2233 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2234 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, |
| 2235 | size_type __pos, size_type __n, |
| 2236 | const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2237 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2238 | { |
| 2239 | size_type __str_sz = __str.size(); |
| 2240 | if (__pos > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2241 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2242 | __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); |
| 2243 | std::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2247 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2248 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2249 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2250 | 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] | 2251 | : __r_(__default_init_tag(), __a) |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2252 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2253 | __self_view __sv0 = __t; |
| 2254 | __self_view __sv = __sv0.substr(__pos, __n); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2255 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2256 | std::__debug_db_insert_c(this); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2260 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2261 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2262 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2263 | : __r_(__default_init_tag(), __default_init_tag()) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2264 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2265 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2266 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2267 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
| 2270 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2271 | template <class _Tp, class> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2272 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2273 | 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] | 2274 | : __r_(__default_init_tag(), __a) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2275 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2276 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2277 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2278 | std::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | template <class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2283 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2284 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2285 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2286 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 2287 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2288 | basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) |
| 2289 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2290 | __default_init(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2291 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2292 | try |
| 2293 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2294 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2295 | for (; __first != __last; ++__first) |
| 2296 | push_back(*__first); |
| 2297 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2298 | } |
| 2299 | catch (...) |
| 2300 | { |
| 2301 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2302 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2303 | throw; |
| 2304 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2305 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | template <class _CharT, class _Traits, class _Allocator> |
| 2309 | template <class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2310 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2311 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2312 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2313 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 2314 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2315 | basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 2316 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2317 | if (__libcpp_is_constant_evaluated()) |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2318 | __r_.first() = __rep(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2319 | size_type __sz = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2320 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2321 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2322 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2323 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2324 | { |
| 2325 | __set_short_size(__sz); |
| 2326 | __p = __get_short_pointer(); |
| 2327 | } |
| 2328 | else |
| 2329 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2330 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2331 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2332 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2333 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2334 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2335 | __set_long_size(__sz); |
| 2336 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2337 | |
| 2338 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2339 | try |
| 2340 | { |
| 2341 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | a09a3b4 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 2342 | for (; __first != __last; ++__first, (void) ++__p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | traits_type::assign(*__p, *__first); |
| 2344 | traits_type::assign(*__p, value_type()); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2345 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2346 | } |
| 2347 | catch (...) |
| 2348 | { |
| 2349 | if (__is_long()) |
| 2350 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
| 2351 | throw; |
| 2352 | } |
| 2353 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2357 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2358 | basic_string<_CharT, _Traits, _Allocator>::~basic_string() |
| 2359 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 2360 | std::__debug_db_erase_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2361 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2362 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2366 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2367 | void |
| 2368 | basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace |
| 2369 | (size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2370 | 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] | 2371 | { |
| 2372 | size_type __ms = max_size(); |
| 2373 | if (__delta_cap > __ms - __old_cap - 1) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2374 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2375 | pointer __old_p = __get_pointer(); |
| 2376 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2377 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2378 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2379 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2380 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2381 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2382 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2383 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2384 | traits_type::copy(std::__to_address(__p), |
| 2385 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2386 | if (__n_add != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2387 | 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] | 2388 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2389 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2390 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2391 | std::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2392 | if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2393 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2394 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2395 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2396 | __old_sz = __n_copy + __n_add + __sec_cp_sz; |
| 2397 | __set_long_size(__old_sz); |
| 2398 | traits_type::assign(__p[__old_sz], value_type()); |
| 2399 | } |
| 2400 | |
| 2401 | template <class _CharT, class _Traits, class _Allocator> |
| 2402 | void |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2403 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2404 | basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 2405 | size_type __n_copy, size_type __n_del, size_type __n_add) |
| 2406 | { |
| 2407 | size_type __ms = max_size(); |
Marshall Clow | 2267c5d | 2013-11-06 14:24:38 +0000 | [diff] [blame] | 2408 | if (__delta_cap > __ms - __old_cap) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2409 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | pointer __old_p = __get_pointer(); |
| 2411 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2412 | __recommend(std::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2413 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2414 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2415 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2416 | __begin_lifetime(__p, __allocation.count); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 2417 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2418 | if (__n_copy != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2419 | traits_type::copy(std::__to_address(__p), |
| 2420 | std::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2421 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2422 | if (__sec_cp_sz != 0) |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2423 | traits_type::copy(std::__to_address(__p) + __n_copy + __n_add, |
| 2424 | std::__to_address(__old_p) + __n_copy + __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2425 | __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2426 | if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap) |
| 2427 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2428 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2429 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | // assign |
| 2433 | |
| 2434 | template <class _CharT, class _Traits, class _Allocator> |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2435 | template <bool __is_short> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2436 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2437 | basic_string<_CharT, _Traits, _Allocator>& |
| 2438 | basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias( |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2439 | const value_type* __s, size_type __n) { |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2440 | 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] | 2441 | if (__n < __cap) { |
| 2442 | pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer(); |
| 2443 | __is_short ? __set_short_size(__n) : __set_long_size(__n); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2444 | traits_type::copy(std::__to_address(__p), __s, __n); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2445 | traits_type::assign(__p[__n], value_type()); |
| 2446 | __invalidate_iterators_past(__n); |
| 2447 | } else { |
| 2448 | size_type __sz = __is_short ? __get_short_size() : __get_long_size(); |
| 2449 | __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s); |
| 2450 | } |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2451 | return *this; |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2455 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2456 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2457 | basic_string<_CharT, _Traits, _Allocator>::__assign_external( |
| 2458 | const value_type* __s, size_type __n) { |
| 2459 | size_type __cap = capacity(); |
| 2460 | if (__cap >= __n) { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2461 | value_type* __p = std::__to_address(__get_pointer()); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2462 | traits_type::move(__p, __s, __n); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2463 | return __null_terminate_at(__p, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2464 | } else { |
| 2465 | size_type __sz = size(); |
| 2466 | __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2467 | return *this; |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2468 | } |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [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 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2473 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2474 | 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] | 2475 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2476 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2477 | return (__builtin_constant_p(__n) && __fits_in_sso(__n)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2478 | ? __assign_short(__s, __n) |
| 2479 | : __assign_external(__s, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2483 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2484 | basic_string<_CharT, _Traits, _Allocator>& |
| 2485 | basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) |
| 2486 | { |
| 2487 | size_type __cap = capacity(); |
| 2488 | if (__cap < __n) |
| 2489 | { |
| 2490 | size_type __sz = size(); |
| 2491 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2492 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2493 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2494 | traits_type::assign(__p, __n, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2495 | return __null_terminate_at(__p, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2499 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2500 | basic_string<_CharT, _Traits, _Allocator>& |
| 2501 | basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) |
| 2502 | { |
| 2503 | pointer __p; |
| 2504 | if (__is_long()) |
| 2505 | { |
| 2506 | __p = __get_long_pointer(); |
| 2507 | __set_long_size(1); |
| 2508 | } |
| 2509 | else |
| 2510 | { |
| 2511 | __p = __get_short_pointer(); |
| 2512 | __set_short_size(1); |
| 2513 | } |
| 2514 | traits_type::assign(*__p, __c); |
| 2515 | traits_type::assign(*++__p, value_type()); |
| 2516 | __invalidate_iterators_past(1); |
| 2517 | return *this; |
| 2518 | } |
| 2519 | |
| 2520 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2521 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2522 | basic_string<_CharT, _Traits, _Allocator>& |
| 2523 | basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) |
| 2524 | { |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2525 | if (this != &__str) { |
| 2526 | __copy_assign_alloc(__str); |
| 2527 | if (!__is_long()) { |
| 2528 | if (!__str.__is_long()) { |
Nikolas Klauser | 8577eec | 2022-08-30 17:43:14 +0200 | [diff] [blame] | 2529 | __r_.first() = __str.__r_.first(); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2530 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2531 | return __assign_no_alias<true>(__str.data(), __str.size()); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2532 | } |
| 2533 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2534 | return __assign_no_alias<false>(__str.data(), __str.size()); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2535 | } |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2536 | } |
| 2537 | return *this; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 2540 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2541 | |
| 2542 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2543 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2544 | void |
| 2545 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2546 | _NOEXCEPT_(__alloc_traits::is_always_equal::value) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2547 | { |
| 2548 | if (__alloc() != __str.__alloc()) |
| 2549 | assign(__str); |
| 2550 | else |
| 2551 | __move_assign(__str, true_type()); |
| 2552 | } |
| 2553 | |
| 2554 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2555 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2556 | void |
| 2557 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2558 | #if _LIBCPP_STD_VER > 14 |
| 2559 | _NOEXCEPT |
| 2560 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2561 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2562 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2563 | { |
marshall | 2ed4162 | 2019-11-27 07:13:00 -0800 | [diff] [blame] | 2564 | if (__is_long()) { |
| 2565 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), |
| 2566 | __get_long_cap()); |
| 2567 | #if _LIBCPP_STD_VER <= 14 |
| 2568 | if (!is_nothrow_move_assignable<allocator_type>::value) { |
| 2569 | __set_short_size(0); |
| 2570 | traits_type::assign(__get_short_pointer()[0], value_type()); |
| 2571 | } |
| 2572 | #endif |
| 2573 | } |
| 2574 | __move_assign_alloc(__str); |
| 2575 | __r_.first() = __str.__r_.first(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2576 | if (__libcpp_is_constant_evaluated()) { |
| 2577 | __str.__default_init(); |
| 2578 | } else { |
| 2579 | __str.__set_short_size(0); |
| 2580 | traits_type::assign(__str.__get_short_pointer()[0], value_type()); |
| 2581 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2584 | #endif |
| 2585 | |
| 2586 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2587 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2588 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2589 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2590 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2591 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2592 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2593 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2594 | basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2595 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2596 | const basic_string __temp(__first, __last, __alloc()); |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2597 | assign(__temp.data(), __temp.size()); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2598 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | template <class _CharT, class _Traits, class _Allocator> |
| 2602 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2603 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2604 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2605 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2606 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2607 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2608 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2609 | basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2610 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2611 | size_type __cap = capacity(); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2612 | size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ? |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2613 | static_cast<size_type>(std::distance(__first, __last)) : 0; |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2614 | |
| 2615 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2616 | (__cap >= __n || !__addr_in_range(*__first))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2617 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2618 | if (__cap < __n) |
| 2619 | { |
| 2620 | size_type __sz = size(); |
| 2621 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2622 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2623 | pointer __p = __get_pointer(); |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2624 | for (; __first != __last; ++__p, (void) ++__first) |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2625 | traits_type::assign(*__p, *__first); |
| 2626 | traits_type::assign(*__p, value_type()); |
| 2627 | __set_size(__n); |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 2628 | __invalidate_iterators_past(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2629 | } |
| 2630 | else |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2631 | { |
| 2632 | const basic_string __temp(__first, __last, __alloc()); |
| 2633 | assign(__temp.data(), __temp.size()); |
| 2634 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2635 | return *this; |
| 2636 | } |
| 2637 | |
| 2638 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2639 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2640 | basic_string<_CharT, _Traits, _Allocator>& |
| 2641 | basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) |
| 2642 | { |
| 2643 | size_type __sz = __str.size(); |
| 2644 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2645 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2646 | return assign(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2650 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2651 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2652 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2653 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2654 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 2655 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 2656 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2657 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2658 | 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] | 2659 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2660 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2661 | size_type __sz = __sv.size(); |
| 2662 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2663 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2664 | return assign(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | |
| 2668 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2669 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2670 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2671 | basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) { |
| 2672 | return __assign_external(__s, traits_type::length(__s)); |
| 2673 | } |
| 2674 | |
| 2675 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2676 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2677 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2678 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2679 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2680 | _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); |
Louis Dionne | 3e0c433 | 2021-08-31 10:49:06 -0400 | [diff] [blame] | 2681 | return __builtin_constant_p(*__s) |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2682 | ? (__fits_in_sso(traits_type::length(__s)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2683 | ? __assign_short(__s, traits_type::length(__s)) |
| 2684 | : __assign_external(__s, traits_type::length(__s))) |
| 2685 | : __assign_external(__s); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2686 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2687 | // append |
| 2688 | |
| 2689 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2690 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2691 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2692 | 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] | 2693 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2694 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2695 | size_type __cap = capacity(); |
| 2696 | size_type __sz = size(); |
| 2697 | if (__cap - __sz >= __n) |
| 2698 | { |
| 2699 | if (__n) |
| 2700 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2701 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2702 | traits_type::copy(__p + __sz, __s, __n); |
| 2703 | __sz += __n; |
| 2704 | __set_size(__sz); |
| 2705 | traits_type::assign(__p[__sz], value_type()); |
| 2706 | } |
| 2707 | } |
| 2708 | else |
| 2709 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); |
| 2710 | return *this; |
| 2711 | } |
| 2712 | |
| 2713 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2714 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2715 | basic_string<_CharT, _Traits, _Allocator>& |
| 2716 | basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) |
| 2717 | { |
| 2718 | if (__n) |
| 2719 | { |
| 2720 | size_type __cap = capacity(); |
| 2721 | size_type __sz = size(); |
| 2722 | if (__cap - __sz < __n) |
| 2723 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2724 | pointer __p = __get_pointer(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2725 | traits_type::assign(std::__to_address(__p) + __sz, __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2726 | __sz += __n; |
| 2727 | __set_size(__sz); |
| 2728 | traits_type::assign(__p[__sz], value_type()); |
| 2729 | } |
| 2730 | return *this; |
| 2731 | } |
| 2732 | |
| 2733 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2734 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 2735 | basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) |
| 2736 | { |
| 2737 | if (__n) |
| 2738 | { |
| 2739 | size_type __cap = capacity(); |
| 2740 | size_type __sz = size(); |
| 2741 | if (__cap - __sz < __n) |
| 2742 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2743 | pointer __p = __get_pointer(); |
| 2744 | __sz += __n; |
| 2745 | __set_size(__sz); |
| 2746 | traits_type::assign(__p[__sz], value_type()); |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2751 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2752 | void |
| 2753 | basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) |
| 2754 | { |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2755 | bool __is_short = !__is_long(); |
| 2756 | size_type __cap; |
| 2757 | size_type __sz; |
| 2758 | if (__is_short) |
| 2759 | { |
| 2760 | __cap = __min_cap - 1; |
| 2761 | __sz = __get_short_size(); |
| 2762 | } |
| 2763 | else |
| 2764 | { |
| 2765 | __cap = __get_long_cap() - 1; |
| 2766 | __sz = __get_long_size(); |
| 2767 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2768 | if (__sz == __cap) |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2769 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2770 | __grow_by(__cap, 1, __sz, __sz, 0); |
Louis Dionne | 82d2b2c | 2021-11-16 11:26:56 -0500 | [diff] [blame] | 2771 | __is_short = false; // the string is always long after __grow_by |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2772 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2773 | pointer __p = __get_pointer(); |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2774 | if (__is_short) |
| 2775 | { |
| 2776 | __p = __get_short_pointer() + __sz; |
| 2777 | __set_short_size(__sz+1); |
| 2778 | } |
| 2779 | else |
| 2780 | { |
| 2781 | __p = __get_long_pointer() + __sz; |
| 2782 | __set_long_size(__sz+1); |
| 2783 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2784 | traits_type::assign(*__p, __c); |
| 2785 | traits_type::assign(*++__p, value_type()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2786 | } |
| 2787 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2788 | template <class _CharT, class _Traits, class _Allocator> |
| 2789 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2790 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2791 | __enable_if_t |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2792 | < |
| 2793 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
| 2794 | basic_string<_CharT, _Traits, _Allocator>& |
| 2795 | > |
| 2796 | basic_string<_CharT, _Traits, _Allocator>::append( |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 2797 | _ForwardIterator __first, _ForwardIterator __last) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2798 | { |
| 2799 | size_type __sz = size(); |
| 2800 | size_type __cap = capacity(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2801 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2802 | if (__n) |
| 2803 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2804 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2805 | !__addr_in_range(*__first)) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2806 | { |
| 2807 | if (__cap - __sz < __n) |
| 2808 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2809 | pointer __p = __get_pointer() + __sz; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2810 | for (; __first != __last; ++__p, (void) ++__first) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2811 | traits_type::assign(*__p, *__first); |
| 2812 | traits_type::assign(*__p, value_type()); |
| 2813 | __set_size(__sz + __n); |
| 2814 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2815 | else |
| 2816 | { |
| 2817 | const basic_string __temp(__first, __last, __alloc()); |
| 2818 | append(__temp.data(), __temp.size()); |
| 2819 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2820 | } |
| 2821 | return *this; |
| 2822 | } |
| 2823 | |
| 2824 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2825 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2826 | basic_string<_CharT, _Traits, _Allocator>& |
| 2827 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) |
| 2828 | { |
| 2829 | size_type __sz = __str.size(); |
| 2830 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2831 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2832 | return append(__str.data() + __pos, std::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 2836 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2837 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2838 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2839 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2840 | __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] | 2841 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2842 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2843 | 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] | 2844 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2845 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2846 | size_type __sz = __sv.size(); |
| 2847 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2848 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2849 | return append(__sv.data() + __pos, std::min(__n, __sz - __pos)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2853 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2854 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2855 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2856 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2857 | _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2858 | return append(__s, traits_type::length(__s)); |
| 2859 | } |
| 2860 | |
| 2861 | // insert |
| 2862 | |
| 2863 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2864 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2865 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2866 | 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] | 2867 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2868 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2869 | size_type __sz = size(); |
| 2870 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2871 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2872 | size_type __cap = capacity(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 2873 | if (__libcpp_is_constant_evaluated()) { |
| 2874 | if (__cap - __sz >= __n) |
| 2875 | __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s); |
| 2876 | else |
| 2877 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2878 | return *this; |
| 2879 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2880 | if (__cap - __sz >= __n) |
| 2881 | { |
| 2882 | if (__n) |
| 2883 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2884 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2885 | size_type __n_move = __sz - __pos; |
| 2886 | if (__n_move != 0) |
| 2887 | { |
| 2888 | if (__p + __pos <= __s && __s < __p + __sz) |
| 2889 | __s += __n; |
| 2890 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2891 | } |
| 2892 | traits_type::move(__p + __pos, __s, __n); |
| 2893 | __sz += __n; |
| 2894 | __set_size(__sz); |
| 2895 | traits_type::assign(__p[__sz], value_type()); |
| 2896 | } |
| 2897 | } |
| 2898 | else |
| 2899 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2900 | return *this; |
| 2901 | } |
| 2902 | |
| 2903 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2904 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2905 | basic_string<_CharT, _Traits, _Allocator>& |
| 2906 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) |
| 2907 | { |
| 2908 | size_type __sz = size(); |
| 2909 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2910 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2911 | if (__n) |
| 2912 | { |
| 2913 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2914 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2915 | if (__cap - __sz >= __n) |
| 2916 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2917 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2918 | size_type __n_move = __sz - __pos; |
| 2919 | if (__n_move != 0) |
| 2920 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2921 | } |
| 2922 | else |
| 2923 | { |
| 2924 | __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 2925 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2926 | } |
| 2927 | traits_type::assign(__p + __pos, __n, __c); |
| 2928 | __sz += __n; |
| 2929 | __set_size(__sz); |
| 2930 | traits_type::assign(__p[__sz], value_type()); |
| 2931 | } |
| 2932 | return *this; |
| 2933 | } |
| 2934 | |
| 2935 | template <class _CharT, class _Traits, class _Allocator> |
| 2936 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2937 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2938 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2939 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2940 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2941 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2942 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2943 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) |
| 2944 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2945 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2946 | "string::insert(iterator, range) called with an iterator not" |
| 2947 | " referring to this string"); |
| 2948 | const basic_string __temp(__first, __last, __alloc()); |
| 2949 | return insert(__pos, __temp.data(), __temp.data() + __temp.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | template <class _CharT, class _Traits, class _Allocator> |
| 2953 | template<class _ForwardIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2954 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2955 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2956 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2957 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2958 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2959 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2960 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) |
| 2961 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2962 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2963 | "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] | 2964 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2965 | size_type __ip = static_cast<size_type>(__pos - begin()); |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2966 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
| 2967 | if (__n == 0) |
| 2968 | return begin() + __ip; |
| 2969 | |
| 2970 | if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2971 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2972 | return __insert_from_safe_copy(__n, __ip, __first, __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2973 | } |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2974 | else |
| 2975 | { |
| 2976 | const basic_string __temp(__first, __last, __alloc()); |
| 2977 | return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end()); |
| 2978 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2982 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2983 | basic_string<_CharT, _Traits, _Allocator>& |
| 2984 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, |
| 2985 | size_type __pos2, size_type __n) |
| 2986 | { |
| 2987 | size_type __str_sz = __str.size(); |
| 2988 | if (__pos2 > __str_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 | return insert(__pos1, __str.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | } |
| 2992 | |
| 2993 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2994 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 2995 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2996 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2997 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2998 | __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] | 2999 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3000 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3001 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3002 | size_type __pos2, size_type __n) |
| 3003 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3004 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3005 | size_type __str_sz = __sv.size(); |
| 3006 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3007 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3008 | return insert(__pos1, __sv.data() + __pos2, std::min(__n, __str_sz - __pos2)); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3012 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3013 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3014 | 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] | 3015 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3016 | _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3017 | return insert(__pos, __s, traits_type::length(__s)); |
| 3018 | } |
| 3019 | |
| 3020 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3021 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3022 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3023 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) |
| 3024 | { |
Louis Dionne | f4cc6fb | 2022-02-15 15:47:45 -0500 | [diff] [blame] | 3025 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3026 | "string::insert(iterator, character) called with an iterator not" |
| 3027 | " referring to this string"); |
| 3028 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3029 | size_type __ip = static_cast<size_type>(__pos - begin()); |
| 3030 | size_type __sz = size(); |
| 3031 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3032 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3033 | if (__cap == __sz) |
| 3034 | { |
| 3035 | __grow_by(__cap, 1, __sz, __ip, 0, 1); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3036 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3037 | } |
| 3038 | else |
| 3039 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3040 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3041 | size_type __n_move = __sz - __ip; |
| 3042 | if (__n_move != 0) |
| 3043 | traits_type::move(__p + __ip + 1, __p + __ip, __n_move); |
| 3044 | } |
| 3045 | traits_type::assign(__p[__ip], __c); |
| 3046 | traits_type::assign(__p[++__sz], value_type()); |
| 3047 | __set_size(__sz); |
| 3048 | return begin() + static_cast<difference_type>(__ip); |
| 3049 | } |
| 3050 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3051 | // replace |
| 3052 | |
| 3053 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3054 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3055 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3056 | 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] | 3057 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3058 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3059 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3060 | size_type __sz = size(); |
| 3061 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3062 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3063 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3064 | size_type __cap = capacity(); |
| 3065 | if (__cap - __sz + __n1 >= __n2) |
| 3066 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3067 | if (__libcpp_is_constant_evaluated()) { |
| 3068 | __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s); |
| 3069 | return *this; |
| 3070 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3071 | value_type* __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3072 | if (__n1 != __n2) |
| 3073 | { |
| 3074 | size_type __n_move = __sz - __pos - __n1; |
| 3075 | if (__n_move != 0) |
| 3076 | { |
| 3077 | if (__n1 > __n2) |
| 3078 | { |
| 3079 | traits_type::move(__p + __pos, __s, __n2); |
| 3080 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3081 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3082 | } |
| 3083 | if (__p + __pos < __s && __s < __p + __sz) |
| 3084 | { |
| 3085 | if (__p + __pos + __n1 <= __s) |
| 3086 | __s += __n2 - __n1; |
| 3087 | else // __p + __pos < __s < __p + __pos + __n1 |
| 3088 | { |
| 3089 | traits_type::move(__p + __pos, __s, __n1); |
| 3090 | __pos += __n1; |
| 3091 | __s += __n2; |
| 3092 | __n2 -= __n1; |
| 3093 | __n1 = 0; |
| 3094 | } |
| 3095 | } |
| 3096 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3097 | } |
| 3098 | } |
| 3099 | traits_type::move(__p + __pos, __s, __n2); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3100 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3101 | } |
| 3102 | else |
| 3103 | __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); |
| 3104 | return *this; |
| 3105 | } |
| 3106 | |
| 3107 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3108 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3109 | basic_string<_CharT, _Traits, _Allocator>& |
| 3110 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) |
| 3111 | { |
| 3112 | size_type __sz = size(); |
| 3113 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3114 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3115 | __n1 = std::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3116 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3117 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3118 | if (__cap - __sz + __n1 >= __n2) |
| 3119 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3120 | __p = std::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3121 | if (__n1 != __n2) |
| 3122 | { |
| 3123 | size_type __n_move = __sz - __pos - __n1; |
| 3124 | if (__n_move != 0) |
| 3125 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3126 | } |
| 3127 | } |
| 3128 | else |
| 3129 | { |
| 3130 | __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3131 | __p = std::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3132 | } |
| 3133 | traits_type::assign(__p + __pos, __n2, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3134 | return __null_terminate_at(__p, __sz - (__n1 - __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3135 | } |
| 3136 | |
| 3137 | template <class _CharT, class _Traits, class _Allocator> |
| 3138 | template<class _InputIterator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3139 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3140 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3141 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3142 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3143 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3144 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3145 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3146 | _InputIterator __j1, _InputIterator __j2) |
| 3147 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 3148 | const basic_string __temp(__j1, __j2, __alloc()); |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3149 | return replace(__i1, __i2, __temp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3153 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3154 | basic_string<_CharT, _Traits, _Allocator>& |
| 3155 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 3156 | size_type __pos2, size_type __n2) |
| 3157 | { |
| 3158 | size_type __str_sz = __str.size(); |
| 3159 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3160 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3161 | 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] | 3162 | } |
| 3163 | |
| 3164 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3165 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3166 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3167 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3168 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3169 | __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] | 3170 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3171 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3172 | 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] | 3173 | size_type __pos2, size_type __n2) |
| 3174 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3175 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3176 | size_type __str_sz = __sv.size(); |
| 3177 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3178 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3179 | 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] | 3180 | } |
| 3181 | |
| 3182 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3183 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3184 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3185 | 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] | 3186 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3187 | _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3188 | return replace(__pos, __n1, __s, traits_type::length(__s)); |
| 3189 | } |
| 3190 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3191 | // erase |
| 3192 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3193 | // 'externally instantiated' erase() implementation, called when __n != npos. |
| 3194 | // Does not check __pos against size() |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3195 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3196 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3197 | void |
| 3198 | basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( |
| 3199 | size_type __pos, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3200 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3201 | if (__n) |
| 3202 | { |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3203 | size_type __sz = size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3204 | value_type* __p = std::__to_address(__get_pointer()); |
| 3205 | __n = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3206 | size_type __n_move = __sz - __pos - __n; |
| 3207 | if (__n_move != 0) |
| 3208 | traits_type::move(__p + __pos, __p + __pos + __n, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3209 | __null_terminate_at(__p, __sz - __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3210 | } |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3214 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3215 | basic_string<_CharT, _Traits, _Allocator>& |
| 3216 | basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, |
| 3217 | size_type __n) { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3218 | if (__pos > size()) |
| 3219 | __throw_out_of_range(); |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3220 | if (__n == npos) { |
| 3221 | __erase_to_end(__pos); |
| 3222 | } else { |
| 3223 | __erase_external_with_move(__pos, __n); |
| 3224 | } |
| 3225 | return *this; |
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 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3231 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) |
| 3232 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3233 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3234 | "string::erase(iterator) called with an iterator not" |
| 3235 | " referring to this string"); |
| 3236 | |
| 3237 | _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); |
| 3238 | iterator __b = begin(); |
| 3239 | size_type __r = static_cast<size_type>(__pos - __b); |
| 3240 | erase(__r, 1); |
| 3241 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3245 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3246 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3247 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 3248 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3249 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 3250 | "string::erase(iterator, iterator) called with an iterator not" |
| 3251 | " referring to this string"); |
| 3252 | |
| 3253 | _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); |
| 3254 | iterator __b = begin(); |
| 3255 | size_type __r = static_cast<size_type>(__first - __b); |
| 3256 | erase(__r, static_cast<size_type>(__last - __first)); |
| 3257 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3261 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3262 | void |
| 3263 | basic_string<_CharT, _Traits, _Allocator>::pop_back() |
| 3264 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3265 | _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3266 | __erase_to_end(size() - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3270 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3271 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3272 | basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3273 | { |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3274 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3275 | if (__is_long()) |
| 3276 | { |
| 3277 | traits_type::assign(*__get_long_pointer(), value_type()); |
| 3278 | __set_long_size(0); |
| 3279 | } |
| 3280 | else |
| 3281 | { |
| 3282 | traits_type::assign(*__get_short_pointer(), value_type()); |
| 3283 | __set_short_size(0); |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3288 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3289 | void |
| 3290 | basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) |
| 3291 | { |
| 3292 | size_type __sz = size(); |
| 3293 | if (__n > __sz) |
| 3294 | append(__n - __sz, __c); |
| 3295 | else |
| 3296 | __erase_to_end(__n); |
| 3297 | } |
| 3298 | |
| 3299 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3300 | _LIBCPP_CONSTEXPR_SINCE_CXX20 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 3301 | basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) |
| 3302 | { |
| 3303 | size_type __sz = size(); |
| 3304 | if (__n > __sz) { |
| 3305 | __append_default_init(__n - __sz); |
| 3306 | } else |
| 3307 | __erase_to_end(__n); |
| 3308 | } |
| 3309 | |
| 3310 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3311 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3312 | void |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3313 | basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3314 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3315 | if (__requested_capacity > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3316 | __throw_length_error(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3317 | |
Louis Dionne | 05b6d3e | 2022-01-14 12:30:22 -0500 | [diff] [blame] | 3318 | // Make sure reserve(n) never shrinks. This is technically only required in C++20 |
| 3319 | // and later (since P0966R1), however we provide consistent behavior in all Standard |
| 3320 | // modes because this function is instantiated in the shared library. |
| 3321 | if (__requested_capacity <= capacity()) |
| 3322 | return; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3323 | |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3324 | size_type __target_capacity = std::max(__requested_capacity, size()); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3325 | __target_capacity = __recommend(__target_capacity); |
| 3326 | if (__target_capacity == capacity()) return; |
| 3327 | |
| 3328 | __shrink_or_extend(__target_capacity); |
| 3329 | } |
| 3330 | |
| 3331 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3332 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3333 | void |
| 3334 | basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT |
| 3335 | { |
| 3336 | size_type __target_capacity = __recommend(size()); |
| 3337 | if (__target_capacity == capacity()) return; |
| 3338 | |
| 3339 | __shrink_or_extend(__target_capacity); |
| 3340 | } |
| 3341 | |
| 3342 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3343 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3344 | void |
| 3345 | basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) |
| 3346 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3347 | size_type __cap = capacity(); |
| 3348 | size_type __sz = size(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3349 | |
| 3350 | pointer __new_data, __p; |
| 3351 | bool __was_long, __now_long; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3352 | if (__fits_in_sso(__target_capacity)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3353 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3354 | __was_long = true; |
| 3355 | __now_long = false; |
| 3356 | __new_data = __get_short_pointer(); |
| 3357 | __p = __get_long_pointer(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3358 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3359 | else |
| 3360 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3361 | if (__target_capacity > __cap) { |
| 3362 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3363 | __new_data = __allocation.ptr; |
| 3364 | __target_capacity = __allocation.count - 1; |
| 3365 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3366 | else |
| 3367 | { |
| 3368 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3369 | try |
| 3370 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3371 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3372 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3373 | __new_data = __allocation.ptr; |
| 3374 | __target_capacity = __allocation.count - 1; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3375 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3376 | } |
| 3377 | catch (...) |
| 3378 | { |
| 3379 | return; |
| 3380 | } |
| 3381 | #else // _LIBCPP_NO_EXCEPTIONS |
| 3382 | if (__new_data == nullptr) |
| 3383 | return; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3384 | #endif // _LIBCPP_NO_EXCEPTIONS |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3385 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame] | 3386 | __begin_lifetime(__new_data, __target_capacity + 1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3387 | __now_long = true; |
| 3388 | __was_long = __is_long(); |
| 3389 | __p = __get_pointer(); |
| 3390 | } |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3391 | traits_type::copy(std::__to_address(__new_data), |
| 3392 | std::__to_address(__p), size()+1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3393 | if (__was_long) |
| 3394 | __alloc_traits::deallocate(__alloc(), __p, __cap+1); |
| 3395 | if (__now_long) |
| 3396 | { |
| 3397 | __set_long_cap(__target_capacity+1); |
| 3398 | __set_long_size(__sz); |
| 3399 | __set_long_pointer(__new_data); |
| 3400 | } |
| 3401 | else |
| 3402 | __set_short_size(__sz); |
Nikolas Klauser | f1d286b | 2022-05-08 16:40:04 +0200 | [diff] [blame] | 3403 | std::__debug_db_invalidate_all(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3404 | } |
| 3405 | |
| 3406 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3407 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3408 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 3409 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const |
| 3410 | { |
| 3411 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3412 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3413 | return (*this)[__n]; |
| 3414 | } |
| 3415 | |
| 3416 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3417 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3418 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 3419 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) |
| 3420 | { |
| 3421 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3422 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3423 | return (*this)[__n]; |
| 3424 | } |
| 3425 | |
| 3426 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3427 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3428 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3429 | 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] | 3430 | { |
| 3431 | size_type __sz = size(); |
| 3432 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3433 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3434 | size_type __rlen = std::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3435 | traits_type::copy(__s, data() + __pos, __rlen); |
| 3436 | return __rlen; |
| 3437 | } |
| 3438 | |
| 3439 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3440 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3441 | void |
| 3442 | basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3443 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3444 | _NOEXCEPT |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3445 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3446 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3447 | __is_nothrow_swappable<allocator_type>::value) |
| 3448 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3449 | { |
Nikolas Klauser | 9883354 | 2022-05-07 22:20:23 +0200 | [diff] [blame] | 3450 | if (!__is_long()) |
| 3451 | std::__debug_db_invalidate_all(this); |
| 3452 | if (!__str.__is_long()) |
| 3453 | std::__debug_db_invalidate_all(&__str); |
| 3454 | std::__debug_db_swap(this, &__str); |
| 3455 | |
Eric Fiselier | 9bf691f | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 3456 | _LIBCPP_ASSERT( |
| 3457 | __alloc_traits::propagate_on_container_swap::value || |
| 3458 | __alloc_traits::is_always_equal::value || |
| 3459 | __alloc() == __str.__alloc(), "swapping non-equal allocators"); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3460 | std::swap(__r_.first(), __str.__r_.first()); |
| 3461 | std::__swap_allocator(__alloc(), __str.__alloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | // find |
| 3465 | |
| 3466 | template <class _Traits> |
| 3467 | struct _LIBCPP_HIDDEN __traits_eq |
| 3468 | { |
| 3469 | typedef typename _Traits::char_type char_type; |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3470 | _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3471 | bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT |
| 3472 | {return _Traits::eq(__x, __y);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3473 | }; |
| 3474 | |
| 3475 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3476 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3477 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3478 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3479 | size_type __pos, |
| 3480 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3481 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3482 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3483 | return std::__str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3484 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3485 | } |
| 3486 | |
| 3487 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3488 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3489 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3490 | basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, |
| 3491 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3492 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3493 | return std::__str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3494 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3498 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3499 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3500 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3501 | < |
| 3502 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3503 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3504 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3505 | basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3506 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3507 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3508 | __self_view __sv = __t; |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3509 | return std::__str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3510 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3511 | } |
| 3512 | |
| 3513 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3514 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3515 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3516 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3517 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3518 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3519 | _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3520 | return std::__str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3521 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3525 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3526 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3527 | basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, |
| 3528 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3529 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3530 | return std::__str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3531 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | // rfind |
| 3535 | |
| 3536 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3537 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3538 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3539 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3540 | size_type __pos, |
| 3541 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3542 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3543 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3544 | return std::__str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3545 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3549 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3550 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3551 | basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, |
| 3552 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3553 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3554 | return std::__str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3555 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3559 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3560 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3561 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3562 | < |
| 3563 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3564 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3565 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3566 | basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3567 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3568 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3569 | __self_view __sv = __t; |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3570 | return std::__str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3571 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3572 | } |
| 3573 | |
| 3574 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3575 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3576 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3577 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3578 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3579 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3580 | _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3581 | return std::__str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3582 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3586 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3587 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3588 | basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, |
| 3589 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3590 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3591 | return std::__str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3592 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | // find_first_of |
| 3596 | |
| 3597 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3598 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3599 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3600 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3601 | size_type __pos, |
| 3602 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3603 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3604 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3605 | return std::__str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3606 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3610 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3611 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3612 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, |
| 3613 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3614 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3615 | return std::__str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3616 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3620 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3621 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3622 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3623 | < |
| 3624 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3625 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3626 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3627 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3628 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3629 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3630 | __self_view __sv = __t; |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3631 | return std::__str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3632 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3633 | } |
| 3634 | |
| 3635 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3636 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3637 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3638 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3639 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3640 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3641 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3642 | return std::__str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3643 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3644 | } |
| 3645 | |
| 3646 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3647 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3648 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3649 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, |
| 3650 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3651 | { |
| 3652 | return find(__c, __pos); |
| 3653 | } |
| 3654 | |
| 3655 | // find_last_of |
| 3656 | |
| 3657 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3658 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3659 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3660 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3661 | size_type __pos, |
| 3662 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3663 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3664 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3665 | return std::__str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3666 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
| 3669 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3670 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3671 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3672 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, |
| 3673 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3674 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3675 | return std::__str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3676 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3680 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3681 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3682 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3683 | < |
| 3684 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3685 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3686 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3687 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3688 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3689 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3690 | __self_view __sv = __t; |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3691 | return std::__str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3692 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3693 | } |
| 3694 | |
| 3695 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3696 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3697 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3698 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3699 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3700 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3701 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3702 | return std::__str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3703 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3707 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3708 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3709 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, |
| 3710 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3711 | { |
| 3712 | return rfind(__c, __pos); |
| 3713 | } |
| 3714 | |
| 3715 | // find_first_not_of |
| 3716 | |
| 3717 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3718 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3719 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3720 | 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] | 3721 | size_type __pos, |
| 3722 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3723 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3724 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3725 | return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3726 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3730 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3731 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3732 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, |
| 3733 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3734 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3735 | return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3736 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3737 | } |
| 3738 | |
| 3739 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3740 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3741 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3742 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3743 | < |
| 3744 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3745 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3746 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3747 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3748 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3749 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3750 | __self_view __sv = __t; |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3751 | return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3752 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3753 | } |
| 3754 | |
| 3755 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3756 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3757 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3758 | 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] | 3759 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3760 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3761 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3762 | return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3763 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3767 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3768 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3769 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, |
| 3770 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3771 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3772 | return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3773 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | // find_last_not_of |
| 3777 | |
| 3778 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3779 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3780 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3781 | 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] | 3782 | size_type __pos, |
| 3783 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3784 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3785 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3786 | return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3787 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3791 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3792 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3793 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, |
| 3794 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3795 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3796 | return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3797 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3801 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3802 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3803 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3804 | < |
| 3805 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3806 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3807 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3808 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3809 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3810 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3811 | __self_view __sv = __t; |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3812 | return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3813 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3814 | } |
| 3815 | |
| 3816 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3817 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3818 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3819 | 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] | 3820 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3821 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3822 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3823 | return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3824 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3828 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3829 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3830 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, |
| 3831 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3832 | { |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 3833 | return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3834 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | // compare |
| 3838 | |
| 3839 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3840 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3841 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3842 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3843 | < |
| 3844 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3845 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3846 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3847 | basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3848 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3849 | __self_view __sv = __t; |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3850 | size_t __lhs_sz = size(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3851 | size_t __rhs_sz = __sv.size(); |
| 3852 | int __result = traits_type::compare(data(), __sv.data(), |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3853 | std::min(__lhs_sz, __rhs_sz)); |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 3854 | if (__result != 0) |
| 3855 | return __result; |
| 3856 | if (__lhs_sz < __rhs_sz) |
| 3857 | return -1; |
| 3858 | if (__lhs_sz > __rhs_sz) |
| 3859 | return 1; |
| 3860 | return 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3864 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3865 | int |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3866 | basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3867 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3868 | return compare(__self_view(__str)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3872 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3873 | int |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3874 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3875 | size_type __n1, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3876 | const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3877 | size_type __n2) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3878 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3879 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3880 | size_type __sz = size(); |
| 3881 | if (__pos1 > __sz || __n2 == npos) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3882 | __throw_out_of_range(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 3883 | size_type __rlen = std::min(__n1, __sz - __pos1); |
| 3884 | int __r = traits_type::compare(data() + __pos1, __s, std::min(__rlen, __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3885 | if (__r == 0) |
| 3886 | { |
| 3887 | if (__rlen < __n2) |
| 3888 | __r = -1; |
| 3889 | else if (__rlen > __n2) |
| 3890 | __r = 1; |
| 3891 | } |
| 3892 | return __r; |
| 3893 | } |
| 3894 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3895 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3896 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3897 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3898 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3899 | < |
| 3900 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3901 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3902 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3903 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3904 | size_type __n1, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3905 | const _Tp& __t) const |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3906 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3907 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3908 | return compare(__pos1, __n1, __sv.data(), __sv.size()); |
| 3909 | } |
| 3910 | |
| 3911 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3912 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3913 | int |
| 3914 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3915 | size_type __n1, |
| 3916 | const basic_string& __str) const |
| 3917 | { |
| 3918 | return compare(__pos1, __n1, __str.data(), __str.size()); |
| 3919 | } |
| 3920 | |
| 3921 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3922 | template <class _Tp> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3923 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3924 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3925 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3926 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 3927 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 3928 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3929 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3930 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3931 | size_type __n1, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3932 | const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3933 | size_type __pos2, |
| 3934 | size_type __n2) const |
| 3935 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3936 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3937 | return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 3938 | } |
| 3939 | |
| 3940 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3941 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3942 | int |
| 3943 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3944 | size_type __n1, |
| 3945 | const basic_string& __str, |
| 3946 | size_type __pos2, |
| 3947 | size_type __n2) const |
| 3948 | { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3949 | return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3953 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3954 | int |
| 3955 | basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT |
| 3956 | { |
| 3957 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 3958 | return compare(0, npos, __s, traits_type::length(__s)); |
| 3959 | } |
| 3960 | |
| 3961 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3962 | _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3963 | int |
| 3964 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 3965 | size_type __n1, |
| 3966 | const value_type* __s) const |
| 3967 | { |
| 3968 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 3969 | return compare(__pos1, __n1, __s, traits_type::length(__s)); |
| 3970 | } |
| 3971 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3972 | // __invariants |
| 3973 | |
| 3974 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3975 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3976 | bool |
| 3977 | basic_string<_CharT, _Traits, _Allocator>::__invariants() const |
| 3978 | { |
| 3979 | if (size() > capacity()) |
| 3980 | return false; |
| 3981 | if (capacity() < __min_cap - 1) |
| 3982 | return false; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 3983 | if (data() == nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3984 | return false; |
Louis Dionne | 663415f | 2020-10-05 16:16:13 -0400 | [diff] [blame] | 3985 | if (data()[size()] != value_type()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3986 | return false; |
| 3987 | return true; |
| 3988 | } |
| 3989 | |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 3990 | // __clear_and_shrink |
| 3991 | |
| 3992 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 3993 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 3994 | void |
Marshall Clow | e60a718 | 2018-05-29 17:04:37 +0000 | [diff] [blame] | 3995 | basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 3996 | { |
| 3997 | clear(); |
| 3998 | if(__is_long()) |
| 3999 | { |
| 4000 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); |
Nikolas Klauser | 1821ec3 | 2022-10-01 15:37:24 +0200 | [diff] [blame] | 4001 | __default_init(); |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4002 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4003 | } |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4004 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4005 | // operator== |
| 4006 | |
| 4007 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4008 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4009 | bool |
| 4010 | operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4011 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4012 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4013 | #if _LIBCPP_STD_VER > 17 |
| 4014 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4015 | #else |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4016 | size_t __lhs_sz = __lhs.size(); |
| 4017 | return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), |
| 4018 | __rhs.data(), |
| 4019 | __lhs_sz) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4020 | #endif |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | template<class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4024 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4025 | bool |
| 4026 | operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, |
| 4027 | const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT |
| 4028 | { |
| 4029 | size_t __lhs_sz = __lhs.size(); |
| 4030 | if (__lhs_sz != __rhs.size()) |
| 4031 | return false; |
| 4032 | const char* __lp = __lhs.data(); |
| 4033 | const char* __rp = __rhs.data(); |
| 4034 | if (__lhs.__is_long()) |
| 4035 | return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; |
| 4036 | for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) |
| 4037 | if (*__lp != *__rp) |
| 4038 | return false; |
| 4039 | return true; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4040 | } |
| 4041 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4042 | #if _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4043 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4044 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4045 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4046 | operator==(const _CharT* __lhs, |
| 4047 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4048 | { |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4049 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4050 | _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); |
| 4051 | size_t __lhs_len = _Traits::length(__lhs); |
| 4052 | if (__lhs_len != __rhs.size()) return false; |
| 4053 | return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4054 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4055 | #endif // _LIBCPP_STD_VER <= 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4056 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4057 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4058 | inline _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4059 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4060 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
| 4061 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4062 | { |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4063 | #if _LIBCPP_STD_VER > 17 |
| 4064 | return basic_string_view<_CharT, _Traits>(__lhs) == basic_string_view<_CharT, _Traits>(__rhs); |
| 4065 | #else |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4066 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4067 | _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); |
| 4068 | size_t __rhs_len = _Traits::length(__rhs); |
| 4069 | if (__rhs_len != __lhs.size()) return false; |
| 4070 | return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4071 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4072 | } |
| 4073 | |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4074 | #if _LIBCPP_STD_VER > 17 |
| 4075 | |
| 4076 | template <class _CharT, class _Traits, class _Allocator> |
| 4077 | _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>( |
| 4078 | const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4079 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) noexcept { |
| 4080 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4081 | } |
| 4082 | |
| 4083 | template <class _CharT, class _Traits, class _Allocator> |
| 4084 | _LIBCPP_HIDE_FROM_ABI constexpr auto |
| 4085 | operator<=>(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) { |
| 4086 | return basic_string_view<_CharT, _Traits>(__lhs) <=> basic_string_view<_CharT, _Traits>(__rhs); |
| 4087 | } |
| 4088 | |
| 4089 | #else // _LIBCPP_STD_VER > 17 |
| 4090 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4091 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4092 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4093 | bool |
| 4094 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4095 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4096 | { |
| 4097 | return !(__lhs == __rhs); |
| 4098 | } |
| 4099 | |
| 4100 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4101 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4102 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4103 | operator!=(const _CharT* __lhs, |
| 4104 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4105 | { |
| 4106 | return !(__lhs == __rhs); |
| 4107 | } |
| 4108 | |
| 4109 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4110 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4111 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4112 | operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4113 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4114 | { |
| 4115 | return !(__lhs == __rhs); |
| 4116 | } |
| 4117 | |
| 4118 | // operator< |
| 4119 | |
| 4120 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4121 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4122 | bool |
| 4123 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4124 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4125 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4126 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4130 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4131 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4132 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4133 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4134 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4135 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4136 | } |
| 4137 | |
| 4138 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4139 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4140 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4141 | operator< (const _CharT* __lhs, |
| 4142 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4143 | { |
| 4144 | return __rhs.compare(__lhs) > 0; |
| 4145 | } |
| 4146 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4147 | // operator> |
| 4148 | |
| 4149 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4150 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4151 | bool |
| 4152 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4153 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4154 | { |
| 4155 | return __rhs < __lhs; |
| 4156 | } |
| 4157 | |
| 4158 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4159 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4160 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4161 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4162 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4163 | { |
| 4164 | return __rhs < __lhs; |
| 4165 | } |
| 4166 | |
| 4167 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4168 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4169 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4170 | operator> (const _CharT* __lhs, |
| 4171 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4172 | { |
| 4173 | return __rhs < __lhs; |
| 4174 | } |
| 4175 | |
| 4176 | // operator<= |
| 4177 | |
| 4178 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4179 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4180 | bool |
| 4181 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4182 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4183 | { |
| 4184 | return !(__rhs < __lhs); |
| 4185 | } |
| 4186 | |
| 4187 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4188 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4189 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4190 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4191 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4192 | { |
| 4193 | return !(__rhs < __lhs); |
| 4194 | } |
| 4195 | |
| 4196 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4197 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4198 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4199 | operator<=(const _CharT* __lhs, |
| 4200 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4201 | { |
| 4202 | return !(__rhs < __lhs); |
| 4203 | } |
| 4204 | |
| 4205 | // operator>= |
| 4206 | |
| 4207 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4208 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4209 | bool |
| 4210 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4211 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4212 | { |
| 4213 | return !(__lhs < __rhs); |
| 4214 | } |
| 4215 | |
| 4216 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4217 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4218 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4219 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4220 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4221 | { |
| 4222 | return !(__lhs < __rhs); |
| 4223 | } |
| 4224 | |
| 4225 | template<class _CharT, class _Traits, class _Allocator> |
Mark de Wever | af1968a | 2022-08-14 14:14:09 +0200 | [diff] [blame] | 4226 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4227 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4228 | operator>=(const _CharT* __lhs, |
| 4229 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4230 | { |
| 4231 | return !(__lhs < __rhs); |
| 4232 | } |
Mark de Wever | b4830e6 | 2022-07-19 07:56:23 +0200 | [diff] [blame] | 4233 | #endif // _LIBCPP_STD_VER > 17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4234 | |
| 4235 | // operator + |
| 4236 | |
| 4237 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4238 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4239 | basic_string<_CharT, _Traits, _Allocator> |
| 4240 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4241 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4242 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4243 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4244 | auto __lhs_sz = __lhs.size(); |
| 4245 | auto __rhs_sz = __rhs.size(); |
| 4246 | _String __r(__uninitialized_size_tag(), |
| 4247 | __lhs_sz + __rhs_sz, |
| 4248 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4249 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4250 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4251 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4252 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4253 | return __r; |
| 4254 | } |
| 4255 | |
| 4256 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4257 | _LIBCPP_HIDDEN _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4258 | basic_string<_CharT, _Traits, _Allocator> |
| 4259 | operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4260 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4261 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4262 | auto __lhs_sz = _Traits::length(__lhs); |
| 4263 | auto __rhs_sz = __rhs.size(); |
| 4264 | _String __r(__uninitialized_size_tag(), |
| 4265 | __lhs_sz + __rhs_sz, |
| 4266 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4267 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4268 | _Traits::copy(__ptr, __lhs, __lhs_sz); |
| 4269 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4270 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4271 | return __r; |
| 4272 | } |
| 4273 | |
| 4274 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4275 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4276 | basic_string<_CharT, _Traits, _Allocator> |
| 4277 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4278 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4279 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4280 | typename _String::size_type __rhs_sz = __rhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4281 | _String __r(__uninitialized_size_tag(), |
| 4282 | __rhs_sz + 1, |
| 4283 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4284 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4285 | _Traits::assign(__ptr, 1, __lhs); |
| 4286 | _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz); |
| 4287 | _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4288 | return __r; |
| 4289 | } |
| 4290 | |
| 4291 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4292 | inline _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, const _CharT* __rhs) |
| 4295 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4296 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4297 | typename _String::size_type __lhs_sz = __lhs.size(); |
| 4298 | typename _String::size_type __rhs_sz = _Traits::length(__rhs); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4299 | _String __r(__uninitialized_size_tag(), |
| 4300 | __lhs_sz + __rhs_sz, |
| 4301 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4302 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4303 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4304 | _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz); |
| 4305 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4306 | return __r; |
| 4307 | } |
| 4308 | |
| 4309 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4310 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4311 | basic_string<_CharT, _Traits, _Allocator> |
| 4312 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) |
| 4313 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4314 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4315 | typename _String::size_type __lhs_sz = __lhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4316 | _String __r(__uninitialized_size_tag(), |
| 4317 | __lhs_sz + 1, |
| 4318 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4319 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4320 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4321 | _Traits::assign(__ptr + __lhs_sz, 1, __rhs); |
| 4322 | _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4323 | return __r; |
| 4324 | } |
| 4325 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 4326 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4327 | |
| 4328 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4329 | inline _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+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4332 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4333 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4334 | } |
| 4335 | |
| 4336 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4337 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4338 | basic_string<_CharT, _Traits, _Allocator> |
| 4339 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4340 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4341 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4345 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4346 | basic_string<_CharT, _Traits, _Allocator> |
| 4347 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4348 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4349 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4350 | } |
| 4351 | |
| 4352 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4353 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4354 | basic_string<_CharT, _Traits, _Allocator> |
| 4355 | operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4356 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4357 | return std::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4361 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4362 | basic_string<_CharT, _Traits, _Allocator> |
| 4363 | operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4364 | { |
| 4365 | __rhs.insert(__rhs.begin(), __lhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4366 | return std::move(__rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4370 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4371 | basic_string<_CharT, _Traits, _Allocator> |
| 4372 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) |
| 4373 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4374 | return std::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4378 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4379 | basic_string<_CharT, _Traits, _Allocator> |
| 4380 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) |
| 4381 | { |
| 4382 | __lhs.push_back(__rhs); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4383 | return std::move(__lhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4384 | } |
| 4385 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4386 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4387 | |
| 4388 | // swap |
| 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 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4393 | swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 4394 | basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4395 | _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4396 | { |
| 4397 | __lhs.swap(__rhs); |
| 4398 | } |
| 4399 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4400 | _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4401 | _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4402 | _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4403 | _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4404 | _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] | 4405 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4406 | _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr); |
| 4407 | _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr); |
| 4408 | _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] | 4409 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4410 | _LIBCPP_FUNC_VIS string to_string(int __val); |
| 4411 | _LIBCPP_FUNC_VIS string to_string(unsigned __val); |
| 4412 | _LIBCPP_FUNC_VIS string to_string(long __val); |
| 4413 | _LIBCPP_FUNC_VIS string to_string(unsigned long __val); |
| 4414 | _LIBCPP_FUNC_VIS string to_string(long long __val); |
| 4415 | _LIBCPP_FUNC_VIS string to_string(unsigned long long __val); |
| 4416 | _LIBCPP_FUNC_VIS string to_string(float __val); |
| 4417 | _LIBCPP_FUNC_VIS string to_string(double __val); |
| 4418 | _LIBCPP_FUNC_VIS string to_string(long double __val); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4419 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4420 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4421 | _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4422 | _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4423 | _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4424 | _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4425 | _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] | 4426 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4427 | _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr); |
| 4428 | _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr); |
| 4429 | _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] | 4430 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4431 | _LIBCPP_FUNC_VIS wstring to_wstring(int __val); |
| 4432 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); |
| 4433 | _LIBCPP_FUNC_VIS wstring to_wstring(long __val); |
| 4434 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); |
| 4435 | _LIBCPP_FUNC_VIS wstring to_wstring(long long __val); |
| 4436 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); |
| 4437 | _LIBCPP_FUNC_VIS wstring to_wstring(float __val); |
| 4438 | _LIBCPP_FUNC_VIS wstring to_wstring(double __val); |
| 4439 | _LIBCPP_FUNC_VIS wstring to_wstring(long double __val); |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4440 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4441 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4442 | template<class _CharT, class _Traits, class _Allocator> |
Martin Storsjö | 88890c2 | 2021-02-22 01:13:13 +0200 | [diff] [blame] | 4443 | _LIBCPP_TEMPLATE_DATA_VIS |
Eric Fiselier | c9fdaf1 | 2020-01-15 17:02:17 -0500 | [diff] [blame] | 4444 | const typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4445 | basic_string<_CharT, _Traits, _Allocator>::npos; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4446 | |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4447 | template <class _CharT, class _Allocator> |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4448 | 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] | 4449 | { |
| 4450 | size_t |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4451 | operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT |
Nikolas Klauser | 0ada919 | 2022-08-13 22:33:12 +0200 | [diff] [blame^] | 4452 | { return std::__do_string_hash(__val.data(), __val.data() + __val.size()); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4453 | }; |
| 4454 | |
Nikolas Klauser | 3ab26e3 | 2022-08-22 02:59:09 +0200 | [diff] [blame] | 4455 | template <class _Allocator> |
| 4456 | struct hash<basic_string<char, char_traits<char>, _Allocator> > : __string_hash<char, _Allocator> {}; |
| 4457 | |
| 4458 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
| 4459 | template <class _Allocator> |
| 4460 | struct hash<basic_string<char8_t, char_traits<char8_t>, _Allocator> > : __string_hash<char8_t, _Allocator> {}; |
| 4461 | #endif |
| 4462 | |
| 4463 | template <class _Allocator> |
| 4464 | struct hash<basic_string<char16_t, char_traits<char16_t>, _Allocator> > : __string_hash<char16_t, _Allocator> {}; |
| 4465 | |
| 4466 | template <class _Allocator> |
| 4467 | struct hash<basic_string<char32_t, char_traits<char32_t>, _Allocator> > : __string_hash<char32_t, _Allocator> {}; |
| 4468 | |
| 4469 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4470 | template <class _Allocator> |
| 4471 | struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Allocator> > : __string_hash<wchar_t, _Allocator> {}; |
| 4472 | #endif |
| 4473 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4474 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4475 | _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4476 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4477 | const basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4478 | |
| 4479 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4480 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4481 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4482 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4483 | |
| 4484 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 4485 | _LIBCPP_HIDE_FROM_ABI basic_istream<_CharT, _Traits>& |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4486 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4487 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4488 | |
| 4489 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4490 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4491 | basic_istream<_CharT, _Traits>& |
| 4492 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4493 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4494 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4495 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4496 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4497 | basic_istream<_CharT, _Traits>& |
| 4498 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4499 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4500 | |
| 4501 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4502 | inline _LIBCPP_HIDE_FROM_ABI |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4503 | basic_istream<_CharT, _Traits>& |
| 4504 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4505 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4506 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4507 | #if _LIBCPP_STD_VER > 17 |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4508 | template <class _CharT, class _Traits, class _Allocator, class _Up> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4509 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4510 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4511 | erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) { |
| 4512 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4513 | __str.erase(std::remove(__str.begin(), __str.end(), __v), __str.end()); |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4514 | return __old_size - __str.size(); |
| 4515 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4516 | |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4517 | template <class _CharT, class _Traits, class _Allocator, class _Predicate> |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4518 | inline _LIBCPP_HIDE_FROM_ABI |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4519 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4520 | erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, |
| 4521 | _Predicate __pred) { |
| 4522 | auto __old_size = __str.size(); |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4523 | __str.erase(std::remove_if(__str.begin(), __str.end(), __pred), |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4524 | __str.end()); |
| 4525 | return __old_size - __str.size(); |
| 4526 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4527 | #endif |
| 4528 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4529 | #ifdef _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4530 | |
| 4531 | template<class _CharT, class _Traits, class _Allocator> |
| 4532 | bool |
| 4533 | basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 4534 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4535 | return data() <= std::__to_address(__i->base()) && |
| 4536 | std::__to_address(__i->base()) < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | template<class _CharT, class _Traits, class _Allocator> |
| 4540 | bool |
| 4541 | basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const |
| 4542 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4543 | return data() < std::__to_address(__i->base()) && |
| 4544 | std::__to_address(__i->base()) <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4545 | } |
| 4546 | |
| 4547 | template<class _CharT, class _Traits, class _Allocator> |
| 4548 | bool |
| 4549 | basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 4550 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4551 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4552 | return data() <= __p && __p <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4553 | } |
| 4554 | |
| 4555 | template<class _CharT, class _Traits, class _Allocator> |
| 4556 | bool |
| 4557 | basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 4558 | { |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4559 | const value_type* __p = std::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4560 | return data() <= __p && __p < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4561 | } |
| 4562 | |
Louis Dionne | 510450b | 2022-04-01 16:38:30 -0400 | [diff] [blame] | 4563 | #endif // _LIBCPP_ENABLE_DEBUG_MODE |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4564 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4565 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4566 | // Literal suffixes for basic_string [basic.string.literals] |
Marshall Clow | ac86837 | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 4567 | inline namespace literals |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4568 | { |
| 4569 | inline namespace string_literals |
| 4570 | { |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4571 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4572 | basic_string<char> operator "" s( const char *__str, size_t __len ) |
| 4573 | { |
| 4574 | return basic_string<char> (__str, __len); |
| 4575 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4576 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4577 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4578 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4579 | basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) |
| 4580 | { |
| 4581 | return basic_string<wchar_t> (__str, __len); |
| 4582 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4583 | #endif |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4584 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 4585 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Nikolas Klauser | 1d5108d | 2022-04-29 11:17:58 +0200 | [diff] [blame] | 4586 | inline _LIBCPP_HIDE_FROM_ABI constexpr |
Nikolas Klauser | 5da956d | 2022-09-02 16:20:28 +0200 | [diff] [blame] | 4587 | 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] | 4588 | { |
| 4589 | return basic_string<char8_t> (__str, __len); |
| 4590 | } |
| 4591 | #endif |
| 4592 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4593 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4594 | basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) |
| 4595 | { |
| 4596 | return basic_string<char16_t> (__str, __len); |
| 4597 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4598 | |
Nikolas Klauser | 8b1c506 | 2022-08-19 13:08:01 +0200 | [diff] [blame] | 4599 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4600 | basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) |
| 4601 | { |
| 4602 | return basic_string<char32_t> (__str, __len); |
| 4603 | } |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 4604 | } // namespace string_literals |
| 4605 | } // namespace literals |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 4606 | |
| 4607 | #if _LIBCPP_STD_VER > 17 |
| 4608 | template <> |
| 4609 | inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true; |
| 4610 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4611 | template <> |
| 4612 | inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true; |
| 4613 | #endif |
| 4614 | #endif |
| 4615 | |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4616 | #endif |
| 4617 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4618 | _LIBCPP_END_NAMESPACE_STD |
| 4619 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 4620 | _LIBCPP_POP_MACROS |
| 4621 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 4622 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
| 4623 | # include <algorithm> |
Nikolas Klauser | 1e4ae5d | 2022-11-02 20:27:42 +0100 | [diff] [blame] | 4624 | # include <concepts> |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 4625 | # include <functional> |
| 4626 | # include <iterator> |
| 4627 | # include <new> |
| 4628 | # include <typeinfo> |
| 4629 | # include <utility> |
| 4630 | # include <vector> |
| 4631 | #endif |
| 4632 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4633 | #endif // _LIBCPP_STRING |