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 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class stateT> |
| 20 | class fpos |
| 21 | { |
| 22 | private: |
| 23 | stateT st; |
| 24 | public: |
| 25 | fpos(streamoff = streamoff()); |
| 26 | |
| 27 | operator streamoff() const; |
| 28 | |
| 29 | stateT state() const; |
| 30 | void state(stateT); |
| 31 | |
| 32 | fpos& operator+=(streamoff); |
| 33 | fpos operator+ (streamoff) const; |
| 34 | fpos& operator-=(streamoff); |
| 35 | fpos operator- (streamoff) const; |
| 36 | }; |
| 37 | |
| 38 | template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y); |
| 39 | |
| 40 | template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y); |
| 41 | template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y); |
| 42 | |
| 43 | template <class charT> |
| 44 | struct char_traits |
| 45 | { |
| 46 | typedef charT char_type; |
| 47 | typedef ... int_type; |
| 48 | typedef streamoff off_type; |
| 49 | typedef streampos pos_type; |
| 50 | typedef mbstate_t state_type; |
| 51 | |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 52 | static void assign(char_type& c1, const char_type& c2) noexcept; |
Howard Hinnant | 270c00e | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 53 | static constexpr bool eq(char_type c1, char_type c2) noexcept; |
| 54 | static constexpr bool lt(char_type c1, char_type c2) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | |
| 56 | static int compare(const char_type* s1, const char_type* s2, size_t n); |
| 57 | static size_t length(const char_type* s); |
| 58 | static const char_type* find(const char_type* s, size_t n, const char_type& a); |
| 59 | static char_type* move(char_type* s1, const char_type* s2, size_t n); |
| 60 | static char_type* copy(char_type* s1, const char_type* s2, size_t n); |
| 61 | static char_type* assign(char_type* s, size_t n, char_type a); |
| 62 | |
Howard Hinnant | 270c00e | 2012-07-20 19:09:12 +0000 | [diff] [blame] | 63 | static constexpr int_type not_eof(int_type c) noexcept; |
| 64 | static constexpr char_type to_char_type(int_type c) noexcept; |
| 65 | static constexpr int_type to_int_type(char_type c) noexcept; |
| 66 | static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; |
| 67 | static constexpr int_type eof() noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | template <> struct char_traits<char>; |
| 71 | template <> struct char_traits<wchar_t>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 72 | template <> struct char_traits<char8_t>; // C++20 |
| 73 | template <> struct char_traits<char16_t>; |
| 74 | template <> struct char_traits<char32_t>; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 76 | template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 77 | class basic_string |
| 78 | { |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 79 | public: |
| 80 | // types: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 81 | typedef traits traits_type; |
| 82 | typedef typename traits_type::char_type value_type; |
| 83 | typedef Allocator allocator_type; |
| 84 | typedef typename allocator_type::size_type size_type; |
| 85 | typedef typename allocator_type::difference_type difference_type; |
| 86 | typedef typename allocator_type::reference reference; |
| 87 | typedef typename allocator_type::const_reference const_reference; |
| 88 | typedef typename allocator_type::pointer pointer; |
| 89 | typedef typename allocator_type::const_pointer const_pointer; |
| 90 | typedef implementation-defined iterator; |
| 91 | typedef implementation-defined const_iterator; |
| 92 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 93 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 94 | |
| 95 | static const size_type npos = -1; |
| 96 | |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 97 | basic_string() |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 98 | noexcept(is_nothrow_default_constructible<allocator_type>::value); // constexpr since C++20 |
| 99 | explicit basic_string(const allocator_type& a); // constexpr since C++20 |
| 100 | basic_string(const basic_string& str); // constexpr since C++20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 101 | basic_string(basic_string&& str) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 102 | noexcept(is_nothrow_move_constructible<allocator_type>::value); // constexpr since C++20 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 103 | basic_string(const basic_string& str, size_type pos, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 104 | const allocator_type& a = allocator_type()); // constexpr since C++20 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 105 | basic_string(const basic_string& str, size_type pos, size_type n, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 106 | const Allocator& a = Allocator()); // constexpr since C++20 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 107 | template<class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 108 | 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] | 109 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 110 | explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17, constexpr since C++20 |
| 111 | basic_string(const value_type* s, const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 112 | 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] | 113 | basic_string(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 114 | 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] | 115 | template<class InputIterator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 116 | basic_string(InputIterator begin, InputIterator end, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 117 | const allocator_type& a = allocator_type()); // constexpr since C++20 |
| 118 | basic_string(initializer_list<value_type>, const Allocator& = Allocator()); // constexpr since C++20 |
| 119 | basic_string(const basic_string&, const Allocator&); // constexpr since C++20 |
| 120 | basic_string(basic_string&&, const Allocator&); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 121 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 122 | ~basic_string(); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 124 | operator basic_string_view<charT, traits>() const noexcept; // constexpr since C++20 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 125 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 126 | basic_string& operator=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 127 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 128 | basic_string& operator=(const T& t); // C++17, constexpr since C++20 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 129 | basic_string& operator=(basic_string&& str) |
| 130 | noexcept( |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 131 | allocator_type::propagate_on_container_move_assignment::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 132 | allocator_type::is_always_equal::value ); // C++17, constexpr since C++20 |
| 133 | basic_string& operator=(const value_type* s); // constexpr since C++20 |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 134 | basic_string& operator=(nullptr_t) = delete; // C++2b |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 135 | basic_string& operator=(value_type c); // constexpr since C++20 |
| 136 | basic_string& operator=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 137 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 138 | iterator begin() noexcept; // constexpr since C++20 |
| 139 | const_iterator begin() const noexcept; // constexpr since C++20 |
| 140 | iterator end() noexcept; // constexpr since C++20 |
| 141 | const_iterator end() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 142 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 143 | reverse_iterator rbegin() noexcept; // constexpr since C++20 |
| 144 | const_reverse_iterator rbegin() const noexcept; // constexpr since C++20 |
| 145 | reverse_iterator rend() noexcept; // constexpr since C++20 |
| 146 | const_reverse_iterator rend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 147 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 148 | const_iterator cbegin() const noexcept; // constexpr since C++20 |
| 149 | const_iterator cend() const noexcept; // constexpr since C++20 |
| 150 | const_reverse_iterator crbegin() const noexcept; // constexpr since C++20 |
| 151 | const_reverse_iterator crend() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 152 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 153 | size_type size() const noexcept; // constexpr since C++20 |
| 154 | size_type length() const noexcept; // constexpr since C++20 |
| 155 | size_type max_size() const noexcept; // constexpr since C++20 |
| 156 | size_type capacity() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 157 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 158 | void resize(size_type n, value_type c); // constexpr since C++20 |
| 159 | void resize(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 160 | |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 161 | template<class Operation> |
| 162 | constexpr void resize_and_overwrite(size_type n, Operation op); // since C++23 |
| 163 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 164 | void reserve(size_type res_arg); // constexpr since C++20 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 165 | void reserve(); // deprecated in C++20 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 166 | void shrink_to_fit(); // constexpr since C++20 |
| 167 | void clear() noexcept; // constexpr since C++20 |
| 168 | bool empty() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 169 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 170 | const_reference operator[](size_type pos) const; // constexpr since C++20 |
| 171 | reference operator[](size_type pos); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 172 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 173 | const_reference at(size_type n) const; // constexpr since C++20 |
| 174 | reference at(size_type n); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 176 | basic_string& operator+=(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 177 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 178 | basic_string& operator+=(const T& t); // C++17, constexpr since C++20 |
| 179 | basic_string& operator+=(const value_type* s); // constexpr since C++20 |
| 180 | basic_string& operator+=(value_type c); // constexpr since C++20 |
| 181 | basic_string& operator+=(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 182 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 183 | basic_string& append(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 184 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 185 | basic_string& append(const T& t); // C++17, constexpr since C++20 |
| 186 | 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] | 187 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 188 | basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 189 | basic_string& append(const value_type* s, size_type n); // constexpr since C++20 |
| 190 | basic_string& append(const value_type* s); // constexpr since C++20 |
| 191 | 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] | 192 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 193 | basic_string& append(InputIterator first, InputIterator last); // constexpr since C++20 |
| 194 | basic_string& append(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 195 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 196 | void push_back(value_type c); // constexpr since C++20 |
| 197 | void pop_back(); // constexpr since C++20 |
| 198 | reference front(); // constexpr since C++20 |
| 199 | const_reference front() const; // constexpr since C++20 |
| 200 | reference back(); // constexpr since C++20 |
| 201 | const_reference back() const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 202 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 203 | basic_string& assign(const basic_string& str); // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 204 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 205 | basic_string& assign(const T& t); // C++17, constexpr since C++20 |
| 206 | basic_string& assign(basic_string&& str); // constexpr since C++20 |
| 207 | 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] | 208 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 209 | basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17, constexpr since C++20 |
| 210 | basic_string& assign(const value_type* s, size_type n); // constexpr since C++20 |
| 211 | basic_string& assign(const value_type* s); // constexpr since C++20 |
| 212 | 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] | 213 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 214 | basic_string& assign(InputIterator first, InputIterator last); // constexpr since C++20 |
| 215 | basic_string& assign(initializer_list<value_type>); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 216 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 217 | 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] | 218 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 219 | 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] | 220 | basic_string& insert(size_type pos1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 221 | size_type pos2, size_type n); // constexpr since C++20 |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 222 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 223 | basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 224 | basic_string& insert(size_type pos, const value_type* s, size_type n=npos); // C++14, constexpr since C++20 |
| 225 | basic_string& insert(size_type pos, const value_type* s); // constexpr since C++20 |
| 226 | basic_string& insert(size_type pos, size_type n, value_type c); // constexpr since C++20 |
| 227 | iterator insert(const_iterator p, value_type c); // constexpr since C++20 |
| 228 | 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] | 229 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 230 | iterator insert(const_iterator p, InputIterator first, InputIterator last); // constexpr since C++20 |
| 231 | 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] | 232 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 233 | basic_string& erase(size_type pos = 0, size_type n = npos); // constexpr since C++20 |
| 234 | iterator erase(const_iterator position); // constexpr since C++20 |
| 235 | iterator erase(const_iterator first, const_iterator last); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 236 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 237 | 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] | 238 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 239 | 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] | 240 | 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^] | 241 | 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] | 242 | template <class T> |
| 243 | basic_string& replace(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 244 | size_type pos2, size_type n); // C++17, constexpr since C++20 |
| 245 | basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2); // constexpr since C++20 |
| 246 | basic_string& replace(size_type pos, size_type n1, const value_type* s); // constexpr since C++20 |
| 247 | basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c); // constexpr since C++20 |
| 248 | 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] | 249 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 250 | basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17, constexpr since C++20 |
| 251 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n); // constexpr since C++20 |
| 252 | basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s); // constexpr since C++20 |
| 253 | 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] | 254 | template<class InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 255 | basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2); // constexpr since C++20 |
| 256 | 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] | 257 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 258 | size_type copy(value_type* s, size_type n, size_type pos = 0) const; // constexpr since C++20 |
| 259 | basic_string substr(size_type pos = 0, size_type n = npos) const; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 260 | |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 261 | void swap(basic_string& str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 262 | noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value || |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 263 | 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] | 264 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 265 | const value_type* c_str() const noexcept; // constexpr since C++20 |
| 266 | const value_type* data() const noexcept; // constexpr since C++20 |
| 267 | value_type* data() noexcept; // C++17, constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 269 | allocator_type get_allocator() const noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 271 | 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] | 272 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 273 | size_type find(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 274 | size_type find(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 275 | size_type find(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 276 | 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] | 277 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 278 | 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] | 279 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 280 | size_type rfind(const T& t, size_type pos = npos) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 281 | size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 282 | size_type rfind(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 283 | 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] | 284 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 285 | 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] | 286 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 287 | size_type find_first_of(const T& t, size_type pos = 0) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 288 | size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 289 | size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 290 | 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] | 291 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 292 | 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] | 293 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 294 | 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 |
| 295 | size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 296 | size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 297 | 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] | 298 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 299 | 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] | 300 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 301 | 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 |
| 302 | size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 303 | size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept; // constexpr since C++20 |
| 304 | 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] | 305 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 306 | 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] | 307 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 308 | 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 |
| 309 | size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept; // constexpr since C++20 |
| 310 | size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept; // constexpr since C++20 |
| 311 | 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] | 312 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 313 | int compare(const basic_string& str) const noexcept; // constexpr since C++20 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 314 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 315 | int compare(const T& t) const noexcept; // C++17, noexcept as an extension, constexpr since C++20 |
| 316 | 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] | 317 | template <class T> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 318 | 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] | 319 | int compare(size_type pos1, size_type n1, const basic_string& str, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 320 | 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] | 321 | template <class T> |
| 322 | int compare(size_type pos1, size_type n1, const T& t, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 323 | size_type pos2, size_type n2=npos) const; // C++17, constexpr since C++20 |
| 324 | int compare(const value_type* s) const noexcept; // constexpr since C++20 |
| 325 | int compare(size_type pos1, size_type n1, const value_type* s) const; // constexpr since C++20 |
| 326 | 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] | 327 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 328 | constexpr bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 329 | constexpr bool starts_with(charT c) const noexcept; // C++20 |
| 330 | constexpr bool starts_with(const charT* s) const; // C++20 |
| 331 | constexpr bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++20 |
| 332 | constexpr bool ends_with(charT c) const noexcept; // C++20 |
| 333 | constexpr bool ends_with(const charT* s) const; // C++20 |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 334 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 335 | constexpr bool contains(basic_string_view<charT, traits> sv) const noexcept; // C++2b |
| 336 | constexpr bool contains(charT c) const noexcept; // C++2b |
| 337 | constexpr bool contains(const charT* s) const; // C++2b |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 338 | }; |
| 339 | |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 340 | template<class InputIterator, |
| 341 | class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> |
| 342 | basic_string(InputIterator, InputIterator, Allocator = Allocator()) |
| 343 | -> basic_string<typename iterator_traits<InputIterator>::value_type, |
| 344 | char_traits<typename iterator_traits<InputIterator>::value_type>, |
| 345 | Allocator>; // C++17 |
| 346 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | template<class charT, class traits, class Allocator> |
| 348 | basic_string<charT, traits, Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 349 | operator+(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 350 | const basic_string<charT, traits, Allocator>& rhs); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 351 | |
| 352 | template<class charT, class traits, class Allocator> |
| 353 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 354 | 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] | 355 | |
| 356 | template<class charT, class traits, class Allocator> |
| 357 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 358 | 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] | 359 | |
| 360 | template<class charT, class traits, class Allocator> |
| 361 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 362 | 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] | 363 | |
| 364 | template<class charT, class traits, class Allocator> |
| 365 | basic_string<charT, traits, Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 366 | 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] | 367 | |
| 368 | template<class charT, class traits, class Allocator> |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 369 | bool operator==(const basic_string<charT, traits, Allocator>& lhs, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 370 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | |
| 372 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 373 | bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | |
| 375 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 376 | 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] | 377 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 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> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 383 | bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since 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 | |
| 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, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 390 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 391 | |
| 392 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 393 | 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] | 394 | |
| 395 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 396 | bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since 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, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 400 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | |
| 402 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 403 | 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] | 404 | |
| 405 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 406 | bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since 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, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 410 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 411 | |
| 412 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 413 | 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] | 414 | |
| 415 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 416 | bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since 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, |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 420 | const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 421 | |
| 422 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 423 | 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] | 424 | |
| 425 | template<class charT, class traits, class Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 426 | bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept; // constexpr since 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 | void swap(basic_string<charT, traits, Allocator>& lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 430 | basic_string<charT, traits, Allocator>& rhs) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 431 | noexcept(noexcept(lhs.swap(rhs))); // constexpr since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 432 | |
| 433 | template<class charT, class traits, class Allocator> |
| 434 | basic_istream<charT, traits>& |
| 435 | operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 436 | |
| 437 | template<class charT, class traits, class Allocator> |
| 438 | basic_ostream<charT, traits>& |
| 439 | operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str); |
| 440 | |
| 441 | template<class charT, class traits, class Allocator> |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 442 | basic_istream<charT, traits>& |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 443 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str, |
| 444 | charT delim); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | |
| 446 | template<class charT, class traits, class Allocator> |
| 447 | basic_istream<charT, traits>& |
| 448 | getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str); |
| 449 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 450 | template<class charT, class traits, class Allocator, class U> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 451 | typename basic_string<charT, traits, Allocator>::size_type |
| 452 | erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 453 | template<class charT, class traits, class Allocator, class Predicate> |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 454 | typename basic_string<charT, traits, Allocator>::size_type |
| 455 | erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20 |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 456 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 457 | typedef basic_string<char> string; |
| 458 | typedef basic_string<wchar_t> wstring; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 459 | typedef basic_string<char8_t> u8string; // C++20 |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 460 | typedef basic_string<char16_t> u16string; |
| 461 | typedef basic_string<char32_t> u32string; |
| 462 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 463 | int stoi (const string& str, size_t* idx = nullptr, int base = 10); |
| 464 | long stol (const string& str, size_t* idx = nullptr, int base = 10); |
| 465 | unsigned long stoul (const string& str, size_t* idx = nullptr, int base = 10); |
| 466 | long long stoll (const string& str, size_t* idx = nullptr, int base = 10); |
| 467 | 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] | 468 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 469 | float stof (const string& str, size_t* idx = nullptr); |
| 470 | double stod (const string& str, size_t* idx = nullptr); |
| 471 | long double stold(const string& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 472 | |
| 473 | string to_string(int val); |
| 474 | string to_string(unsigned val); |
| 475 | string to_string(long val); |
| 476 | string to_string(unsigned long val); |
| 477 | string to_string(long long val); |
| 478 | string to_string(unsigned long long val); |
| 479 | string to_string(float val); |
| 480 | string to_string(double val); |
| 481 | string to_string(long double val); |
| 482 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 483 | int stoi (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 484 | long stol (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 485 | unsigned long stoul (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 486 | long long stoll (const wstring& str, size_t* idx = nullptr, int base = 10); |
| 487 | 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] | 488 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 489 | float stof (const wstring& str, size_t* idx = nullptr); |
| 490 | double stod (const wstring& str, size_t* idx = nullptr); |
| 491 | long double stold(const wstring& str, size_t* idx = nullptr); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 492 | |
| 493 | wstring to_wstring(int val); |
| 494 | wstring to_wstring(unsigned val); |
| 495 | wstring to_wstring(long val); |
| 496 | wstring to_wstring(unsigned long val); |
| 497 | wstring to_wstring(long long val); |
| 498 | wstring to_wstring(unsigned long long val); |
| 499 | wstring to_wstring(float val); |
| 500 | wstring to_wstring(double val); |
| 501 | wstring to_wstring(long double val); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 502 | |
| 503 | template <> struct hash<string>; |
Marek Kurdej | e3ac4e2 | 2021-03-23 17:15:07 +0100 | [diff] [blame] | 504 | template <> struct hash<u8string>; // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | template <> struct hash<u16string>; |
| 506 | template <> struct hash<u32string>; |
| 507 | template <> struct hash<wstring>; |
| 508 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 509 | basic_string<char> operator "" s( const char *str, size_t len ); // C++14, constexpr since C++20 |
| 510 | basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14, constexpr since C++20 |
| 511 | constexpr basic_string<char8_t> operator "" s( const char8_t *str, size_t len ); // C++20 |
| 512 | basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14, constexpr since C++20 |
| 513 | 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] | 514 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 515 | } // std |
| 516 | |
| 517 | */ |
| 518 | |
Nikolas Klauser | f210d8a | 2022-02-15 18:18:08 +0100 | [diff] [blame] | 519 | #include <__algorithm/max.h> |
| 520 | #include <__algorithm/min.h> |
| 521 | #include <__algorithm/remove.h> |
| 522 | #include <__algorithm/remove_if.h> |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 523 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 524 | #include <__config> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 525 | #include <__debug> |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 526 | #include <__format/enable_insertable.h> |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 527 | #include <__ios/fpos.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 528 | #include <__iterator/wrap_iter.h> |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 529 | #include <__memory/allocate_at_least.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 530 | #include <__utility/auto_cast.h> |
| 531 | #include <__utility/move.h> |
| 532 | #include <__utility/swap.h> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 533 | #include <__utility/unreachable.h> |
| 534 | #include <climits> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 535 | #include <compare> |
| 536 | #include <cstdio> // EOF |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 537 | #include <cstdlib> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 538 | #include <cstring> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 539 | #include <initializer_list> |
| 540 | #include <iosfwd> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 541 | #include <iterator> |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 542 | #include <limits> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 543 | #include <memory> |
| 544 | #include <stdexcept> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 545 | #include <string_view> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 546 | #include <type_traits> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 547 | #include <version> |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 548 | |
Nikolas Klauser | 4c1bf59 | 2022-02-11 19:15:18 +0100 | [diff] [blame] | 549 | // TODO: remove these headers |
| 550 | #include <__functional/binary_function.h> |
| 551 | #include <__functional/invoke.h> |
| 552 | #include <__functional/operations.h> |
| 553 | #include <__functional/reference_wrapper.h> |
| 554 | #include <__functional/unary_function.h> |
| 555 | #include <__functional/weak_result_type.h> |
| 556 | #include <new> |
| 557 | #include <typeinfo> |
| 558 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 559 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 560 | # include <cwchar> |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 561 | #endif |
| 562 | |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 563 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
Nikolas Klauser | 8084027 | 2022-02-04 13:04:33 +0100 | [diff] [blame] | 564 | # include <cstdint> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 565 | #endif |
Eric Fiselier | 14b6de9 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 566 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 567 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 568 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 569 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 570 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 571 | _LIBCPP_PUSH_MACROS |
| 572 | #include <__undef_macros> |
| 573 | |
| 574 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 576 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 577 | // basic_string |
| 578 | |
| 579 | template<class _CharT, class _Traits, class _Allocator> |
| 580 | basic_string<_CharT, _Traits, _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 581 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 582 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, |
| 583 | const basic_string<_CharT, _Traits, _Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 584 | |
| 585 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 586 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 587 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 588 | operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 589 | |
| 590 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 591 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 592 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 593 | operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | |
| 595 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 596 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 597 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 598 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 599 | |
| 600 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 601 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | basic_string<_CharT, _Traits, _Allocator> |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 603 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | |
Shoaib Meenai | ea36371 | 2017-07-29 02:54:41 +0000 | [diff] [blame] | 605 | _LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&)) |
| 606 | |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 607 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 608 | struct __string_is_trivial_iterator : public false_type {}; |
| 609 | |
| 610 | template <class _Tp> |
| 611 | struct __string_is_trivial_iterator<_Tp*> |
| 612 | : public is_arithmetic<_Tp> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 613 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 614 | template <class _Iter> |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 615 | struct __string_is_trivial_iterator<__wrap_iter<_Iter> > |
| 616 | : public __string_is_trivial_iterator<_Iter> {}; |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 617 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 618 | template <class _CharT, class _Traits, class _Tp> |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 619 | struct __can_be_converted_to_string_view : public _BoolConstant< |
| 620 | is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value && |
| 621 | !is_convertible<const _Tp&, const _CharT*>::value |
| 622 | > {}; |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 623 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 624 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 625 | typedef basic_string<char8_t> u8string; |
| 626 | #endif |
| 627 | |
| 628 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 629 | typedef basic_string<char16_t> u16string; |
| 630 | typedef basic_string<char32_t> u32string; |
Louis Dionne | 96fc5f5 | 2021-09-09 11:25:10 -0400 | [diff] [blame] | 631 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 632 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 633 | struct __uninitialized_size_tag {}; |
| 634 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 635 | template<class _CharT, class _Traits, class _Allocator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 636 | class |
| 637 | _LIBCPP_TEMPLATE_VIS |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 638 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 639 | _LIBCPP_PREFERRED_NAME(u8string) |
| 640 | #endif |
| 641 | #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS |
| 642 | _LIBCPP_PREFERRED_NAME(u16string) |
| 643 | _LIBCPP_PREFERRED_NAME(u32string) |
| 644 | #endif |
| 645 | basic_string |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 646 | { |
| 647 | public: |
| 648 | typedef basic_string __self; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 649 | typedef basic_string_view<_CharT, _Traits> __self_view; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 650 | typedef _Traits traits_type; |
Marshall Clow | a3a74e0 | 2017-03-15 18:41:11 +0000 | [diff] [blame] | 651 | typedef _CharT value_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 652 | typedef _Allocator allocator_type; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 653 | typedef allocator_traits<allocator_type> __alloc_traits; |
| 654 | typedef typename __alloc_traits::size_type size_type; |
| 655 | typedef typename __alloc_traits::difference_type difference_type; |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 656 | typedef value_type& reference; |
| 657 | typedef const value_type& const_reference; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 658 | typedef typename __alloc_traits::pointer pointer; |
| 659 | typedef typename __alloc_traits::const_pointer const_pointer; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 660 | |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 661 | static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array"); |
| 662 | static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout"); |
| 663 | static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial"); |
| 664 | static_assert(( is_same<_CharT, typename traits_type::char_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 665 | "traits_type::char_type must be the same type as CharT"); |
Marshall Clow | 79f3354 | 2018-03-21 00:36:05 +0000 | [diff] [blame] | 666 | static_assert(( is_same<typename allocator_type::value_type, value_type>::value), |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 667 | "Allocator::value_type must be same type as value_type"); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 668 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 669 | typedef __wrap_iter<pointer> iterator; |
| 670 | typedef __wrap_iter<const_pointer> const_iterator; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 671 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 672 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 673 | |
| 674 | private: |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 675 | |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 676 | #ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 677 | |
| 678 | struct __long |
| 679 | { |
| 680 | pointer __data_; |
| 681 | size_type __size_; |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 682 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
| 683 | size_type __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 684 | }; |
| 685 | |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 686 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 687 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 688 | |
| 689 | struct __short |
| 690 | { |
| 691 | value_type __data_[__min_cap]; |
Azat Khuzhin | 1995f72 | 2022-04-08 16:13:46 -0400 | [diff] [blame] | 692 | unsigned char __padding[sizeof(value_type) - 1]; |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 693 | unsigned char __size_ : 7; |
| 694 | unsigned char __is_long_ : 1; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 695 | }; |
| 696 | |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 697 | // The __endian_factor is required because the field we use to store the size |
| 698 | // (either size_type or unsigned char depending on long/short) has one fewer |
| 699 | // bit than it would if it were not a bitfield. |
| 700 | // |
| 701 | // If the LSB is used to store the short-flag in the short string representation, |
| 702 | // we have to multiply the size by two when it is stored and divide it by two when |
| 703 | // it is loaded to make sure that we always store an even number. In the long string |
| 704 | // representation, we can ignore this because we can assume that we always allocate |
| 705 | // an even amount of value_types. |
| 706 | // |
| 707 | // If the MSB is used for the short-flag, the max_size() is numeric_limits<size_type>::max() / 2. |
| 708 | // This does not impact the short string representation, since we never need the MSB |
| 709 | // for representing the size of a short string anyway. |
| 710 | |
| 711 | #ifdef _LIBCPP_BIG_ENDIAN |
| 712 | static const size_type __endian_factor = 2; |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 713 | #else |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 714 | static const size_type __endian_factor = 1; |
| 715 | #endif |
| 716 | |
| 717 | #else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
| 718 | |
| 719 | #ifdef _LIBCPP_BIG_ENDIAN |
| 720 | static const size_type __endian_factor = 1; |
| 721 | #else |
| 722 | static const size_type __endian_factor = 2; |
| 723 | #endif |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 724 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 725 | struct __long |
| 726 | { |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 727 | size_type __is_long_ : 1; |
| 728 | size_type __cap_ : sizeof(size_type) * CHAR_BIT - 1; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 729 | size_type __size_; |
| 730 | pointer __data_; |
| 731 | }; |
| 732 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 733 | enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ? |
| 734 | (sizeof(__long) - 1)/sizeof(value_type) : 2}; |
| 735 | |
| 736 | struct __short |
| 737 | { |
| 738 | union |
| 739 | { |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 740 | struct { |
| 741 | unsigned char __is_long_ : 1; |
| 742 | unsigned char __size_ : 7; |
| 743 | }; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 744 | value_type __lx; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 745 | }; |
| 746 | value_type __data_[__min_cap]; |
| 747 | }; |
| 748 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 749 | #endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 750 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 751 | union __ulx{__long __lx; __short __lxx;}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 752 | |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 753 | enum {__n_words = sizeof(__ulx) / sizeof(size_type)}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 754 | |
| 755 | struct __raw |
| 756 | { |
| 757 | size_type __words[__n_words]; |
| 758 | }; |
| 759 | |
| 760 | struct __rep |
| 761 | { |
| 762 | union |
| 763 | { |
| 764 | __long __l; |
| 765 | __short __s; |
| 766 | __raw __r; |
| 767 | }; |
| 768 | }; |
| 769 | |
| 770 | __compressed_pair<__rep, allocator_type> __r_; |
| 771 | |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 772 | // Construct a string with the given allocator and enough storage to hold `__size` characters, but |
| 773 | // don't initialize the characters. The contents of the string, including the null terminator, must be |
| 774 | // initialized separately. |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 775 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 776 | 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] | 777 | : __r_(__default_init_tag(), __a) { |
| 778 | if (__size > max_size()) |
| 779 | __throw_length_error(); |
| 780 | if (__fits_in_sso(__size)) { |
| 781 | __zero(); |
| 782 | __set_short_size(__size); |
| 783 | } else { |
| 784 | auto __capacity = __recommend(__size) + 1; |
| 785 | auto __allocation = __alloc_traits::allocate(__alloc(), __capacity); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 786 | __begin_lifetime(__allocation, __capacity); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 787 | __set_long_cap(__capacity); |
| 788 | __set_long_pointer(__allocation); |
| 789 | __set_long_size(__size); |
| 790 | } |
| 791 | std::__debug_db_insert_c(this); |
| 792 | } |
| 793 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 794 | public: |
Martin Storsjö | 88890c2 | 2021-02-22 01:13:13 +0200 | [diff] [blame] | 795 | _LIBCPP_TEMPLATE_DATA_VIS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 796 | static const size_type npos = -1; |
| 797 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 798 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string() |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 799 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 800 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 801 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit basic_string(const allocator_type& __a) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 802 | #if _LIBCPP_STD_VER <= 14 |
| 803 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value); |
| 804 | #else |
| 805 | _NOEXCEPT; |
| 806 | #endif |
| 807 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 808 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str); |
| 809 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str, const allocator_type& __a); |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 810 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 811 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 812 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 813 | basic_string(basic_string&& __str) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 814 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 815 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 816 | #else |
| 817 | _NOEXCEPT; |
| 818 | #endif |
| 819 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 820 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 821 | basic_string(basic_string&& __str, const allocator_type& __a); |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 822 | #endif // _LIBCPP_CXX03_LANG |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 823 | |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 824 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 825 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 826 | basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) { |
Eric Fiselier | a856786 | 2018-07-17 05:48:48 +0000 | [diff] [blame] | 827 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); |
| 828 | __init(__s, traits_type::length(__s)); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 829 | _VSTD::__debug_db_insert_c(this); |
Eric Fiselier | a856786 | 2018-07-17 05:48:48 +0000 | [diff] [blame] | 830 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 831 | |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 832 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 833 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 834 | basic_string(const _CharT* __s, const _Allocator& __a); |
| 835 | |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 836 | #if _LIBCPP_STD_VER > 20 |
| 837 | basic_string(nullptr_t) = delete; |
| 838 | #endif |
| 839 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 840 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 841 | basic_string(const _CharT* __s, size_type __n); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 842 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 843 | basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 844 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 845 | basic_string(size_type __n, _CharT __c); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 846 | |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 847 | template <class = __enable_if_t<__is_allocator<_Allocator>::value, nullptr_t> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 848 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 849 | basic_string(size_type __n, _CharT __c, const _Allocator& __a); |
| 850 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 851 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 852 | basic_string(const basic_string& __str, size_type __pos, size_type __n, |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 853 | const _Allocator& __a = _Allocator()); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 854 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 855 | basic_string(const basic_string& __str, size_type __pos, |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 856 | const _Allocator& __a = _Allocator()); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 857 | |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 858 | template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 859 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 860 | basic_string(const _Tp& __t, size_type __pos, size_type __n, |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 861 | const allocator_type& __a = allocator_type()); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 862 | |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 863 | template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 864 | !__is_same_uncvref<_Tp, basic_string>::value> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 865 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 866 | explicit basic_string(const _Tp& __t); |
| 867 | |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 868 | template<class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && !__is_same_uncvref<_Tp, basic_string>::value> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 869 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 870 | explicit basic_string(const _Tp& __t, const allocator_type& __a); |
| 871 | |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 872 | template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 873 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 874 | basic_string(_InputIterator __first, _InputIterator __last); |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 875 | template<class _InputIterator, class = __enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value> > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 876 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 877 | basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 878 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 879 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 880 | basic_string(initializer_list<_CharT> __il); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 881 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 882 | basic_string(initializer_list<_CharT> __il, const _Allocator& __a); |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 883 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 885 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 ~basic_string(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 886 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 887 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 888 | operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } |
| 889 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 890 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const basic_string& __str); |
Eric Fiselier | 5ec13b1 | 2017-01-23 21:24:58 +0000 | [diff] [blame] | 891 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 892 | template <class _Tp, class = __enable_if_t<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value && |
| 893 | !__is_same_uncvref<_Tp, basic_string>::value> > |
| 894 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const _Tp& __t) { |
| 895 | __self_view __sv = __t; |
| 896 | return assign(__sv); |
| 897 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 898 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 899 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 900 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 901 | basic_string& operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 902 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 903 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 904 | 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] | 905 | #endif |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 906 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 907 | basic_string& operator=(const value_type* __s) {return assign(__s);} |
Marek Kurdej | 90d7971 | 2021-07-27 16:16:21 +0200 | [diff] [blame] | 908 | #if _LIBCPP_STD_VER > 20 |
| 909 | basic_string& operator=(nullptr_t) = delete; |
| 910 | #endif |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 911 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 912 | |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 913 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 914 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 915 | iterator begin() _NOEXCEPT |
| 916 | {return iterator(this, __get_pointer());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 917 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 918 | const_iterator begin() const _NOEXCEPT |
| 919 | {return const_iterator(this, __get_pointer());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 920 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 921 | iterator end() _NOEXCEPT |
| 922 | {return iterator(this, __get_pointer() + size());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 923 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 924 | const_iterator end() const _NOEXCEPT |
| 925 | {return const_iterator(this, __get_pointer() + size());} |
| 926 | #else |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 927 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 928 | iterator begin() _NOEXCEPT |
| 929 | {return iterator(__get_pointer());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 930 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 931 | const_iterator begin() const _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 932 | {return const_iterator(__get_pointer());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 933 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 934 | iterator end() _NOEXCEPT |
| 935 | {return iterator(__get_pointer() + size());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 936 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 937 | const_iterator end() const _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 938 | {return const_iterator(__get_pointer() + size());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 939 | #endif // _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 940 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 941 | reverse_iterator rbegin() _NOEXCEPT |
| 942 | {return reverse_iterator(end());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 943 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 944 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 945 | {return const_reverse_iterator(end());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 946 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 947 | reverse_iterator rend() _NOEXCEPT |
| 948 | {return reverse_iterator(begin());} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 949 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 950 | const_reverse_iterator rend() const _NOEXCEPT |
| 951 | {return const_reverse_iterator(begin());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 952 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 953 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 954 | const_iterator cbegin() const _NOEXCEPT |
| 955 | {return begin();} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 956 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 957 | const_iterator cend() const _NOEXCEPT |
| 958 | {return end();} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 959 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 960 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 961 | {return rbegin();} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 962 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 963 | const_reverse_iterator crend() const _NOEXCEPT |
| 964 | {return rend();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 965 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 966 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 967 | {return __is_long() ? __get_long_size() : __get_short_size();} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 968 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type length() const _NOEXCEPT {return size();} |
| 969 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type max_size() const _NOEXCEPT; |
| 970 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type capacity() const _NOEXCEPT { |
| 971 | return (__is_long() ? __get_long_cap() : static_cast<size_type>(__min_cap)) - 1; |
| 972 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 973 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 974 | _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n, value_type __c); |
| 975 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void resize(size_type __n) { resize(__n, value_type()); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 977 | _LIBCPP_CONSTEXPR_AFTER_CXX17 void reserve(size_type __requested_capacity); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 978 | |
| 979 | #if _LIBCPP_STD_VER > 20 |
| 980 | template <class _Op> |
| 981 | _LIBCPP_HIDE_FROM_ABI constexpr |
| 982 | void resize_and_overwrite(size_type __n, _Op __op) { |
| 983 | __resize_default_init(__n); |
Nikolas Klauser | a4a76a1 | 2022-01-20 13:53:59 +0100 | [diff] [blame] | 984 | __erase_to_end(_VSTD::move(__op)(data(), _LIBCPP_AUTO_CAST(__n))); |
Nikolas Klauser | 9e6040c | 2022-01-06 21:43:26 +0100 | [diff] [blame] | 985 | } |
| 986 | #endif |
| 987 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 988 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __resize_default_init(size_type __n); |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 989 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 990 | _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_INLINE_VISIBILITY void reserve() _NOEXCEPT { shrink_to_fit(); } |
| 991 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void shrink_to_fit() _NOEXCEPT; |
| 992 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void clear() _NOEXCEPT; |
| 993 | |
| 994 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 995 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 996 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 997 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 998 | const_reference operator[](size_type __pos) const _NOEXCEPT; |
| 999 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference operator[](size_type __pos) _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1000 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1001 | _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference at(size_type __n) const; |
| 1002 | _LIBCPP_CONSTEXPR_AFTER_CXX17 reference at(size_type __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1003 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1004 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const basic_string& __str) { |
| 1005 | return append(__str); |
| 1006 | } |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1007 | |
| 1008 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1009 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1010 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1011 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1012 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1013 | && !__is_same_uncvref<_Tp, basic_string >::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1014 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1015 | > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1016 | operator+=(const _Tp& __t) { |
| 1017 | __self_view __sv = __t; return append(__sv); |
| 1018 | } |
| 1019 | |
| 1020 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(const value_type* __s) { |
| 1021 | return append(__s); |
| 1022 | } |
| 1023 | |
| 1024 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator+=(value_type __c) { |
| 1025 | push_back(__c); |
| 1026 | return *this; |
| 1027 | } |
| 1028 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1029 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1030 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1031 | basic_string& operator+=(initializer_list<value_type> __il) { return append(__il); } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1032 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1033 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1034 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1035 | basic_string& append(const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1036 | |
| 1037 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1038 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1039 | __enable_if_t< |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1040 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1041 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1042 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1043 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1044 | append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1045 | _LIBCPP_CONSTEXPR_AFTER_CXX17 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] | 1046 | |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 1047 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1048 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1049 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1050 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1051 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1052 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1053 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1054 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1055 | append(const _Tp& __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1056 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s, size_type __n); |
| 1057 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(const value_type* __s); |
| 1058 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& append(size_type __n, value_type __c); |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1059 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1060 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 1061 | void __append_default_init(size_type __n); |
| 1062 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1063 | template<class _InputIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1064 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1065 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1067 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1068 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1069 | > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1070 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1071 | append(_InputIterator __first, _InputIterator __last) { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1072 | const basic_string __temp(__first, __last, __alloc()); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1073 | append(__temp.data(), __temp.size()); |
| 1074 | return *this; |
| 1075 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1076 | template<class _ForwardIterator> |
Shoaib Meenai | 69c5741 | 2017-03-02 03:02:50 +0000 | [diff] [blame] | 1077 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1078 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1079 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1080 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1081 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1082 | > |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1083 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1084 | append(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 1085 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1086 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1087 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1088 | 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] | 1089 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1090 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1091 | _LIBCPP_CONSTEXPR_AFTER_CXX17 void push_back(value_type __c); |
| 1092 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void pop_back(); |
| 1093 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference front() _NOEXCEPT; |
| 1094 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference front() const _NOEXCEPT; |
| 1095 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 reference back() _NOEXCEPT; |
| 1096 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 const_reference back() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1097 | |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1098 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1099 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1100 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1101 | < |
| 1102 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1103 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1104 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1105 | assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1106 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 95d5e9a | 2016-03-09 18:08:29 +0000 | [diff] [blame] | 1107 | basic_string& assign(const basic_string& __str) { return *this = __str; } |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1108 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1109 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1110 | basic_string& assign(basic_string&& __str) |
Marshall Clow | 5aa9e94 | 2015-10-05 16:17:34 +0000 | [diff] [blame] | 1111 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1112 | {*this = _VSTD::move(__str); return *this;} |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1113 | #endif |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1114 | _LIBCPP_CONSTEXPR_AFTER_CXX17 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] | 1115 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1116 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1117 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1118 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1119 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 1120 | && !__is_same_uncvref<_Tp, basic_string>::value, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1121 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1122 | > |
Eric Fiselier | c5ea1ae | 2017-06-01 02:29:37 +0000 | [diff] [blame] | 1123 | assign(const _Tp & __t, size_type __pos, size_type __n=npos); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1124 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s, size_type __n); |
| 1125 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(const value_type* __s); |
| 1126 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& assign(size_type __n, value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | template<class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1128 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1129 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1130 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1131 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1132 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1133 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1134 | assign(_InputIterator __first, _InputIterator __last); |
| 1135 | template<class _ForwardIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1136 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1137 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1138 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1139 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1140 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1141 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1142 | assign(_ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1143 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1144 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1145 | 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] | 1146 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1147 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1148 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1149 | basic_string& insert(size_type __pos1, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1150 | |
| 1151 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1152 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1153 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1154 | < |
| 1155 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1156 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1157 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1158 | insert(size_type __pos1, const _Tp& __t) |
| 1159 | { __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); } |
| 1160 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1161 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1162 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1163 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1164 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1165 | __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] | 1166 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1167 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1168 | insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1169 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1170 | basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1171 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s, size_type __n); |
| 1172 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, const value_type* __s); |
| 1173 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& insert(size_type __pos, size_type __n, value_type __c); |
| 1174 | _LIBCPP_CONSTEXPR_AFTER_CXX17 iterator insert(const_iterator __pos, value_type __c); |
| 1175 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1176 | iterator insert(const_iterator __pos, size_type __n, value_type __c); |
| 1177 | template<class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1178 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1179 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1180 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1181 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1182 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1183 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1184 | insert(const_iterator __pos, _InputIterator __first, _InputIterator __last); |
| 1185 | template<class _ForwardIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1186 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1187 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1188 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1189 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1190 | iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1191 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1193 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1194 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | iterator insert(const_iterator __pos, initializer_list<value_type> __il) |
| 1196 | {return insert(__pos, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1197 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1199 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& erase(size_type __pos = 0, size_type __n = npos); |
| 1200 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1201 | iterator erase(const_iterator __pos); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1202 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | iterator erase(const_iterator __first, const_iterator __last); |
| 1204 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1205 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1206 | basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1207 | |
| 1208 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1209 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1210 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1211 | < |
| 1212 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1213 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1214 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1215 | replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1216 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 8db7fb0 | 2014-03-04 19:17:19 +0000 | [diff] [blame] | 1217 | 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] | 1218 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1219 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1220 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1221 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1222 | __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] | 1223 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1224 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1225 | replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1226 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1227 | basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1228 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s); |
| 1229 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c); |
| 1230 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1231 | basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str); |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1232 | |
| 1233 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1234 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1235 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1236 | < |
| 1237 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1238 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1239 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1240 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); } |
| 1241 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1242 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1243 | basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1244 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1245 | basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1246 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1247 | basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1248 | template<class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1249 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1250 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1251 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 1252 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1253 | basic_string& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1254 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1255 | replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2); |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1256 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1257 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 1258 | 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] | 1259 | {return replace(__i1, __i2, __il.begin(), __il.end());} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1260 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1261 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1262 | _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const; |
| 1263 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1264 | basic_string substr(size_type __pos = 0, size_type __n = npos) const; |
| 1265 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1266 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1267 | void swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1268 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1269 | _NOEXCEPT; |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1270 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 1271 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1272 | __is_nothrow_swappable<allocator_type>::value); |
| 1273 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1274 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1275 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1276 | const value_type* c_str() const _NOEXCEPT {return data();} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1277 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1278 | const value_type* data() const _NOEXCEPT {return _VSTD::__to_address(__get_pointer());} |
Eric Fiselier | 4ee2a89 | 2017-11-20 20:23:27 +0000 | [diff] [blame] | 1279 | #if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY) |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1280 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1281 | value_type* data() _NOEXCEPT {return _VSTD::__to_address(__get_pointer());} |
Marshall Clow | d3c2239 | 2016-03-08 15:44:30 +0000 | [diff] [blame] | 1282 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1283 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1284 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1285 | allocator_type get_allocator() const _NOEXCEPT {return __alloc();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1286 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1287 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1288 | 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] | 1289 | |
| 1290 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1291 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1292 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1293 | < |
| 1294 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1295 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1296 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1297 | find(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1298 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1299 | size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1300 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1301 | size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1302 | _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1304 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1305 | 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] | 1306 | |
| 1307 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1308 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1309 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1310 | < |
| 1311 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1312 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1313 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1314 | rfind(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1315 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1316 | size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1317 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1318 | size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1319 | _LIBCPP_CONSTEXPR_AFTER_CXX17 size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1320 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1321 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1322 | 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] | 1323 | |
| 1324 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1325 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1326 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1327 | < |
| 1328 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1329 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1330 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1331 | find_first_of(const _Tp& __t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1332 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1333 | size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1334 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1335 | size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1336 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1337 | 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] | 1338 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1339 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1340 | 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] | 1341 | |
| 1342 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1343 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1344 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1345 | < |
| 1346 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1347 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1348 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1349 | find_last_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1350 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1351 | size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1352 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1353 | size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1354 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1355 | 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] | 1356 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1357 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1358 | 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] | 1359 | |
| 1360 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1361 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1362 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1363 | < |
| 1364 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1365 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1366 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1367 | find_first_not_of(const _Tp &__t, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1368 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1369 | size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1370 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1371 | size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1372 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1373 | size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT; |
| 1374 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1375 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1376 | 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] | 1377 | |
| 1378 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1379 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1380 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1381 | < |
| 1382 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1383 | size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1384 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1385 | find_last_not_of(const _Tp& __t, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1386 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1387 | size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1388 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1389 | size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1390 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1391 | size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT; |
| 1392 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1393 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1394 | int compare(const basic_string& __str) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1395 | |
| 1396 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1397 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1398 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1399 | < |
| 1400 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1401 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1402 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 1403 | compare(const _Tp &__t) const _NOEXCEPT; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1404 | |
| 1405 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1406 | _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1407 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1408 | < |
| 1409 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 1410 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1411 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1412 | compare(size_type __pos1, size_type __n1, const _Tp& __t) const; |
| 1413 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1414 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1415 | int compare(size_type __pos1, size_type __n1, const basic_string& __str) const; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1416 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1417 | int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, |
| 1418 | size_type __n2 = npos) const; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1419 | |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1420 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1421 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1422 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1423 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1424 | __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] | 1425 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1426 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 1427 | compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1428 | _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(const value_type* __s) const _NOEXCEPT; |
| 1429 | _LIBCPP_CONSTEXPR_AFTER_CXX17 int compare(size_type __pos1, size_type __n1, const value_type* __s) const; |
| 1430 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1431 | 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] | 1432 | |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1433 | #if _LIBCPP_STD_VER > 17 |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1434 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1435 | bool starts_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1436 | { return __self_view(data(), size()).starts_with(__sv); } |
| 1437 | |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1438 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1439 | bool starts_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1440 | { return !empty() && _Traits::eq(front(), __c); } |
| 1441 | |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1442 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1443 | bool starts_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1444 | { return starts_with(__self_view(__s)); } |
| 1445 | |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1446 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1447 | bool ends_with(__self_view __sv) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1448 | { return __self_view(data(), size()).ends_with( __sv); } |
| 1449 | |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1450 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1451 | bool ends_with(value_type __c) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1452 | { return !empty() && _Traits::eq(back(), __c); } |
| 1453 | |
Arthur O'Dwyer | a0cb1e8 | 2021-09-28 12:19:35 -0400 | [diff] [blame] | 1454 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1455 | bool ends_with(const value_type* __s) const noexcept |
Marshall Clow | 18c293b | 2017-12-04 20:11:38 +0000 | [diff] [blame] | 1456 | { return ends_with(__self_view(__s)); } |
| 1457 | #endif |
| 1458 | |
Wim Leflere | 023c354 | 2021-01-19 14:33:30 -0500 | [diff] [blame] | 1459 | #if _LIBCPP_STD_VER > 20 |
| 1460 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1461 | bool contains(__self_view __sv) const noexcept |
| 1462 | { return __self_view(data(), size()).contains(__sv); } |
| 1463 | |
| 1464 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1465 | bool contains(value_type __c) const noexcept |
| 1466 | { return __self_view(data(), size()).contains(__c); } |
| 1467 | |
| 1468 | constexpr _LIBCPP_INLINE_VISIBILITY |
| 1469 | bool contains(const value_type* __s) const |
| 1470 | { return __self_view(data(), size()).contains(__s); } |
| 1471 | #endif |
| 1472 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1473 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 bool __invariants() const; |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1474 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1475 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __clear_and_shrink() _NOEXCEPT; |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 1476 | |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1477 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1478 | |
| 1479 | bool __dereferenceable(const const_iterator* __i) const; |
| 1480 | bool __decrementable(const const_iterator* __i) const; |
| 1481 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1482 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1483 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1484 | #endif // _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1485 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1486 | private: |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1487 | template<class _Alloc> |
| 1488 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1489 | bool friend operator==(const basic_string<char, char_traits<char>, _Alloc>& __lhs, |
| 1490 | const basic_string<char, char_traits<char>, _Alloc>& __rhs) _NOEXCEPT; |
| 1491 | |
| 1492 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __shrink_or_extend(size_type __target_capacity); |
| 1493 | |
| 1494 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1495 | bool __is_long() const _NOEXCEPT { |
| 1496 | if (__libcpp_is_constant_evaluated()) |
| 1497 | return true; |
| 1498 | return __r_.first().__s.__is_long_; |
| 1499 | } |
| 1500 | |
| 1501 | static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __begin_lifetime(pointer __begin, size_type __n) { |
| 1502 | #if _LIBCPP_STD_VER > 17 |
| 1503 | if (__libcpp_is_constant_evaluated()) { |
| 1504 | for (size_type __i = 0; __i != __n; ++__i) |
| 1505 | std::construct_at(std::addressof(__begin[__i])); |
| 1506 | } |
| 1507 | #else |
| 1508 | (void)__begin; |
| 1509 | (void)__n; |
| 1510 | #endif // _LIBCPP_STD_VER > 17 |
| 1511 | } |
| 1512 | |
| 1513 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __default_init() { |
| 1514 | __zero(); |
| 1515 | if (__libcpp_is_constant_evaluated()) { |
| 1516 | size_type __sz = __recommend(0) + 1; |
| 1517 | pointer __ptr = __alloc_traits::allocate(__alloc(), __sz); |
| 1518 | __begin_lifetime(__ptr, __sz); |
| 1519 | __set_long_pointer(__ptr); |
| 1520 | __set_long_cap(__sz); |
| 1521 | __set_long_size(0); |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 void __deallocate_constexpr() { |
| 1526 | if (__libcpp_is_constant_evaluated() && __get_pointer() != nullptr) |
| 1527 | __alloc_traits::deallocate(__alloc(), __get_pointer(), __get_long_cap()); |
| 1528 | } |
| 1529 | |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1530 | _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI static bool __fits_in_sso(size_type __sz) { |
| 1531 | // SSO is disabled during constant evaluation because `__is_long` isn't constexpr friendly |
| 1532 | return !__libcpp_is_constant_evaluated() && (__sz < __min_cap); |
| 1533 | } |
| 1534 | |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 1535 | template <class _ForwardIterator> |
| 1536 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 1537 | iterator __insert_from_safe_copy(size_type __n, size_type __ip, _ForwardIterator __first, _ForwardIterator __last) { |
| 1538 | size_type __sz = size(); |
| 1539 | size_type __cap = capacity(); |
| 1540 | value_type* __p; |
| 1541 | if (__cap - __sz >= __n) |
| 1542 | { |
| 1543 | __p = std::__to_address(__get_pointer()); |
| 1544 | size_type __n_move = __sz - __ip; |
| 1545 | if (__n_move != 0) |
| 1546 | traits_type::move(__p + __ip + __n, __p + __ip, __n_move); |
| 1547 | } |
| 1548 | else |
| 1549 | { |
| 1550 | __grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n); |
| 1551 | __p = std::__to_address(__get_long_pointer()); |
| 1552 | } |
| 1553 | __sz += __n; |
| 1554 | __set_size(__sz); |
| 1555 | traits_type::assign(__p[__sz], value_type()); |
| 1556 | for (__p += __ip; __first != __last; ++__p, ++__first) |
| 1557 | traits_type::assign(*__p, *__first); |
| 1558 | |
| 1559 | return begin() + __ip; |
| 1560 | } |
| 1561 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1562 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 allocator_type& __alloc() _NOEXCEPT { return __r_.second(); } |
| 1563 | _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] | 1564 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1565 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1566 | void __set_short_size(size_type __s) _NOEXCEPT { |
| 1567 | _LIBCPP_ASSERT(__s < __min_cap, "__s should never be greater than or equal to the short string capacity"); |
| 1568 | __r_.first().__s.__size_ = __s; |
| 1569 | __r_.first().__s.__is_long_ = false; |
| 1570 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1571 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1572 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1573 | size_type __get_short_size() const _NOEXCEPT { |
| 1574 | _LIBCPP_ASSERT(!__r_.first().__s.__is_long_, "String has to be short when trying to get the short size"); |
| 1575 | return __r_.first().__s.__size_; |
| 1576 | } |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 1577 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1578 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1579 | void __set_long_size(size_type __s) _NOEXCEPT |
| 1580 | {__r_.first().__l.__size_ = __s;} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1581 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1582 | size_type __get_long_size() const _NOEXCEPT |
| 1583 | {return __r_.first().__l.__size_;} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1584 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1585 | void __set_size(size_type __s) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1586 | {if (__is_long()) __set_long_size(__s); else __set_short_size(__s);} |
| 1587 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1588 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1589 | void __set_long_cap(size_type __s) _NOEXCEPT { |
| 1590 | __r_.first().__l.__cap_ = __s / __endian_factor; |
| 1591 | __r_.first().__l.__is_long_ = true; |
| 1592 | } |
| 1593 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1594 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 1595 | size_type __get_long_cap() const _NOEXCEPT { |
| 1596 | return __r_.first().__l.__cap_ * __endian_factor; |
| 1597 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1598 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1599 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1600 | void __set_long_pointer(pointer __p) _NOEXCEPT |
| 1601 | {__r_.first().__l.__data_ = __p;} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1602 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1603 | pointer __get_long_pointer() _NOEXCEPT |
| 1604 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1605 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1606 | const_pointer __get_long_pointer() const _NOEXCEPT |
| 1607 | {return __r_.first().__l.__data_;} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1608 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1609 | pointer __get_short_pointer() _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1610 | {return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1611 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1612 | const_pointer __get_short_pointer() const _NOEXCEPT |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1613 | {return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1614 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1615 | pointer __get_pointer() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1616 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1617 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1618 | const_pointer __get_pointer() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1619 | {return __is_long() ? __get_long_pointer() : __get_short_pointer();} |
| 1620 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1621 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1622 | void __zero() _NOEXCEPT { |
| 1623 | __r_.first() = __rep(); |
| 1624 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1625 | |
| 1626 | template <size_type __a> static |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1627 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 1628 | size_type __align_it(size_type __s) _NOEXCEPT |
Eric Fiselier | 8599fcc | 2015-08-28 07:02:42 +0000 | [diff] [blame] | 1629 | {return (__s + (__a-1)) & ~(__a-1);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1630 | enum {__alignment = 16}; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1631 | static _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 1632 | size_type __recommend(size_type __s) _NOEXCEPT |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1633 | { |
| 1634 | if (__s < __min_cap) { |
| 1635 | if (__libcpp_is_constant_evaluated()) |
| 1636 | return static_cast<size_type>(__min_cap); |
| 1637 | else |
| 1638 | return static_cast<size_type>(__min_cap) - 1; |
| 1639 | } |
Marshall Clow | 8058452 | 2018-02-07 21:30:17 +0000 | [diff] [blame] | 1640 | size_type __guess = __align_it<sizeof(value_type) < __alignment ? |
| 1641 | __alignment/sizeof(value_type) : 1 > (__s+1) - 1; |
| 1642 | if (__guess == __min_cap) ++__guess; |
| 1643 | return __guess; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1644 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1645 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1646 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1647 | void __init(const value_type* __s, size_type __sz, size_type __reserve); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1648 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1649 | void __init(const value_type* __s, size_type __sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1650 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1651 | void __init(size_type __n, value_type __c); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1652 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 1653 | // Slow path for the (inlined) copy constructor for 'long' strings. |
| 1654 | // Always externally instantiated and not inlined. |
| 1655 | // Requires that __s is zero terminated. |
| 1656 | // The main reason for this function to exist is because for unstable, we |
| 1657 | // want to allow inlining of the copy constructor. However, we don't want |
| 1658 | // to call the __init() functions as those are marked as inline which may |
| 1659 | // result in over-aggressive inlining by the compiler, where our aim is |
| 1660 | // to only inline the fast path code directly in the ctor. |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1661 | _LIBCPP_CONSTEXPR_AFTER_CXX17 void __init_copy_ctor_external(const value_type* __s, size_type __sz); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 1662 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1663 | template <class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1664 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1665 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1666 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1667 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 1668 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1669 | __init(_InputIterator __first, _InputIterator __last); |
| 1670 | |
| 1671 | template <class _ForwardIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1672 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 1673 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1674 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 1675 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 1676 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1677 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 1678 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1679 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1680 | 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] | 1681 | size_type __n_copy, size_type __n_del, size_type __n_add = 0); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1682 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 1684 | size_type __n_copy, size_type __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1685 | size_type __n_add, const value_type* __p_new_stuff); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1686 | |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 1687 | // __assign_no_alias is invoked for assignment operations where we |
| 1688 | // have proof that the input does not alias the current instance. |
| 1689 | // For example, operator=(basic_string) performs a 'self' check. |
| 1690 | template <bool __is_short> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1691 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_no_alias(const value_type* __s, size_type __n); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 1692 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1693 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1694 | void __erase_to_end(size_type __pos); |
| 1695 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 1696 | // __erase_external_with_move is invoked for erase() invocations where |
| 1697 | // `n ~= npos`, likely requiring memory moves on the string data. |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1698 | _LIBCPP_CONSTEXPR_AFTER_CXX17 void __erase_external_with_move(size_type __pos, size_type __n); |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 1699 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1700 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1701 | void __copy_assign_alloc(const basic_string& __str) |
| 1702 | {__copy_assign_alloc(__str, integral_constant<bool, |
| 1703 | __alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 1704 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1705 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1706 | void __copy_assign_alloc(const basic_string& __str, true_type) |
| 1707 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1708 | if (__alloc() == __str.__alloc()) |
| 1709 | __alloc() = __str.__alloc(); |
| 1710 | else |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1711 | { |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1712 | if (!__str.__is_long()) |
| 1713 | { |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 1714 | __clear_and_shrink(); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1715 | __alloc() = __str.__alloc(); |
| 1716 | } |
| 1717 | else |
| 1718 | { |
| 1719 | allocator_type __a = __str.__alloc(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1720 | auto __allocation = std::__allocate_at_least(__a, __str.__get_long_cap()); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1721 | __begin_lifetime(__allocation.ptr, __allocation.count); |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 1722 | __clear_and_shrink(); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1723 | __alloc() = _VSTD::move(__a); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1724 | __set_long_pointer(__allocation.ptr); |
| 1725 | __set_long_cap(__allocation.count); |
Marshall Clow | f258c20 | 2017-01-31 03:40:52 +0000 | [diff] [blame] | 1726 | __set_long_size(__str.size()); |
| 1727 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1728 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1731 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1732 | void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1733 | {} |
| 1734 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 1735 | #ifndef _LIBCPP_CXX03_LANG |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1736 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1737 | void __move_assign(basic_string& __str, false_type) |
| 1738 | _NOEXCEPT_(__alloc_traits::is_always_equal::value); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1739 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1740 | void __move_assign(basic_string& __str, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1741 | #if _LIBCPP_STD_VER > 14 |
| 1742 | _NOEXCEPT; |
| 1743 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1744 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1745 | #endif |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 1746 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 1747 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1748 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1749 | void |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1750 | __move_assign_alloc(basic_string& __str) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1751 | _NOEXCEPT_( |
| 1752 | !__alloc_traits::propagate_on_container_move_assignment::value || |
| 1753 | is_nothrow_move_assignable<allocator_type>::value) |
| 1754 | {__move_assign_alloc(__str, integral_constant<bool, |
| 1755 | __alloc_traits::propagate_on_container_move_assignment::value>());} |
| 1756 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1757 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c273496 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 1758 | void __move_assign_alloc(basic_string& __c, true_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1759 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
| 1760 | { |
| 1761 | __alloc() = _VSTD::move(__c.__alloc()); |
| 1762 | } |
| 1763 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1764 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1765 | void __move_assign_alloc(basic_string&, false_type) |
Howard Hinnant | 58fe91b | 2011-08-17 20:36:18 +0000 | [diff] [blame] | 1766 | _NOEXCEPT |
| 1767 | {} |
| 1768 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1769 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s); |
| 1770 | _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& __assign_external(const value_type* __s, size_type __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 1771 | |
| 1772 | // Assigns the value in __s, guaranteed to be __n < __min_cap in length. |
| 1773 | inline basic_string& __assign_short(const value_type* __s, size_type __n) { |
| 1774 | pointer __p = __is_long() |
| 1775 | ? (__set_long_size(__n), __get_long_pointer()) |
| 1776 | : (__set_short_size(__n), __get_short_pointer()); |
| 1777 | traits_type::move(_VSTD::__to_address(__p), __s, __n); |
| 1778 | traits_type::assign(__p[__n], value_type()); |
| 1779 | return *this; |
| 1780 | } |
| 1781 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1782 | _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1783 | basic_string& __null_terminate_at(value_type* __p, size_type __newsz) { |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 1784 | __set_size(__newsz); |
| 1785 | __invalidate_iterators_past(__newsz); |
| 1786 | traits_type::assign(__p[__newsz], value_type()); |
| 1787 | return *this; |
| 1788 | } |
| 1789 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1790 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __invalidate_all_iterators(); |
| 1791 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __invalidate_iterators_past(size_type); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1792 | |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1793 | template<class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1794 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1795 | bool __addr_in_range(_Tp&& __t) const { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1796 | // assume that the ranges overlap, because we can't check during constant evaluation |
| 1797 | if (__libcpp_is_constant_evaluated()) |
| 1798 | return true; |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 1799 | const volatile void *__p = _VSTD::addressof(__t); |
| 1800 | return data() <= __p && __p <= data() + size(); |
| 1801 | } |
| 1802 | |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1803 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1804 | void __throw_length_error() const { |
Nikolas Klauser | f89bb93 | 2022-01-24 19:44:34 +0100 | [diff] [blame] | 1805 | _VSTD::__throw_length_error("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | _LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI |
| 1809 | void __throw_out_of_range() const { |
Nikolas Klauser | f89bb93 | 2022-01-24 19:44:34 +0100 | [diff] [blame] | 1810 | _VSTD::__throw_out_of_range("basic_string"); |
Louis Dionne | d24191c | 2021-08-19 12:39:16 -0400 | [diff] [blame] | 1811 | } |
| 1812 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1813 | friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const basic_string&); |
| 1814 | friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const value_type*, const basic_string&); |
| 1815 | friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(value_type, const basic_string&); |
| 1816 | friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, const value_type*); |
| 1817 | friend _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string operator+<>(const basic_string&, value_type); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1818 | }; |
| 1819 | |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1820 | // These declarations must appear before any functions are implicitly used |
| 1821 | // so that they have the correct visibility specifier. |
| 1822 | #ifdef _LIBCPP_ABI_STRING_OPTIMIZED_EXTERNAL_INSTANTIATION |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1823 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) |
| 1824 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 1825 | _LIBCPP_STRING_UNSTABLE_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) |
| 1826 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1827 | #else |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1828 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, char) |
| 1829 | # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 1830 | _LIBCPP_STRING_V1_EXTERN_TEMPLATE_LIST(_LIBCPP_EXTERN_TEMPLATE, wchar_t) |
| 1831 | # endif |
Eric Fiselier | 2ed640b | 2020-03-04 13:54:04 -0500 | [diff] [blame] | 1832 | #endif |
| 1833 | |
| 1834 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 1835 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1836 | template<class _InputIterator, |
Arthur O'Dwyer | 5622676 | 2021-03-03 23:02:20 -0500 | [diff] [blame] | 1837 | class _CharT = __iter_value_type<_InputIterator>, |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1838 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1839 | class = enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value>, |
| 1840 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1841 | > |
| 1842 | basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 1843 | -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1844 | |
| 1845 | template<class _CharT, |
| 1846 | class _Traits, |
| 1847 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1848 | class = enable_if_t<__is_allocator<_Allocator>::value> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1849 | > |
| 1850 | explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) |
| 1851 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 1852 | |
| 1853 | template<class _CharT, |
| 1854 | class _Traits, |
| 1855 | class _Allocator = allocator<_CharT>, |
Louis Dionne | 2554716 | 2021-08-17 12:26:09 -0400 | [diff] [blame] | 1856 | class = enable_if_t<__is_allocator<_Allocator>::value>, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1857 | class _Sz = typename allocator_traits<_Allocator>::size_type |
| 1858 | > |
| 1859 | basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator()) |
| 1860 | -> basic_string<_CharT, _Traits, _Allocator>; |
Marshall Clow | a056333 | 2018-02-08 06:34:03 +0000 | [diff] [blame] | 1861 | #endif |
| 1862 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1863 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1864 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | void |
| 1866 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators() |
| 1867 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1868 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1869 | if (!__libcpp_is_constant_evaluated()) |
| 1870 | __get_db()->__invalidate_all(this); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1871 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1875 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1876 | void |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1877 | basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type __pos) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1878 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 1879 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1880 | if (!__libcpp_is_constant_evaluated()) { |
| 1881 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1882 | if (__c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1883 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1884 | const_pointer __new_last = __get_pointer() + __pos; |
| 1885 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | { |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1887 | --__p; |
| 1888 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 1889 | if (__i->base() > __new_last) |
| 1890 | { |
| 1891 | (*__p)->__c_ = nullptr; |
| 1892 | if (--__c->end_ != __p) |
| 1893 | _VSTD::memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 1894 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1895 | } |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 1896 | __get_db()->unlock(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1897 | } |
| 1898 | } |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 1899 | #else |
| 1900 | (void)__pos; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1901 | #endif // _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1905 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 1906 | basic_string<_CharT, _Traits, _Allocator>::basic_string() |
Marshall Clow | e546cbb | 2015-06-04 02:05:41 +0000 | [diff] [blame] | 1907 | _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 1908 | : __r_(__default_init_tag(), __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1909 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1910 | std::__debug_db_insert_c(this); |
| 1911 | __default_init(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1915 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1916 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) |
Eric Fiselier | e012bf2 | 2015-07-18 20:40:46 +0000 | [diff] [blame] | 1917 | #if _LIBCPP_STD_VER <= 14 |
| 1918 | _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) |
| 1919 | #else |
| 1920 | _NOEXCEPT |
| 1921 | #endif |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 1922 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1923 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1924 | std::__debug_db_insert_c(this); |
| 1925 | __default_init(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1929 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 815ed73 | 2016-09-16 00:00:48 +0000 | [diff] [blame] | 1930 | void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, |
| 1931 | size_type __sz, |
| 1932 | size_type __reserve) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1933 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1934 | if (__libcpp_is_constant_evaluated()) |
| 1935 | __zero(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1936 | if (__reserve > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 1937 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1938 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1939 | if (__fits_in_sso(__reserve)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1940 | { |
| 1941 | __set_short_size(__sz); |
| 1942 | __p = __get_short_pointer(); |
| 1943 | } |
| 1944 | else |
| 1945 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1946 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__reserve) + 1); |
| 1947 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1948 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1949 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1950 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1951 | __set_long_size(__sz); |
| 1952 | } |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1953 | traits_type::copy(_VSTD::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1954 | traits_type::assign(__p[__sz], value_type()); |
| 1955 | } |
| 1956 | |
| 1957 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1958 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1959 | void |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 1960 | 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] | 1961 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1962 | if (__libcpp_is_constant_evaluated()) |
| 1963 | __zero(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1964 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 1965 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1966 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 1967 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1968 | { |
| 1969 | __set_short_size(__sz); |
| 1970 | __p = __get_short_pointer(); |
| 1971 | } |
| 1972 | else |
| 1973 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1974 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 1975 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1976 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1977 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 1978 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1979 | __set_long_size(__sz); |
| 1980 | } |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 1981 | traits_type::copy(_VSTD::__to_address(__p), __s, __sz); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1982 | traits_type::assign(__p[__sz], value_type()); |
| 1983 | } |
| 1984 | |
| 1985 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 1986 | template <class> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1987 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 1988 | 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] | 1989 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1990 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 1991 | _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | __init(__s, traits_type::length(__s)); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 1993 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 1997 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 1998 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 1999 | : __r_(__default_init_tag(), __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2000 | { |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2001 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); |
| 2002 | __init(__s, __n); |
| 2003 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2007 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2008 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2009 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2010 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2011 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2012 | __init(__s, __n); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2013 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2017 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2018 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2019 | : __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] | 2020 | { |
| 2021 | if (!__str.__is_long()) |
| 2022 | __r_.first().__r = __str.__r_.first().__r; |
| 2023 | else |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2024 | __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()), |
| 2025 | __str.__get_long_size()); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2026 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2030 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2031 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
| 2032 | const basic_string& __str, const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2033 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2034 | { |
| 2035 | if (!__str.__is_long()) |
| 2036 | __r_.first().__r = __str.__r_.first().__r; |
| 2037 | else |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2038 | __init_copy_ctor_external(_VSTD::__to_address(__str.__get_long_pointer()), |
| 2039 | __str.__get_long_size()); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2040 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2043 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2044 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2045 | void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( |
| 2046 | const value_type* __s, size_type __sz) { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2047 | if (__libcpp_is_constant_evaluated()) |
| 2048 | __zero(); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2049 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2050 | if (__fits_in_sso(__sz)) { |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2051 | __p = __get_short_pointer(); |
| 2052 | __set_short_size(__sz); |
| 2053 | } else { |
| 2054 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2055 | __throw_length_error(); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2056 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2057 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2058 | __begin_lifetime(__p, __allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2059 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2060 | __set_long_cap(__allocation.count); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2061 | __set_long_size(__sz); |
| 2062 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2063 | traits_type::copy(std::__to_address(__p), __s, __sz + 1); |
Martijn Vels | 5e7c975 | 2020-03-04 17:52:46 -0500 | [diff] [blame] | 2064 | } |
| 2065 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 2066 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2067 | |
| 2068 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2069 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2070 | basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 2071 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2072 | _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) |
Marshall Clow | a80abc7 | 2015-06-03 19:56:43 +0000 | [diff] [blame] | 2073 | #else |
| 2074 | _NOEXCEPT |
| 2075 | #endif |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2076 | : __r_(_VSTD::move(__str.__r_)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2077 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2078 | __str.__default_init(); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2079 | _VSTD::__debug_db_insert_c(this); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 2080 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2081 | if (!__libcpp_is_constant_evaluated() && __is_long()) |
| 2082 | __get_db()->swap(this, &__str); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2083 | #endif |
| 2084 | } |
| 2085 | |
| 2086 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2087 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2088 | basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2089 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2090 | { |
Marshall Clow | d2d2469 | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 2091 | if (__str.__is_long() && __a != __str.__alloc()) // copy, not move |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2092 | __init(_VSTD::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); |
Marshall Clow | d2d2469 | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 2093 | else |
| 2094 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2095 | if (__libcpp_is_constant_evaluated()) { |
| 2096 | __zero(); |
| 2097 | __r_.first().__l = __str.__r_.first().__l; |
| 2098 | } else { |
| 2099 | __r_.first().__r = __str.__r_.first().__r; |
| 2100 | } |
| 2101 | __str.__default_init(); |
Marshall Clow | d2d2469 | 2014-07-17 15:32:20 +0000 | [diff] [blame] | 2102 | } |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2103 | _VSTD::__debug_db_insert_c(this); |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 2104 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2105 | if (!__libcpp_is_constant_evaluated() && __is_long()) |
| 2106 | __get_db()->swap(this, &__str); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2107 | #endif |
| 2108 | } |
| 2109 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2110 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | |
| 2112 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2113 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2114 | void |
| 2115 | basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c) |
| 2116 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2117 | if (__libcpp_is_constant_evaluated()) |
| 2118 | __zero(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2119 | if (__n > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2120 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2121 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2122 | if (__fits_in_sso(__n)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2123 | { |
| 2124 | __set_short_size(__n); |
| 2125 | __p = __get_short_pointer(); |
| 2126 | } |
| 2127 | else |
| 2128 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2129 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__n) + 1); |
| 2130 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2131 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2132 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2133 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2134 | __set_long_size(__n); |
| 2135 | } |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2136 | traits_type::assign(_VSTD::__to_address(__p), __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2137 | traits_type::assign(__p[__n], value_type()); |
| 2138 | } |
| 2139 | |
| 2140 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2141 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2142 | basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2143 | : __r_(__default_init_tag(), __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2144 | { |
| 2145 | __init(__n, __c); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2146 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2150 | template <class> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2151 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2152 | 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] | 2153 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2154 | { |
| 2155 | __init(__n, __c); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2156 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2159 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2160 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2161 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, |
| 2162 | size_type __pos, size_type __n, |
| 2163 | const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2164 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2165 | { |
| 2166 | size_type __str_sz = __str.size(); |
| 2167 | if (__pos > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2168 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2169 | __init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos)); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2170 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2174 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 2175 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2176 | const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2177 | : __r_(__default_init_tag(), __a) |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 2178 | { |
| 2179 | size_type __str_sz = __str.size(); |
| 2180 | if (__pos > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2181 | __throw_out_of_range(); |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 2182 | __init(__str.data() + __pos, __str_sz - __pos); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2183 | _VSTD::__debug_db_insert_c(this); |
Marshall Clow | 8344580 | 2016-04-07 18:13:41 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2187 | template <class _Tp, class> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2188 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2189 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2190 | 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] | 2191 | : __r_(__default_init_tag(), __a) |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2192 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2193 | __self_view __sv0 = __t; |
| 2194 | __self_view __sv = __sv0.substr(__pos, __n); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2195 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2196 | _VSTD::__debug_db_insert_c(this); |
Marshall Clow | 78dbe46 | 2016-11-14 18:22:19 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2200 | template <class _Tp, class> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2201 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2202 | basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2203 | : __r_(__default_init_tag(), __default_init_tag()) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2204 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2205 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2206 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2207 | _VSTD::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2211 | template <class _Tp, class> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2212 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2213 | 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] | 2214 | : __r_(__default_init_tag(), __a) |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2215 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 2216 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2217 | __init(__sv.data(), __sv.size()); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2218 | _VSTD::__debug_db_insert_c(this); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2222 | template <class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2223 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2224 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2225 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2226 | __is_exactly_cpp17_input_iterator<_InputIterator>::value |
| 2227 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2228 | basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last) |
| 2229 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2230 | __default_init(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2231 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2232 | try |
| 2233 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2234 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2235 | for (; __first != __last; ++__first) |
| 2236 | push_back(*__first); |
| 2237 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2238 | } |
| 2239 | catch (...) |
| 2240 | { |
| 2241 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2242 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2243 | throw; |
| 2244 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2245 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | template <class _CharT, class _Traits, class _Allocator> |
| 2249 | template <class _ForwardIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2250 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2251 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2252 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2253 | __is_cpp17_forward_iterator<_ForwardIterator>::value |
| 2254 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2255 | basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 2256 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2257 | if (__libcpp_is_constant_evaluated()) |
| 2258 | __zero(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2259 | size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2260 | if (__sz > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2261 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2262 | pointer __p; |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2263 | if (__fits_in_sso(__sz)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2264 | { |
| 2265 | __set_short_size(__sz); |
| 2266 | __p = __get_short_pointer(); |
| 2267 | } |
| 2268 | else |
| 2269 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2270 | auto __allocation = std::__allocate_at_least(__alloc(), __recommend(__sz) + 1); |
| 2271 | __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2272 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2273 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2274 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2275 | __set_long_size(__sz); |
| 2276 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2277 | |
| 2278 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2279 | try |
| 2280 | { |
| 2281 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | a09a3b4 | 2014-10-27 19:28:20 +0000 | [diff] [blame] | 2282 | for (; __first != __last; ++__first, (void) ++__p) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2283 | traits_type::assign(*__p, *__first); |
| 2284 | traits_type::assign(*__p, value_type()); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2285 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 2286 | } |
| 2287 | catch (...) |
| 2288 | { |
| 2289 | if (__is_long()) |
| 2290 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
| 2291 | throw; |
| 2292 | } |
| 2293 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | template <class _CharT, class _Traits, class _Allocator> |
Eric Fiselier | c0f566d | 2019-03-14 12:31:10 +0000 | [diff] [blame] | 2297 | template<class _InputIterator, class> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2298 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2299 | basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2300 | : __r_(__default_init_tag(), __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2301 | { |
| 2302 | __init(__first, __last); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2303 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | template <class _CharT, class _Traits, class _Allocator> |
Eric Fiselier | c0f566d | 2019-03-14 12:31:10 +0000 | [diff] [blame] | 2307 | template<class _InputIterator, class> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2308 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2309 | basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, |
| 2310 | const allocator_type& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2311 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2312 | { |
| 2313 | __init(__first, __last); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2314 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 2317 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2318 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2319 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2320 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2321 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
| 2322 | initializer_list<_CharT> __il) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2323 | : __r_(__default_init_tag(), __default_init_tag()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2324 | { |
| 2325 | __init(__il.begin(), __il.end()); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2326 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2330 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 812882b | 2017-02-17 01:17:10 +0000 | [diff] [blame] | 2331 | basic_string<_CharT, _Traits, _Allocator>::basic_string( |
| 2332 | initializer_list<_CharT> __il, const _Allocator& __a) |
Eric Fiselier | 5169d1c | 2019-12-16 19:03:23 -0500 | [diff] [blame] | 2333 | : __r_(__default_init_tag(), __a) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2334 | { |
| 2335 | __init(__il.begin(), __il.end()); |
Nikolas Klauser | f280773 | 2022-01-11 00:33:35 +0100 | [diff] [blame] | 2336 | _VSTD::__debug_db_insert_c(this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2339 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2340 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2341 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2342 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2343 | basic_string<_CharT, _Traits, _Allocator>::~basic_string() |
| 2344 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 2345 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 2346 | if (!__libcpp_is_constant_evaluated()) |
| 2347 | __get_db()->__erase_c(this); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 2348 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2349 | if (__is_long()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2350 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2354 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2355 | void |
| 2356 | basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace |
| 2357 | (size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2358 | 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] | 2359 | { |
| 2360 | size_type __ms = max_size(); |
| 2361 | if (__delta_cap > __ms - __old_cap - 1) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2362 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2363 | pointer __old_p = __get_pointer(); |
| 2364 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2365 | __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2366 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2367 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2368 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2369 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2370 | __invalidate_all_iterators(); |
| 2371 | if (__n_copy != 0) |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2372 | traits_type::copy(_VSTD::__to_address(__p), |
| 2373 | _VSTD::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2374 | if (__n_add != 0) |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2375 | traits_type::copy(_VSTD::__to_address(__p) + __n_copy, __p_new_stuff, __n_add); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2376 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2377 | if (__sec_cp_sz != 0) |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2378 | traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add, |
| 2379 | _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2380 | if (__old_cap+1 != __min_cap || __libcpp_is_constant_evaluated()) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2381 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2382 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2383 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2384 | __old_sz = __n_copy + __n_add + __sec_cp_sz; |
| 2385 | __set_long_size(__old_sz); |
| 2386 | traits_type::assign(__p[__old_sz], value_type()); |
| 2387 | } |
| 2388 | |
| 2389 | template <class _CharT, class _Traits, class _Allocator> |
| 2390 | void |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2391 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2392 | basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz, |
| 2393 | size_type __n_copy, size_type __n_del, size_type __n_add) |
| 2394 | { |
| 2395 | size_type __ms = max_size(); |
Marshall Clow | 2267c5d | 2013-11-06 14:24:38 +0000 | [diff] [blame] | 2396 | if (__delta_cap > __ms - __old_cap) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2397 | __throw_length_error(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | pointer __old_p = __get_pointer(); |
| 2399 | size_type __cap = __old_cap < __ms / 2 - __alignment ? |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2400 | __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2401 | __ms - 1; |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2402 | auto __allocation = std::__allocate_at_least(__alloc(), __cap + 1); |
| 2403 | pointer __p = __allocation.ptr; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2404 | __begin_lifetime(__p, __allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2405 | __invalidate_all_iterators(); |
| 2406 | if (__n_copy != 0) |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2407 | traits_type::copy(_VSTD::__to_address(__p), |
| 2408 | _VSTD::__to_address(__old_p), __n_copy); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2409 | size_type __sec_cp_sz = __old_sz - __n_del - __n_copy; |
| 2410 | if (__sec_cp_sz != 0) |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2411 | traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add, |
| 2412 | _VSTD::__to_address(__old_p) + __n_copy + __n_del, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2413 | __sec_cp_sz); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2414 | if (__libcpp_is_constant_evaluated() || __old_cap + 1 != __min_cap) |
| 2415 | __alloc_traits::deallocate(__alloc(), __old_p, __old_cap + 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2416 | __set_long_pointer(__p); |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 2417 | __set_long_cap(__allocation.count); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | // assign |
| 2421 | |
| 2422 | template <class _CharT, class _Traits, class _Allocator> |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2423 | template <bool __is_short> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2424 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2425 | basic_string<_CharT, _Traits, _Allocator>& |
| 2426 | basic_string<_CharT, _Traits, _Allocator>::__assign_no_alias( |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2427 | const value_type* __s, size_type __n) { |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2428 | 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] | 2429 | if (__n < __cap) { |
| 2430 | pointer __p = __is_short ? __get_short_pointer() : __get_long_pointer(); |
| 2431 | __is_short ? __set_short_size(__n) : __set_long_size(__n); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2432 | traits_type::copy(std::__to_address(__p), __s, __n); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2433 | traits_type::assign(__p[__n], value_type()); |
| 2434 | __invalidate_iterators_past(__n); |
| 2435 | } else { |
| 2436 | size_type __sz = __is_short ? __get_short_size() : __get_long_size(); |
| 2437 | __grow_by_and_replace(__cap - 1, __n - __cap + 1, __sz, 0, __sz, __n, __s); |
| 2438 | } |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2439 | return *this; |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2443 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2444 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2445 | basic_string<_CharT, _Traits, _Allocator>::__assign_external( |
| 2446 | const value_type* __s, size_type __n) { |
| 2447 | size_type __cap = capacity(); |
| 2448 | if (__cap >= __n) { |
| 2449 | value_type* __p = _VSTD::__to_address(__get_pointer()); |
| 2450 | traits_type::move(__p, __s, __n); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2451 | return __null_terminate_at(__p, __n); |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2452 | } else { |
| 2453 | size_type __sz = size(); |
| 2454 | __grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2455 | return *this; |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2456 | } |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2460 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2461 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2462 | 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] | 2463 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2464 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr"); |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2465 | return (__builtin_constant_p(__n) && __fits_in_sso(__n)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2466 | ? __assign_short(__s, __n) |
| 2467 | : __assign_external(__s, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2471 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2472 | basic_string<_CharT, _Traits, _Allocator>& |
| 2473 | basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c) |
| 2474 | { |
| 2475 | size_type __cap = capacity(); |
| 2476 | if (__cap < __n) |
| 2477 | { |
| 2478 | size_type __sz = size(); |
| 2479 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2480 | } |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2481 | value_type* __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2482 | traits_type::assign(__p, __n, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 2483 | return __null_terminate_at(__p, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2487 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2488 | basic_string<_CharT, _Traits, _Allocator>& |
| 2489 | basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c) |
| 2490 | { |
| 2491 | pointer __p; |
| 2492 | if (__is_long()) |
| 2493 | { |
| 2494 | __p = __get_long_pointer(); |
| 2495 | __set_long_size(1); |
| 2496 | } |
| 2497 | else |
| 2498 | { |
| 2499 | __p = __get_short_pointer(); |
| 2500 | __set_short_size(1); |
| 2501 | } |
| 2502 | traits_type::assign(*__p, __c); |
| 2503 | traits_type::assign(*++__p, value_type()); |
| 2504 | __invalidate_iterators_past(1); |
| 2505 | return *this; |
| 2506 | } |
| 2507 | |
| 2508 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2509 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2510 | basic_string<_CharT, _Traits, _Allocator>& |
| 2511 | basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str) |
| 2512 | { |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2513 | if (this != &__str) { |
| 2514 | __copy_assign_alloc(__str); |
| 2515 | if (!__is_long()) { |
| 2516 | if (!__str.__is_long()) { |
Eric Fiselier | 03bbc92 | 2020-01-15 17:27:10 -0500 | [diff] [blame] | 2517 | __r_.first().__r = __str.__r_.first().__r; |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2518 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2519 | return __assign_no_alias<true>(__str.data(), __str.size()); |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2520 | } |
| 2521 | } else { |
Martijn Vels | b6a08b6 | 2020-04-10 18:36:31 -0400 | [diff] [blame] | 2522 | return __assign_no_alias<false>(__str.data(), __str.size()); |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2523 | } |
Martijn Vels | 596e3de | 2020-02-26 15:55:49 -0500 | [diff] [blame] | 2524 | } |
| 2525 | return *this; |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 2528 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2529 | |
| 2530 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2531 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2532 | void |
| 2533 | basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2534 | _NOEXCEPT_(__alloc_traits::is_always_equal::value) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2535 | { |
| 2536 | if (__alloc() != __str.__alloc()) |
| 2537 | assign(__str); |
| 2538 | else |
| 2539 | __move_assign(__str, true_type()); |
| 2540 | } |
| 2541 | |
| 2542 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2543 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
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, true_type) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2546 | #if _LIBCPP_STD_VER > 14 |
| 2547 | _NOEXCEPT |
| 2548 | #else |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 2549 | _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2550 | #endif |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2551 | { |
marshall | 2ed4162 | 2019-11-27 07:13:00 -0800 | [diff] [blame] | 2552 | if (__is_long()) { |
| 2553 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), |
| 2554 | __get_long_cap()); |
| 2555 | #if _LIBCPP_STD_VER <= 14 |
| 2556 | if (!is_nothrow_move_assignable<allocator_type>::value) { |
| 2557 | __set_short_size(0); |
| 2558 | traits_type::assign(__get_short_pointer()[0], value_type()); |
| 2559 | } |
| 2560 | #endif |
| 2561 | } |
| 2562 | __move_assign_alloc(__str); |
| 2563 | __r_.first() = __str.__r_.first(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2564 | if (__libcpp_is_constant_evaluated()) { |
| 2565 | __str.__default_init(); |
| 2566 | } else { |
| 2567 | __str.__set_short_size(0); |
| 2568 | traits_type::assign(__str.__get_short_pointer()[0], value_type()); |
| 2569 | } |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2573 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2574 | basic_string<_CharT, _Traits, _Allocator>& |
| 2575 | basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) |
Marshall Clow | 2fe8a8d | 2015-08-18 18:57:00 +0000 | [diff] [blame] | 2576 | _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 2577 | { |
| 2578 | __move_assign(__str, integral_constant<bool, |
| 2579 | __alloc_traits::propagate_on_container_move_assignment::value>()); |
| 2580 | return *this; |
| 2581 | } |
| 2582 | |
| 2583 | #endif |
| 2584 | |
| 2585 | template <class _CharT, class _Traits, class _Allocator> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2586 | template<class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2587 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2588 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2589 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2590 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2591 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2592 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2593 | basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last) |
| 2594 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2595 | const basic_string __temp(__first, __last, __alloc()); |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2596 | assign(__temp.data(), __temp.size()); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2597 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | template <class _CharT, class _Traits, class _Allocator> |
| 2601 | template<class _ForwardIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2602 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2603 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2604 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2605 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2606 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2607 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2608 | basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last) |
| 2609 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2610 | size_type __cap = capacity(); |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2611 | size_type __n = __string_is_trivial_iterator<_ForwardIterator>::value ? |
| 2612 | static_cast<size_type>(_VSTD::distance(__first, __last)) : 0; |
| 2613 | |
| 2614 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2615 | (__cap >= __n || !__addr_in_range(*__first))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2616 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2617 | if (__cap < __n) |
| 2618 | { |
| 2619 | size_type __sz = size(); |
| 2620 | __grow_by(__cap, __n - __cap, __sz, 0, __sz); |
| 2621 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2622 | pointer __p = __get_pointer(); |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2623 | for (; __first != __last; ++__p, (void) ++__first) |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2624 | traits_type::assign(*__p, *__first); |
| 2625 | traits_type::assign(*__p, value_type()); |
| 2626 | __set_size(__n); |
Arthur O'Dwyer | b3db454 | 2021-04-27 09:10:04 -0400 | [diff] [blame] | 2627 | __invalidate_iterators_past(__n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2628 | } |
| 2629 | else |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2630 | { |
| 2631 | const basic_string __temp(__first, __last, __alloc()); |
| 2632 | assign(__temp.data(), __temp.size()); |
| 2633 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2634 | return *this; |
| 2635 | } |
| 2636 | |
| 2637 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2638 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2639 | basic_string<_CharT, _Traits, _Allocator>& |
| 2640 | basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n) |
| 2641 | { |
| 2642 | size_type __sz = __str.size(); |
| 2643 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2644 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2645 | return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2649 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2650 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2651 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2652 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2653 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 2654 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 2655 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2656 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2657 | 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] | 2658 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2659 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2660 | size_type __sz = __sv.size(); |
| 2661 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2662 | __throw_out_of_range(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2663 | return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
| 2664 | } |
| 2665 | |
| 2666 | |
| 2667 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2668 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2669 | basic_string<_CharT, _Traits, _Allocator>& |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2670 | basic_string<_CharT, _Traits, _Allocator>::__assign_external(const value_type* __s) { |
| 2671 | return __assign_external(__s, traits_type::length(__s)); |
| 2672 | } |
| 2673 | |
| 2674 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2675 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2676 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2677 | basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2678 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2679 | _LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr"); |
Louis Dionne | 3e0c433 | 2021-08-31 10:49:06 -0400 | [diff] [blame] | 2680 | return __builtin_constant_p(*__s) |
Nikolas Klauser | 93826d1 | 2022-01-04 17:24:03 +0100 | [diff] [blame] | 2681 | ? (__fits_in_sso(traits_type::length(__s)) |
Martijn Vels | da7d94f | 2020-06-19 14:24:03 -0400 | [diff] [blame] | 2682 | ? __assign_short(__s, traits_type::length(__s)) |
| 2683 | : __assign_external(__s, traits_type::length(__s))) |
| 2684 | : __assign_external(__s); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2685 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2686 | // append |
| 2687 | |
| 2688 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2689 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2690 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2691 | 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] | 2692 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2693 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2694 | size_type __cap = capacity(); |
| 2695 | size_type __sz = size(); |
| 2696 | if (__cap - __sz >= __n) |
| 2697 | { |
| 2698 | if (__n) |
| 2699 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2700 | value_type* __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2701 | traits_type::copy(__p + __sz, __s, __n); |
| 2702 | __sz += __n; |
| 2703 | __set_size(__sz); |
| 2704 | traits_type::assign(__p[__sz], value_type()); |
| 2705 | } |
| 2706 | } |
| 2707 | else |
| 2708 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s); |
| 2709 | return *this; |
| 2710 | } |
| 2711 | |
| 2712 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2713 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2714 | basic_string<_CharT, _Traits, _Allocator>& |
| 2715 | basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c) |
| 2716 | { |
| 2717 | if (__n) |
| 2718 | { |
| 2719 | size_type __cap = capacity(); |
| 2720 | size_type __sz = size(); |
| 2721 | if (__cap - __sz < __n) |
| 2722 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2723 | pointer __p = __get_pointer(); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2724 | traits_type::assign(_VSTD::__to_address(__p) + __sz, __n, __c); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2725 | __sz += __n; |
| 2726 | __set_size(__sz); |
| 2727 | traits_type::assign(__p[__sz], value_type()); |
| 2728 | } |
| 2729 | return *this; |
| 2730 | } |
| 2731 | |
| 2732 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2733 | _LIBCPP_CONSTEXPR_AFTER_CXX17 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 2734 | basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n) |
| 2735 | { |
| 2736 | if (__n) |
| 2737 | { |
| 2738 | size_type __cap = capacity(); |
| 2739 | size_type __sz = size(); |
| 2740 | if (__cap - __sz < __n) |
| 2741 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2742 | pointer __p = __get_pointer(); |
| 2743 | __sz += __n; |
| 2744 | __set_size(__sz); |
| 2745 | traits_type::assign(__p[__sz], value_type()); |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2750 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2751 | void |
| 2752 | basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c) |
| 2753 | { |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2754 | bool __is_short = !__is_long(); |
| 2755 | size_type __cap; |
| 2756 | size_type __sz; |
| 2757 | if (__is_short) |
| 2758 | { |
| 2759 | __cap = __min_cap - 1; |
| 2760 | __sz = __get_short_size(); |
| 2761 | } |
| 2762 | else |
| 2763 | { |
| 2764 | __cap = __get_long_cap() - 1; |
| 2765 | __sz = __get_long_size(); |
| 2766 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2767 | if (__sz == __cap) |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2768 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2769 | __grow_by(__cap, 1, __sz, __sz, 0); |
Louis Dionne | 82d2b2c | 2021-11-16 11:26:56 -0500 | [diff] [blame] | 2770 | __is_short = false; // the string is always long after __grow_by |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2771 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2772 | pointer __p = __get_pointer(); |
Howard Hinnant | 68bf181 | 2013-04-30 21:44:48 +0000 | [diff] [blame] | 2773 | if (__is_short) |
| 2774 | { |
| 2775 | __p = __get_short_pointer() + __sz; |
| 2776 | __set_short_size(__sz+1); |
| 2777 | } |
| 2778 | else |
| 2779 | { |
| 2780 | __p = __get_long_pointer() + __sz; |
| 2781 | __set_long_size(__sz+1); |
| 2782 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2783 | traits_type::assign(*__p, __c); |
| 2784 | traits_type::assign(*++__p, value_type()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2785 | } |
| 2786 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2787 | template <class _CharT, class _Traits, class _Allocator> |
| 2788 | template<class _ForwardIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2789 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2790 | __enable_if_t |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2791 | < |
| 2792 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
| 2793 | basic_string<_CharT, _Traits, _Allocator>& |
| 2794 | > |
| 2795 | basic_string<_CharT, _Traits, _Allocator>::append( |
Eric Fiselier | db7ee8f | 2016-10-31 02:46:25 +0000 | [diff] [blame] | 2796 | _ForwardIterator __first, _ForwardIterator __last) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2797 | { |
| 2798 | size_type __sz = size(); |
| 2799 | size_type __cap = capacity(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2800 | size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2801 | if (__n) |
| 2802 | { |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2803 | if (__string_is_trivial_iterator<_ForwardIterator>::value && |
| 2804 | !__addr_in_range(*__first)) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2805 | { |
| 2806 | if (__cap - __sz < __n) |
| 2807 | __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); |
| 2808 | pointer __p = __get_pointer() + __sz; |
Arthur O'Dwyer | 80dbcbe | 2021-09-07 21:35:37 -0400 | [diff] [blame] | 2809 | for (; __first != __last; ++__p, (void) ++__first) |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 2810 | traits_type::assign(*__p, *__first); |
| 2811 | traits_type::assign(*__p, value_type()); |
| 2812 | __set_size(__sz + __n); |
| 2813 | } |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2814 | else |
| 2815 | { |
| 2816 | const basic_string __temp(__first, __last, __alloc()); |
| 2817 | append(__temp.data(), __temp.size()); |
| 2818 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2819 | } |
| 2820 | return *this; |
| 2821 | } |
| 2822 | |
| 2823 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2824 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2825 | basic_string<_CharT, _Traits, _Allocator>& |
| 2826 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str) |
| 2827 | { |
| 2828 | return append(__str.data(), __str.size()); |
| 2829 | } |
| 2830 | |
| 2831 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2832 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2833 | basic_string<_CharT, _Traits, _Allocator>& |
| 2834 | basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n) |
| 2835 | { |
| 2836 | size_type __sz = __str.size(); |
| 2837 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2838 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2839 | return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 6295396 | 2016-10-03 23:40:48 +0000 | [diff] [blame] | 2843 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2844 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2845 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2846 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2847 | __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] | 2848 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2849 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2850 | 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] | 2851 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 2852 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2853 | size_type __sz = __sv.size(); |
| 2854 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2855 | __throw_out_of_range(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 2856 | return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos)); |
| 2857 | } |
| 2858 | |
| 2859 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2860 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2861 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2862 | basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2863 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2864 | _LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2865 | return append(__s, traits_type::length(__s)); |
| 2866 | } |
| 2867 | |
| 2868 | // insert |
| 2869 | |
| 2870 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2871 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2872 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2873 | 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] | 2874 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 2875 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2876 | size_type __sz = size(); |
| 2877 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2878 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2879 | size_type __cap = capacity(); |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2880 | if (__libcpp_is_constant_evaluated()) { |
| 2881 | if (__cap - __sz >= __n) |
| 2882 | __grow_by_and_replace(__cap, 0, __sz, __pos, 0, __n, __s); |
| 2883 | else |
| 2884 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2885 | return *this; |
| 2886 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2887 | if (__cap - __sz >= __n) |
| 2888 | { |
| 2889 | if (__n) |
| 2890 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2891 | value_type* __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2892 | size_type __n_move = __sz - __pos; |
| 2893 | if (__n_move != 0) |
| 2894 | { |
| 2895 | if (__p + __pos <= __s && __s < __p + __sz) |
| 2896 | __s += __n; |
| 2897 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2898 | } |
| 2899 | traits_type::move(__p + __pos, __s, __n); |
| 2900 | __sz += __n; |
| 2901 | __set_size(__sz); |
| 2902 | traits_type::assign(__p[__sz], value_type()); |
| 2903 | } |
| 2904 | } |
| 2905 | else |
| 2906 | __grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s); |
| 2907 | return *this; |
| 2908 | } |
| 2909 | |
| 2910 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2911 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2912 | basic_string<_CharT, _Traits, _Allocator>& |
| 2913 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c) |
| 2914 | { |
| 2915 | size_type __sz = size(); |
| 2916 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 2917 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2918 | if (__n) |
| 2919 | { |
| 2920 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 2921 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2922 | if (__cap - __sz >= __n) |
| 2923 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2924 | __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2925 | size_type __n_move = __sz - __pos; |
| 2926 | if (__n_move != 0) |
| 2927 | traits_type::move(__p + __pos + __n, __p + __pos, __n_move); |
| 2928 | } |
| 2929 | else |
| 2930 | { |
| 2931 | __grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 2932 | __p = _VSTD::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2933 | } |
| 2934 | traits_type::assign(__p + __pos, __n, __c); |
| 2935 | __sz += __n; |
| 2936 | __set_size(__sz); |
| 2937 | traits_type::assign(__p[__sz], value_type()); |
| 2938 | } |
| 2939 | return *this; |
| 2940 | } |
| 2941 | |
| 2942 | template <class _CharT, class _Traits, class _Allocator> |
| 2943 | template<class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2944 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2945 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2946 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2947 | __is_exactly_cpp17_input_iterator<_InputIterator>::value, |
Marshall Clow | 039b2f0 | 2016-01-13 21:54:34 +0000 | [diff] [blame] | 2948 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2949 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2950 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last) |
| 2951 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 2952 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2953 | "string::insert(iterator, range) called with an iterator not" |
| 2954 | " referring to this string"); |
| 2955 | const basic_string __temp(__first, __last, __alloc()); |
| 2956 | return insert(__pos, __temp.data(), __temp.data() + __temp.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | template <class _CharT, class _Traits, class _Allocator> |
| 2960 | template<class _ForwardIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2961 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 2962 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2963 | < |
Arthur O'Dwyer | 98ff31f | 2021-04-16 17:49:57 -0400 | [diff] [blame] | 2964 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2965 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 2966 | > |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2967 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last) |
| 2968 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2969 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 2970 | "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] | 2971 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2972 | size_type __ip = static_cast<size_type>(__pos - begin()); |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2973 | size_type __n = static_cast<size_type>(std::distance(__first, __last)); |
| 2974 | if (__n == 0) |
| 2975 | return begin() + __ip; |
| 2976 | |
| 2977 | if (__string_is_trivial_iterator<_ForwardIterator>::value && !__addr_in_range(*__first)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2978 | { |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2979 | return __insert_from_safe_copy(__n, __ip, __first, __last); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2980 | } |
Nikolas Klauser | 48d680d | 2022-02-26 13:28:33 +0100 | [diff] [blame] | 2981 | else |
| 2982 | { |
| 2983 | const basic_string __temp(__first, __last, __alloc()); |
| 2984 | return __insert_from_safe_copy(__n, __ip, __temp.begin(), __temp.end()); |
| 2985 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2989 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2990 | basic_string<_CharT, _Traits, _Allocator>& |
| 2991 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str) |
| 2992 | { |
| 2993 | return insert(__pos1, __str.data(), __str.size()); |
| 2994 | } |
| 2995 | |
| 2996 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 2997 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2998 | basic_string<_CharT, _Traits, _Allocator>& |
| 2999 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str, |
| 3000 | size_type __pos2, size_type __n) |
| 3001 | { |
| 3002 | size_type __str_sz = __str.size(); |
| 3003 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3004 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3005 | return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3009 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3010 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3011 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3012 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3013 | __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] | 3014 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3015 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3016 | basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3017 | size_type __pos2, size_type __n) |
| 3018 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3019 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3020 | size_type __str_sz = __sv.size(); |
| 3021 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3022 | __throw_out_of_range(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3023 | return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2)); |
| 3024 | } |
| 3025 | |
| 3026 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3027 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3028 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3029 | 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] | 3030 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3031 | _LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3032 | return insert(__pos, __s, traits_type::length(__s)); |
| 3033 | } |
| 3034 | |
| 3035 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3036 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3037 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3038 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c) |
| 3039 | { |
Louis Dionne | f4cc6fb | 2022-02-15 15:47:45 -0500 | [diff] [blame] | 3040 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3041 | "string::insert(iterator, character) called with an iterator not" |
| 3042 | " referring to this string"); |
| 3043 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3044 | size_type __ip = static_cast<size_type>(__pos - begin()); |
| 3045 | size_type __sz = size(); |
| 3046 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3047 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3048 | if (__cap == __sz) |
| 3049 | { |
| 3050 | __grow_by(__cap, 1, __sz, __ip, 0, 1); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 3051 | __p = _VSTD::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3052 | } |
| 3053 | else |
| 3054 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 3055 | __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3056 | size_type __n_move = __sz - __ip; |
| 3057 | if (__n_move != 0) |
| 3058 | traits_type::move(__p + __ip + 1, __p + __ip, __n_move); |
| 3059 | } |
| 3060 | traits_type::assign(__p[__ip], __c); |
| 3061 | traits_type::assign(__p[++__sz], value_type()); |
| 3062 | __set_size(__sz); |
| 3063 | return begin() + static_cast<difference_type>(__ip); |
| 3064 | } |
| 3065 | |
| 3066 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3067 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3068 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3069 | basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c) |
| 3070 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3071 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3072 | "string::insert(iterator, n, value) called with an iterator not" |
| 3073 | " referring to this string"); |
| 3074 | difference_type __p = __pos - begin(); |
| 3075 | insert(static_cast<size_type>(__p), __n, __c); |
| 3076 | return begin() + __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | // replace |
| 3080 | |
| 3081 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3082 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3083 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3084 | 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] | 3085 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3086 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3087 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3088 | size_type __sz = size(); |
| 3089 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3090 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3091 | __n1 = _VSTD::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3092 | size_type __cap = capacity(); |
| 3093 | if (__cap - __sz + __n1 >= __n2) |
| 3094 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3095 | if (__libcpp_is_constant_evaluated()) { |
| 3096 | __grow_by_and_replace(__cap, 0, __sz, __pos, __n1, __n2, __s); |
| 3097 | return *this; |
| 3098 | } |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 3099 | value_type* __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3100 | if (__n1 != __n2) |
| 3101 | { |
| 3102 | size_type __n_move = __sz - __pos - __n1; |
| 3103 | if (__n_move != 0) |
| 3104 | { |
| 3105 | if (__n1 > __n2) |
| 3106 | { |
| 3107 | traits_type::move(__p + __pos, __s, __n2); |
| 3108 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3109 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3110 | } |
| 3111 | if (__p + __pos < __s && __s < __p + __sz) |
| 3112 | { |
| 3113 | if (__p + __pos + __n1 <= __s) |
| 3114 | __s += __n2 - __n1; |
| 3115 | else // __p + __pos < __s < __p + __pos + __n1 |
| 3116 | { |
| 3117 | traits_type::move(__p + __pos, __s, __n1); |
| 3118 | __pos += __n1; |
| 3119 | __s += __n2; |
| 3120 | __n2 -= __n1; |
| 3121 | __n1 = 0; |
| 3122 | } |
| 3123 | } |
| 3124 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3125 | } |
| 3126 | } |
| 3127 | traits_type::move(__p + __pos, __s, __n2); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3128 | return __null_terminate_at(__p, __sz + (__n2 - __n1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3129 | } |
| 3130 | else |
| 3131 | __grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s); |
| 3132 | return *this; |
| 3133 | } |
| 3134 | |
| 3135 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3136 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3137 | basic_string<_CharT, _Traits, _Allocator>& |
| 3138 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c) |
| 3139 | { |
| 3140 | size_type __sz = size(); |
| 3141 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3142 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3143 | __n1 = _VSTD::min(__n1, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3144 | size_type __cap = capacity(); |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3145 | value_type* __p; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3146 | if (__cap - __sz + __n1 >= __n2) |
| 3147 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 3148 | __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3149 | if (__n1 != __n2) |
| 3150 | { |
| 3151 | size_type __n_move = __sz - __pos - __n1; |
| 3152 | if (__n_move != 0) |
| 3153 | traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move); |
| 3154 | } |
| 3155 | } |
| 3156 | else |
| 3157 | { |
| 3158 | __grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 3159 | __p = _VSTD::__to_address(__get_long_pointer()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3160 | } |
| 3161 | traits_type::assign(__p + __pos, __n2, __c); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3162 | return __null_terminate_at(__p, __sz - (__n1 - __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | template <class _CharT, class _Traits, class _Allocator> |
| 3166 | template<class _InputIterator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3167 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3168 | __enable_if_t |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3169 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3170 | __is_cpp17_input_iterator<_InputIterator>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3171 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3172 | > |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3173 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3174 | _InputIterator __j1, _InputIterator __j2) |
| 3175 | { |
Marshall Clow | 958362f | 2016-09-05 01:54:30 +0000 | [diff] [blame] | 3176 | const basic_string __temp(__j1, __j2, __alloc()); |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3177 | return replace(__i1, __i2, __temp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3181 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3182 | basic_string<_CharT, _Traits, _Allocator>& |
| 3183 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str) |
| 3184 | { |
| 3185 | return replace(__pos1, __n1, __str.data(), __str.size()); |
| 3186 | } |
| 3187 | |
| 3188 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3189 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3190 | basic_string<_CharT, _Traits, _Allocator>& |
| 3191 | basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 3192 | size_type __pos2, size_type __n2) |
| 3193 | { |
| 3194 | size_type __str_sz = __str.size(); |
| 3195 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3196 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3197 | return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3198 | } |
| 3199 | |
| 3200 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3201 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3202 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3203 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3204 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3205 | __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] | 3206 | basic_string<_CharT, _Traits, _Allocator>& |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3207 | > |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3208 | 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] | 3209 | size_type __pos2, size_type __n2) |
| 3210 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 3211 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3212 | size_type __str_sz = __sv.size(); |
| 3213 | if (__pos2 > __str_sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3214 | __throw_out_of_range(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3215 | return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2)); |
| 3216 | } |
| 3217 | |
| 3218 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3219 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3220 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3221 | 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] | 3222 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3223 | _LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3224 | return replace(__pos, __n1, __s, traits_type::length(__s)); |
| 3225 | } |
| 3226 | |
| 3227 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3228 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3229 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3230 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3231 | { |
| 3232 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), |
| 3233 | __str.data(), __str.size()); |
| 3234 | } |
| 3235 | |
| 3236 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3237 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3238 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3239 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3240 | { |
| 3241 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n); |
| 3242 | } |
| 3243 | |
| 3244 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3245 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3246 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3247 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3248 | { |
| 3249 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s); |
| 3250 | } |
| 3251 | |
| 3252 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3253 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3254 | basic_string<_CharT, _Traits, _Allocator>& |
Howard Hinnant | 990d6e8 | 2010-11-17 21:11:40 +0000 | [diff] [blame] | 3255 | basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3256 | { |
| 3257 | return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c); |
| 3258 | } |
| 3259 | |
| 3260 | // erase |
| 3261 | |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3262 | // 'externally instantiated' erase() implementation, called when __n != npos. |
| 3263 | // Does not check __pos against size() |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3264 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3265 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3266 | void |
| 3267 | basic_string<_CharT, _Traits, _Allocator>::__erase_external_with_move( |
| 3268 | size_type __pos, size_type __n) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3269 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3270 | if (__n) |
| 3271 | { |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3272 | size_type __sz = size(); |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 3273 | value_type* __p = _VSTD::__to_address(__get_pointer()); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3274 | __n = _VSTD::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3275 | size_type __n_move = __sz - __pos - __n; |
| 3276 | if (__n_move != 0) |
| 3277 | traits_type::move(__p + __pos, __p + __pos + __n, __n_move); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3278 | __null_terminate_at(__p, __sz - __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3279 | } |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3283 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3284 | basic_string<_CharT, _Traits, _Allocator>& |
| 3285 | basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, |
| 3286 | size_type __n) { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3287 | if (__pos > size()) |
| 3288 | __throw_out_of_range(); |
Martijn Vels | a81fc79 | 2020-02-26 13:25:43 -0500 | [diff] [blame] | 3289 | if (__n == npos) { |
| 3290 | __erase_to_end(__pos); |
| 3291 | } else { |
| 3292 | __erase_external_with_move(__pos, __n); |
| 3293 | } |
| 3294 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3298 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3299 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3300 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos) |
| 3301 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3302 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this, |
| 3303 | "string::erase(iterator) called with an iterator not" |
| 3304 | " referring to this string"); |
| 3305 | |
| 3306 | _LIBCPP_ASSERT(__pos != end(), "string::erase(iterator) called with a non-dereferenceable iterator"); |
| 3307 | iterator __b = begin(); |
| 3308 | size_type __r = static_cast<size_type>(__pos - __b); |
| 3309 | erase(__r, 1); |
| 3310 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3314 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3315 | typename basic_string<_CharT, _Traits, _Allocator>::iterator |
| 3316 | basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last) |
| 3317 | { |
Nikolas Klauser | eed2583 | 2021-12-15 01:32:30 +0100 | [diff] [blame] | 3318 | _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this, |
| 3319 | "string::erase(iterator, iterator) called with an iterator not" |
| 3320 | " referring to this string"); |
| 3321 | |
| 3322 | _LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range"); |
| 3323 | iterator __b = begin(); |
| 3324 | size_type __r = static_cast<size_type>(__first - __b); |
| 3325 | erase(__r, static_cast<size_type>(__last - __first)); |
| 3326 | return __b + static_cast<difference_type>(__r); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3330 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3331 | void |
| 3332 | basic_string<_CharT, _Traits, _Allocator>::pop_back() |
| 3333 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3334 | _LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty"); |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3335 | __erase_to_end(size() - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3339 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3340 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3341 | basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3342 | { |
| 3343 | __invalidate_all_iterators(); |
| 3344 | if (__is_long()) |
| 3345 | { |
| 3346 | traits_type::assign(*__get_long_pointer(), value_type()); |
| 3347 | __set_long_size(0); |
| 3348 | } |
| 3349 | else |
| 3350 | { |
| 3351 | traits_type::assign(*__get_short_pointer(), value_type()); |
| 3352 | __set_short_size(0); |
| 3353 | } |
| 3354 | } |
| 3355 | |
| 3356 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3357 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3358 | void |
| 3359 | basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos) |
| 3360 | { |
Nikolas Klauser | 3ec7fb2 | 2021-12-14 01:20:53 +0100 | [diff] [blame] | 3361 | __null_terminate_at(_VSTD::__to_address(__get_pointer()), __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3362 | } |
| 3363 | |
| 3364 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3365 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3366 | void |
| 3367 | basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c) |
| 3368 | { |
| 3369 | size_type __sz = size(); |
| 3370 | if (__n > __sz) |
| 3371 | append(__n - __sz, __c); |
| 3372 | else |
| 3373 | __erase_to_end(__n); |
| 3374 | } |
| 3375 | |
| 3376 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3377 | _LIBCPP_CONSTEXPR_AFTER_CXX17 inline void |
Eric Fiselier | 451d558 | 2018-11-26 20:15:38 +0000 | [diff] [blame] | 3378 | basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n) |
| 3379 | { |
| 3380 | size_type __sz = size(); |
| 3381 | if (__n > __sz) { |
| 3382 | __append_default_init(__n - __sz); |
| 3383 | } else |
| 3384 | __erase_to_end(__n); |
| 3385 | } |
| 3386 | |
| 3387 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3388 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3389 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3390 | basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3391 | { |
Howard Hinnant | ea8f7e1 | 2010-11-17 17:55:08 +0000 | [diff] [blame] | 3392 | size_type __m = __alloc_traits::max_size(__alloc()); |
Nikolas Klauser | 62060be | 2022-04-20 10:52:04 +0200 | [diff] [blame] | 3393 | if (__m <= std::numeric_limits<size_type>::max() / 2) { |
| 3394 | return __m - __alignment; |
| 3395 | } else { |
| 3396 | bool __uses_lsb = __endian_factor == 2; |
| 3397 | return __uses_lsb ? __m - __alignment : (__m / 2) - __alignment; |
| 3398 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3402 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3403 | void |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3404 | basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3405 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3406 | if (__requested_capacity > max_size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3407 | __throw_length_error(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3408 | |
Louis Dionne | 05b6d3e | 2022-01-14 12:30:22 -0500 | [diff] [blame] | 3409 | // Make sure reserve(n) never shrinks. This is technically only required in C++20 |
| 3410 | // and later (since P0966R1), however we provide consistent behavior in all Standard |
| 3411 | // modes because this function is instantiated in the shared library. |
| 3412 | if (__requested_capacity <= capacity()) |
| 3413 | return; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3414 | |
| 3415 | size_type __target_capacity = _VSTD::max(__requested_capacity, size()); |
| 3416 | __target_capacity = __recommend(__target_capacity); |
| 3417 | if (__target_capacity == capacity()) return; |
| 3418 | |
| 3419 | __shrink_or_extend(__target_capacity); |
| 3420 | } |
| 3421 | |
| 3422 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3423 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3424 | void |
| 3425 | basic_string<_CharT, _Traits, _Allocator>::shrink_to_fit() _NOEXCEPT |
| 3426 | { |
| 3427 | size_type __target_capacity = __recommend(size()); |
| 3428 | if (__target_capacity == capacity()) return; |
| 3429 | |
| 3430 | __shrink_or_extend(__target_capacity); |
| 3431 | } |
| 3432 | |
| 3433 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3434 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3435 | void |
| 3436 | basic_string<_CharT, _Traits, _Allocator>::__shrink_or_extend(size_type __target_capacity) |
| 3437 | { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3438 | size_type __cap = capacity(); |
| 3439 | size_type __sz = size(); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3440 | |
| 3441 | pointer __new_data, __p; |
| 3442 | bool __was_long, __now_long; |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3443 | if (__fits_in_sso(__target_capacity)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3444 | { |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3445 | __was_long = true; |
| 3446 | __now_long = false; |
| 3447 | __new_data = __get_short_pointer(); |
| 3448 | __p = __get_long_pointer(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3449 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3450 | else |
| 3451 | { |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3452 | if (__target_capacity > __cap) { |
| 3453 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3454 | __new_data = __allocation.ptr; |
| 3455 | __target_capacity = __allocation.count - 1; |
| 3456 | } |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3457 | else |
| 3458 | { |
| 3459 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3460 | try |
| 3461 | { |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3462 | #endif // _LIBCPP_NO_EXCEPTIONS |
Nikolas Klauser | c513eba | 2022-04-09 09:41:19 +0200 | [diff] [blame] | 3463 | auto __allocation = std::__allocate_at_least(__alloc(), __target_capacity + 1); |
| 3464 | __new_data = __allocation.ptr; |
| 3465 | __target_capacity = __allocation.count - 1; |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3466 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 3467 | } |
| 3468 | catch (...) |
| 3469 | { |
| 3470 | return; |
| 3471 | } |
| 3472 | #else // _LIBCPP_NO_EXCEPTIONS |
| 3473 | if (__new_data == nullptr) |
| 3474 | return; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3475 | #endif // _LIBCPP_NO_EXCEPTIONS |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3476 | } |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3477 | __begin_lifetime(__new_data, __target_capacity + 1); |
Marek Kurdej | c984814 | 2020-11-26 10:07:16 +0100 | [diff] [blame] | 3478 | __now_long = true; |
| 3479 | __was_long = __is_long(); |
| 3480 | __p = __get_pointer(); |
| 3481 | } |
| 3482 | traits_type::copy(_VSTD::__to_address(__new_data), |
| 3483 | _VSTD::__to_address(__p), size()+1); |
| 3484 | if (__was_long) |
| 3485 | __alloc_traits::deallocate(__alloc(), __p, __cap+1); |
| 3486 | if (__now_long) |
| 3487 | { |
| 3488 | __set_long_cap(__target_capacity+1); |
| 3489 | __set_long_size(__sz); |
| 3490 | __set_long_pointer(__new_data); |
| 3491 | } |
| 3492 | else |
| 3493 | __set_short_size(__sz); |
| 3494 | __invalidate_all_iterators(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3498 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3499 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3500 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3501 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3502 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3503 | return *(data() + __pos); |
| 3504 | } |
| 3505 | |
| 3506 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3507 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3508 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3509 | basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3510 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3511 | _LIBCPP_ASSERT(__pos <= size(), "string index out of bounds"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3512 | return *(__get_pointer() + __pos); |
| 3513 | } |
| 3514 | |
| 3515 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3516 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3517 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
| 3518 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const |
| 3519 | { |
| 3520 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3521 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3522 | return (*this)[__n]; |
| 3523 | } |
| 3524 | |
| 3525 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3526 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3527 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
| 3528 | basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) |
| 3529 | { |
| 3530 | if (__n >= size()) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3531 | __throw_out_of_range(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3532 | return (*this)[__n]; |
| 3533 | } |
| 3534 | |
| 3535 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3536 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3537 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3538 | basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3539 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3540 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3541 | return *__get_pointer(); |
| 3542 | } |
| 3543 | |
| 3544 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3545 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3546 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3547 | basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3548 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3549 | _LIBCPP_ASSERT(!empty(), "string::front(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3550 | return *data(); |
| 3551 | } |
| 3552 | |
| 3553 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3554 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3555 | typename basic_string<_CharT, _Traits, _Allocator>::reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3556 | basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3557 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3558 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3559 | return *(__get_pointer() + size() - 1); |
| 3560 | } |
| 3561 | |
| 3562 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3563 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3564 | typename basic_string<_CharT, _Traits, _Allocator>::const_reference |
Marshall Clow | 05cf669 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 3565 | basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3566 | { |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3567 | _LIBCPP_ASSERT(!empty(), "string::back(): string is empty"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3568 | return *(data() + size() - 1); |
| 3569 | } |
| 3570 | |
| 3571 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3572 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3573 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3574 | 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] | 3575 | { |
| 3576 | size_type __sz = size(); |
| 3577 | if (__pos > __sz) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 3578 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3579 | size_type __rlen = _VSTD::min(__n, __sz - __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3580 | traits_type::copy(__s, data() + __pos, __rlen); |
| 3581 | return __rlen; |
| 3582 | } |
| 3583 | |
| 3584 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3585 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3586 | basic_string<_CharT, _Traits, _Allocator> |
| 3587 | basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const |
| 3588 | { |
| 3589 | return basic_string(*this, __pos, __n, __alloc()); |
| 3590 | } |
| 3591 | |
| 3592 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3593 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3594 | void |
| 3595 | basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str) |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3596 | #if _LIBCPP_STD_VER >= 14 |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3597 | _NOEXCEPT |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3598 | #else |
Eric Fiselier | 873b8d3 | 2019-03-18 21:50:12 +0000 | [diff] [blame] | 3599 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
Marshall Clow | 8982dcd | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 3600 | __is_nothrow_swappable<allocator_type>::value) |
| 3601 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3602 | { |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 3603 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Nikolas Klauser | 1a7d9f0 | 2021-12-16 14:55:03 +0100 | [diff] [blame] | 3604 | if (!__libcpp_is_constant_evaluated()) { |
| 3605 | if (!__is_long()) |
| 3606 | __get_db()->__invalidate_all(this); |
| 3607 | if (!__str.__is_long()) |
| 3608 | __get_db()->__invalidate_all(&__str); |
| 3609 | __get_db()->swap(this, &__str); |
| 3610 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3611 | #endif |
Eric Fiselier | 9bf691f | 2016-12-28 05:53:01 +0000 | [diff] [blame] | 3612 | _LIBCPP_ASSERT( |
| 3613 | __alloc_traits::propagate_on_container_swap::value || |
| 3614 | __alloc_traits::is_always_equal::value || |
| 3615 | __alloc() == __str.__alloc(), "swapping non-equal allocators"); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3616 | _VSTD::swap(__r_.first(), __str.__r_.first()); |
Arthur O'Dwyer | 4e0de31 | 2020-11-18 18:54:38 -0500 | [diff] [blame] | 3617 | _VSTD::__swap_allocator(__alloc(), __str.__alloc()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3618 | } |
| 3619 | |
| 3620 | // find |
| 3621 | |
| 3622 | template <class _Traits> |
| 3623 | struct _LIBCPP_HIDDEN __traits_eq |
| 3624 | { |
| 3625 | typedef typename _Traits::char_type char_type; |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3626 | _LIBCPP_INLINE_VISIBILITY |
| 3627 | bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT |
| 3628 | {return _Traits::eq(__x, __y);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3629 | }; |
| 3630 | |
| 3631 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3632 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3633 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3634 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3635 | size_type __pos, |
| 3636 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3637 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3638 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3639 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3640 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3644 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3645 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3646 | basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str, |
| 3647 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3648 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3649 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3650 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3654 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3655 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3656 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3657 | < |
| 3658 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3659 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3660 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3661 | basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3662 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3663 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3664 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3665 | return __str_find<value_type, size_type, traits_type, npos> |
| 3666 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3667 | } |
| 3668 | |
| 3669 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3670 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3671 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3672 | basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3673 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3674 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3675 | _LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3676 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3677 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3678 | } |
| 3679 | |
| 3680 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3681 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3682 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3683 | basic_string<_CharT, _Traits, _Allocator>::find(value_type __c, |
| 3684 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3685 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3686 | return __str_find<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3687 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3688 | } |
| 3689 | |
| 3690 | // rfind |
| 3691 | |
| 3692 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3693 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3694 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3695 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3696 | size_type __pos, |
| 3697 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3698 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3699 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3700 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3701 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3705 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3706 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3707 | basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str, |
| 3708 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3709 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3710 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3711 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3715 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3716 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3717 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3718 | < |
| 3719 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3720 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3721 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3722 | basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3723 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3724 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3725 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3726 | return __str_rfind<value_type, size_type, traits_type, npos> |
| 3727 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3728 | } |
| 3729 | |
| 3730 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3731 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3732 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3733 | basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3734 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3735 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3736 | _LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3737 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3738 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3742 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3743 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3744 | basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c, |
| 3745 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3746 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3747 | return __str_rfind<value_type, size_type, traits_type, npos> |
Marshall Clow | c527b6e | 2014-06-02 02:22:49 +0000 | [diff] [blame] | 3748 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | // find_first_of |
| 3752 | |
| 3753 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3754 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3755 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3756 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3757 | size_type __pos, |
| 3758 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3759 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3760 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3761 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3762 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3763 | } |
| 3764 | |
| 3765 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3766 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3767 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3768 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str, |
| 3769 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3770 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3771 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3772 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3776 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3777 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3778 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3779 | < |
| 3780 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3781 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3782 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3783 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3784 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3785 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3786 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3787 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
| 3788 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3789 | } |
| 3790 | |
| 3791 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3792 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3793 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3794 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3795 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3796 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3797 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3798 | return __str_find_first_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3799 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3803 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3804 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3805 | basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c, |
| 3806 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3807 | { |
| 3808 | return find(__c, __pos); |
| 3809 | } |
| 3810 | |
| 3811 | // find_last_of |
| 3812 | |
| 3813 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3814 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3815 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3816 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3817 | size_type __pos, |
| 3818 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3819 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3820 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3821 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3822 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3826 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3827 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3828 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str, |
| 3829 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3830 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3831 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3832 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3833 | } |
| 3834 | |
| 3835 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3836 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3837 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3838 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3839 | < |
| 3840 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3841 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3842 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3843 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3844 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3845 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3846 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3847 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
| 3848 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3849 | } |
| 3850 | |
| 3851 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3852 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3853 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3854 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3855 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3856 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3857 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3858 | return __str_find_last_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3859 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3863 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3864 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3865 | basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c, |
| 3866 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3867 | { |
| 3868 | return rfind(__c, __pos); |
| 3869 | } |
| 3870 | |
| 3871 | // find_first_not_of |
| 3872 | |
| 3873 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3874 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3875 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3876 | 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] | 3877 | size_type __pos, |
| 3878 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3879 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3880 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3881 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3882 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3883 | } |
| 3884 | |
| 3885 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3886 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3887 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3888 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str, |
| 3889 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3890 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3891 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3892 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3893 | } |
| 3894 | |
| 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 | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3897 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
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 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3902 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3903 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3904 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3905 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3906 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3907 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
| 3908 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3909 | } |
| 3910 | |
| 3911 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3912 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3913 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3914 | 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] | 3915 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3916 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3917 | _LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3918 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3919 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3923 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3924 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3925 | basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c, |
| 3926 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3927 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3928 | return __str_find_first_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3929 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | // find_last_not_of |
| 3933 | |
| 3934 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3935 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3936 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3937 | 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] | 3938 | size_type __pos, |
| 3939 | size_type __n) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3940 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3941 | _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3942 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3943 | (data(), size(), __s, __pos, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3944 | } |
| 3945 | |
| 3946 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3947 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3948 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3949 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str, |
| 3950 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3951 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3952 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3953 | (data(), size(), __str.data(), __pos, __str.size()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3954 | } |
| 3955 | |
| 3956 | template<class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3957 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3958 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3959 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3960 | < |
| 3961 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 3962 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 3963 | > |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3964 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t, |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 3965 | size_type __pos) const _NOEXCEPT |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3966 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3967 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3968 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
| 3969 | (data(), size(), __sv.data(), __pos, __sv.size()); |
| 3970 | } |
| 3971 | |
| 3972 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3973 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3974 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 3975 | 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] | 3976 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3977 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 3978 | _LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr"); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3979 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3980 | (data(), size(), __s, __pos, traits_type::length(__s)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3984 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3985 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 3986 | basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c, |
| 3987 | size_type __pos) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3988 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 3989 | return __str_find_last_not_of<value_type, size_type, traits_type, npos> |
Marshall Clow | 4bc2be2 | 2014-02-16 01:57:26 +0000 | [diff] [blame] | 3990 | (data(), size(), __c, __pos); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | // compare |
| 3994 | |
| 3995 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3996 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 3997 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 3998 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 3999 | < |
| 4000 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 4001 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 4002 | > |
zoecarver | 1997e0a | 2021-02-05 11:54:47 -0800 | [diff] [blame] | 4003 | basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4004 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 4005 | __self_view __sv = __t; |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 4006 | size_t __lhs_sz = size(); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4007 | size_t __rhs_sz = __sv.size(); |
| 4008 | int __result = traits_type::compare(data(), __sv.data(), |
Howard Hinnant | b048553 | 2011-07-24 21:45:06 +0000 | [diff] [blame] | 4009 | _VSTD::min(__lhs_sz, __rhs_sz)); |
| 4010 | if (__result != 0) |
| 4011 | return __result; |
| 4012 | if (__lhs_sz < __rhs_sz) |
| 4013 | return -1; |
| 4014 | if (__lhs_sz > __rhs_sz) |
| 4015 | return 1; |
| 4016 | return 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4020 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4021 | int |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4022 | basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4023 | { |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4024 | return compare(__self_view(__str)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4025 | } |
| 4026 | |
| 4027 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4028 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4029 | int |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4030 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4031 | size_type __n1, |
Howard Hinnant | d17880b | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 4032 | const value_type* __s, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4033 | size_type __n2) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4034 | { |
Alp Toker | b8a95f5 | 2014-05-15 11:27:39 +0000 | [diff] [blame] | 4035 | _LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4036 | size_type __sz = size(); |
| 4037 | if (__pos1 > __sz || __n2 == npos) |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4038 | __throw_out_of_range(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4039 | size_type __rlen = _VSTD::min(__n1, __sz - __pos1); |
| 4040 | int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4041 | if (__r == 0) |
| 4042 | { |
| 4043 | if (__rlen < __n2) |
| 4044 | __r = -1; |
| 4045 | else if (__rlen > __n2) |
| 4046 | __r = 1; |
| 4047 | } |
| 4048 | return __r; |
| 4049 | } |
| 4050 | |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4051 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 4052 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4053 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 4054 | __enable_if_t |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 4055 | < |
| 4056 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, |
| 4057 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 4058 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4059 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4060 | size_type __n1, |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 4061 | const _Tp& __t) const |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4062 | { |
Marshall Clow | e46031a | 2018-07-02 18:41:15 +0000 | [diff] [blame] | 4063 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4064 | return compare(__pos1, __n1, __sv.data(), __sv.size()); |
| 4065 | } |
| 4066 | |
| 4067 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4068 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4069 | int |
| 4070 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4071 | size_type __n1, |
| 4072 | const basic_string& __str) const |
| 4073 | { |
| 4074 | return compare(__pos1, __n1, __str.data(), __str.size()); |
| 4075 | } |
| 4076 | |
| 4077 | template <class _CharT, class _Traits, class _Allocator> |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4078 | template <class _Tp> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4079 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 9ce598d | 2021-09-08 09:14:43 -0400 | [diff] [blame] | 4080 | __enable_if_t |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4081 | < |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 4082 | __can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value |
| 4083 | && !__is_same_uncvref<_Tp, basic_string<_CharT, _Traits, _Allocator> >::value, |
Marshall Clow | b7db497 | 2017-11-15 20:02:27 +0000 | [diff] [blame] | 4084 | int |
Eric Fiselier | c522ceb | 2020-01-15 16:57:08 -0500 | [diff] [blame] | 4085 | > |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4086 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4087 | size_type __n1, |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4088 | const _Tp& __t, |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4089 | size_type __pos2, |
| 4090 | size_type __n2) const |
| 4091 | { |
Marshall Clow | 8251334 | 2016-09-24 22:45:42 +0000 | [diff] [blame] | 4092 | __self_view __sv = __t; |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4093 | return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 4094 | } |
| 4095 | |
| 4096 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4097 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4098 | int |
| 4099 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4100 | size_type __n1, |
| 4101 | const basic_string& __str, |
| 4102 | size_type __pos2, |
| 4103 | size_type __n2) const |
| 4104 | { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4105 | return compare(__pos1, __n1, __self_view(__str), __pos2, __n2); |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4109 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4110 | int |
| 4111 | basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT |
| 4112 | { |
| 4113 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4114 | return compare(0, npos, __s, traits_type::length(__s)); |
| 4115 | } |
| 4116 | |
| 4117 | template <class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4118 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | df63a6d | 2016-07-21 05:31:24 +0000 | [diff] [blame] | 4119 | int |
| 4120 | basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1, |
| 4121 | size_type __n1, |
| 4122 | const value_type* __s) const |
| 4123 | { |
| 4124 | _LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr"); |
| 4125 | return compare(__pos1, __n1, __s, traits_type::length(__s)); |
| 4126 | } |
| 4127 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4128 | // __invariants |
| 4129 | |
| 4130 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4131 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4132 | bool |
| 4133 | basic_string<_CharT, _Traits, _Allocator>::__invariants() const |
| 4134 | { |
| 4135 | if (size() > capacity()) |
| 4136 | return false; |
| 4137 | if (capacity() < __min_cap - 1) |
| 4138 | return false; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4139 | if (data() == nullptr) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4140 | return false; |
Louis Dionne | 663415f | 2020-10-05 16:16:13 -0400 | [diff] [blame] | 4141 | if (data()[size()] != value_type()) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4142 | return false; |
| 4143 | return true; |
| 4144 | } |
| 4145 | |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4146 | // __clear_and_shrink |
| 4147 | |
| 4148 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4149 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4150 | void |
Marshall Clow | e60a718 | 2018-05-29 17:04:37 +0000 | [diff] [blame] | 4151 | basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4152 | { |
| 4153 | clear(); |
| 4154 | if(__is_long()) |
| 4155 | { |
| 4156 | __alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); |
| 4157 | __set_long_cap(0); |
| 4158 | __set_short_size(0); |
Louis Dionne | 663415f | 2020-10-05 16:16:13 -0400 | [diff] [blame] | 4159 | traits_type::assign(*__get_short_pointer(), value_type()); |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4160 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4161 | } |
Vedant Kumar | 55e007e | 2018-03-08 21:15:26 +0000 | [diff] [blame] | 4162 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4163 | // operator== |
| 4164 | |
| 4165 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4166 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4167 | bool |
| 4168 | operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4169 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4170 | { |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4171 | size_t __lhs_sz = __lhs.size(); |
| 4172 | return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(), |
| 4173 | __rhs.data(), |
| 4174 | __lhs_sz) == 0; |
| 4175 | } |
| 4176 | |
| 4177 | template<class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4178 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aaeb113 | 2013-04-22 23:55:13 +0000 | [diff] [blame] | 4179 | bool |
| 4180 | operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs, |
| 4181 | const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT |
| 4182 | { |
| 4183 | size_t __lhs_sz = __lhs.size(); |
| 4184 | if (__lhs_sz != __rhs.size()) |
| 4185 | return false; |
| 4186 | const char* __lp = __lhs.data(); |
| 4187 | const char* __rp = __rhs.data(); |
| 4188 | if (__lhs.__is_long()) |
| 4189 | return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0; |
| 4190 | for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp) |
| 4191 | if (*__lp != *__rp) |
| 4192 | return false; |
| 4193 | return true; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4194 | } |
| 4195 | |
| 4196 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4197 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
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 | { |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4202 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4203 | _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); |
| 4204 | size_t __lhs_len = _Traits::length(__lhs); |
| 4205 | if (__lhs_len != __rhs.size()) return false; |
| 4206 | return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4207 | } |
| 4208 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4209 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4210 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4211 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4212 | operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
| 4213 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4214 | { |
Eric Fiselier | 0cafa3f | 2015-08-28 03:02:37 +0000 | [diff] [blame] | 4215 | typedef basic_string<_CharT, _Traits, _Allocator> _String; |
| 4216 | _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); |
| 4217 | size_t __rhs_len = _Traits::length(__rhs); |
| 4218 | if (__rhs_len != __lhs.size()) return false; |
| 4219 | return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4220 | } |
| 4221 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4222 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4223 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4224 | bool |
| 4225 | operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4226 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4227 | { |
| 4228 | return !(__lhs == __rhs); |
| 4229 | } |
| 4230 | |
| 4231 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4232 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4233 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4234 | operator!=(const _CharT* __lhs, |
| 4235 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4236 | { |
| 4237 | return !(__lhs == __rhs); |
| 4238 | } |
| 4239 | |
| 4240 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4241 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4242 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4243 | operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4244 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4245 | { |
| 4246 | return !(__lhs == __rhs); |
| 4247 | } |
| 4248 | |
| 4249 | // operator< |
| 4250 | |
| 4251 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4252 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4253 | bool |
| 4254 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4255 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4256 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4257 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4261 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4262 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4263 | operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4264 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4265 | { |
Howard Hinnant | a2660c1 | 2011-07-24 15:07:21 +0000 | [diff] [blame] | 4266 | return __lhs.compare(__rhs) < 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4267 | } |
| 4268 | |
| 4269 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4270 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4271 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4272 | operator< (const _CharT* __lhs, |
| 4273 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4274 | { |
| 4275 | return __rhs.compare(__lhs) > 0; |
| 4276 | } |
| 4277 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4278 | // operator> |
| 4279 | |
| 4280 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4281 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4282 | bool |
| 4283 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4284 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4285 | { |
| 4286 | return __rhs < __lhs; |
| 4287 | } |
| 4288 | |
| 4289 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4290 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4291 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4292 | operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4293 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4294 | { |
| 4295 | return __rhs < __lhs; |
| 4296 | } |
| 4297 | |
| 4298 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4299 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4300 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4301 | operator> (const _CharT* __lhs, |
| 4302 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4303 | { |
| 4304 | return __rhs < __lhs; |
| 4305 | } |
| 4306 | |
| 4307 | // operator<= |
| 4308 | |
| 4309 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4310 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4311 | bool |
| 4312 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4313 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4314 | { |
| 4315 | return !(__rhs < __lhs); |
| 4316 | } |
| 4317 | |
| 4318 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4319 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4320 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4321 | operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4322 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4323 | { |
| 4324 | return !(__rhs < __lhs); |
| 4325 | } |
| 4326 | |
| 4327 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4328 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4329 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4330 | operator<=(const _CharT* __lhs, |
| 4331 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4332 | { |
| 4333 | return !(__rhs < __lhs); |
| 4334 | } |
| 4335 | |
| 4336 | // operator>= |
| 4337 | |
| 4338 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4339 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4340 | bool |
| 4341 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4342 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4343 | { |
| 4344 | return !(__lhs < __rhs); |
| 4345 | } |
| 4346 | |
| 4347 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4348 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4349 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4350 | operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4351 | const _CharT* __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4352 | { |
| 4353 | return !(__lhs < __rhs); |
| 4354 | } |
| 4355 | |
| 4356 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4357 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4358 | bool |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4359 | operator>=(const _CharT* __lhs, |
| 4360 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4361 | { |
| 4362 | return !(__lhs < __rhs); |
| 4363 | } |
| 4364 | |
| 4365 | // operator + |
| 4366 | |
| 4367 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4368 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4369 | basic_string<_CharT, _Traits, _Allocator> |
| 4370 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, |
| 4371 | const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4372 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4373 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4374 | auto __lhs_sz = __lhs.size(); |
| 4375 | auto __rhs_sz = __rhs.size(); |
| 4376 | _String __r(__uninitialized_size_tag(), |
| 4377 | __lhs_sz + __rhs_sz, |
| 4378 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4379 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4380 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4381 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4382 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4383 | return __r; |
| 4384 | } |
| 4385 | |
| 4386 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4387 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4388 | basic_string<_CharT, _Traits, _Allocator> |
| 4389 | operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4390 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4391 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4392 | auto __lhs_sz = _Traits::length(__lhs); |
| 4393 | auto __rhs_sz = __rhs.size(); |
| 4394 | _String __r(__uninitialized_size_tag(), |
| 4395 | __lhs_sz + __rhs_sz, |
| 4396 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4397 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4398 | _Traits::copy(__ptr, __lhs, __lhs_sz); |
| 4399 | _Traits::copy(__ptr + __lhs_sz, __rhs.data(), __rhs_sz); |
| 4400 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4401 | return __r; |
| 4402 | } |
| 4403 | |
| 4404 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4405 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4406 | basic_string<_CharT, _Traits, _Allocator> |
| 4407 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs) |
| 4408 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4409 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4410 | typename _String::size_type __rhs_sz = __rhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4411 | _String __r(__uninitialized_size_tag(), |
| 4412 | __rhs_sz + 1, |
| 4413 | _String::__alloc_traits::select_on_container_copy_construction(__rhs.get_allocator())); |
| 4414 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4415 | _Traits::assign(__ptr, 1, __lhs); |
| 4416 | _Traits::copy(__ptr + 1, __rhs.data(), __rhs_sz); |
| 4417 | _Traits::assign(__ptr + 1 + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4418 | return __r; |
| 4419 | } |
| 4420 | |
| 4421 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4422 | inline _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4423 | basic_string<_CharT, _Traits, _Allocator> |
| 4424 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs) |
| 4425 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4426 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4427 | typename _String::size_type __lhs_sz = __lhs.size(); |
| 4428 | typename _String::size_type __rhs_sz = _Traits::length(__rhs); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4429 | _String __r(__uninitialized_size_tag(), |
| 4430 | __lhs_sz + __rhs_sz, |
| 4431 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4432 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4433 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4434 | _Traits::copy(__ptr + __lhs_sz, __rhs, __rhs_sz); |
| 4435 | _Traits::assign(__ptr + __lhs_sz + __rhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4436 | return __r; |
| 4437 | } |
| 4438 | |
| 4439 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4440 | _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4441 | basic_string<_CharT, _Traits, _Allocator> |
| 4442 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs) |
| 4443 | { |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4444 | using _String = basic_string<_CharT, _Traits, _Allocator>; |
Nikolas Klauser | 38631bf | 2022-02-11 19:24:31 +0100 | [diff] [blame] | 4445 | typename _String::size_type __lhs_sz = __lhs.size(); |
Nikolas Klauser | 55dc808 | 2022-04-09 16:19:45 +0200 | [diff] [blame] | 4446 | _String __r(__uninitialized_size_tag(), |
| 4447 | __lhs_sz + 1, |
| 4448 | _String::__alloc_traits::select_on_container_copy_construction(__lhs.get_allocator())); |
| 4449 | auto __ptr = std::__to_address(__r.__get_pointer()); |
| 4450 | _Traits::copy(__ptr, __lhs.data(), __lhs_sz); |
| 4451 | _Traits::assign(__ptr + __lhs_sz, 1, __rhs); |
| 4452 | _Traits::assign(__ptr + 1 + __lhs_sz, 1, _CharT()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4453 | return __r; |
| 4454 | } |
| 4455 | |
Eric Fiselier | fc92be8 | 2017-04-19 00:28:44 +0000 | [diff] [blame] | 4456 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4457 | |
| 4458 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4459 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4460 | basic_string<_CharT, _Traits, _Allocator> |
| 4461 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4462 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4463 | return _VSTD::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4464 | } |
| 4465 | |
| 4466 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4467 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4468 | basic_string<_CharT, _Traits, _Allocator> |
| 4469 | operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4470 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4471 | return _VSTD::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4475 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4476 | basic_string<_CharT, _Traits, _Allocator> |
| 4477 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs) |
| 4478 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4479 | return _VSTD::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
| 4482 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4483 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4484 | basic_string<_CharT, _Traits, _Allocator> |
| 4485 | operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4486 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4487 | return _VSTD::move(__rhs.insert(0, __lhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4491 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4492 | basic_string<_CharT, _Traits, _Allocator> |
| 4493 | operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs) |
| 4494 | { |
| 4495 | __rhs.insert(__rhs.begin(), __lhs); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4496 | return _VSTD::move(__rhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4500 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4501 | basic_string<_CharT, _Traits, _Allocator> |
| 4502 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs) |
| 4503 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4504 | return _VSTD::move(__lhs.append(__rhs)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4508 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4509 | basic_string<_CharT, _Traits, _Allocator> |
| 4510 | operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs) |
| 4511 | { |
| 4512 | __lhs.push_back(__rhs); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4513 | return _VSTD::move(__lhs); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4516 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4517 | |
| 4518 | // swap |
| 4519 | |
| 4520 | template<class _CharT, class _Traits, class _Allocator> |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4521 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4522 | void |
Howard Hinnant | aeb17d8 | 2011-05-29 19:57:12 +0000 | [diff] [blame] | 4523 | swap(basic_string<_CharT, _Traits, _Allocator>& __lhs, |
Howard Hinnant | 3e27687 | 2011-06-03 18:40:47 +0000 | [diff] [blame] | 4524 | basic_string<_CharT, _Traits, _Allocator>& __rhs) |
| 4525 | _NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs))) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4526 | { |
| 4527 | __lhs.swap(__rhs); |
| 4528 | } |
| 4529 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4530 | _LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4531 | _LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4532 | _LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4533 | _LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = nullptr, int __base = 10); |
| 4534 | _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] | 4535 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4536 | _LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = nullptr); |
| 4537 | _LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = nullptr); |
| 4538 | _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] | 4539 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4540 | _LIBCPP_FUNC_VIS string to_string(int __val); |
| 4541 | _LIBCPP_FUNC_VIS string to_string(unsigned __val); |
| 4542 | _LIBCPP_FUNC_VIS string to_string(long __val); |
| 4543 | _LIBCPP_FUNC_VIS string to_string(unsigned long __val); |
| 4544 | _LIBCPP_FUNC_VIS string to_string(long long __val); |
| 4545 | _LIBCPP_FUNC_VIS string to_string(unsigned long long __val); |
| 4546 | _LIBCPP_FUNC_VIS string to_string(float __val); |
| 4547 | _LIBCPP_FUNC_VIS string to_string(double __val); |
| 4548 | _LIBCPP_FUNC_VIS string to_string(long double __val); |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4549 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4550 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4551 | _LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4552 | _LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4553 | _LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4554 | _LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = nullptr, int __base = 10); |
| 4555 | _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] | 4556 | |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 4557 | _LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = nullptr); |
| 4558 | _LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = nullptr); |
| 4559 | _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] | 4560 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4561 | _LIBCPP_FUNC_VIS wstring to_wstring(int __val); |
| 4562 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val); |
| 4563 | _LIBCPP_FUNC_VIS wstring to_wstring(long __val); |
| 4564 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val); |
| 4565 | _LIBCPP_FUNC_VIS wstring to_wstring(long long __val); |
| 4566 | _LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val); |
| 4567 | _LIBCPP_FUNC_VIS wstring to_wstring(float __val); |
| 4568 | _LIBCPP_FUNC_VIS wstring to_wstring(double __val); |
| 4569 | _LIBCPP_FUNC_VIS wstring to_wstring(long double __val); |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4570 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a5f4f8e | 2010-06-02 18:20:39 +0000 | [diff] [blame] | 4571 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4572 | template<class _CharT, class _Traits, class _Allocator> |
Martin Storsjö | 88890c2 | 2021-02-22 01:13:13 +0200 | [diff] [blame] | 4573 | _LIBCPP_TEMPLATE_DATA_VIS |
Eric Fiselier | c9fdaf1 | 2020-01-15 17:02:17 -0500 | [diff] [blame] | 4574 | const typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4575 | basic_string<_CharT, _Traits, _Allocator>::npos; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4576 | |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4577 | template <class _CharT, class _Allocator> |
| 4578 | struct _LIBCPP_TEMPLATE_VIS |
| 4579 | hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> > |
| 4580 | : public unary_function< |
| 4581 | basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4582 | { |
| 4583 | size_t |
Marshall Clow | 851b9ec | 2019-05-20 21:56:51 +0000 | [diff] [blame] | 4584 | operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT |
| 4585 | { return __do_string_hash(__val.data(), __val.data() + __val.size()); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4586 | }; |
| 4587 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4588 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4589 | template<class _CharT, class _Traits, class _Allocator> |
| 4590 | basic_ostream<_CharT, _Traits>& |
| 4591 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4592 | const basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4593 | |
| 4594 | template<class _CharT, class _Traits, class _Allocator> |
| 4595 | basic_istream<_CharT, _Traits>& |
| 4596 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4597 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4598 | |
| 4599 | template<class _CharT, class _Traits, class _Allocator> |
| 4600 | basic_istream<_CharT, _Traits>& |
| 4601 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4602 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4603 | |
| 4604 | template<class _CharT, class _Traits, class _Allocator> |
| 4605 | inline _LIBCPP_INLINE_VISIBILITY |
| 4606 | basic_istream<_CharT, _Traits>& |
| 4607 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4608 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4609 | |
Howard Hinnant | dc09597 | 2011-07-18 15:51:59 +0000 | [diff] [blame] | 4610 | template<class _CharT, class _Traits, class _Allocator> |
| 4611 | inline _LIBCPP_INLINE_VISIBILITY |
| 4612 | basic_istream<_CharT, _Traits>& |
| 4613 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4614 | basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm); |
| 4615 | |
| 4616 | template<class _CharT, class _Traits, class _Allocator> |
| 4617 | inline _LIBCPP_INLINE_VISIBILITY |
| 4618 | basic_istream<_CharT, _Traits>& |
| 4619 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4620 | basic_string<_CharT, _Traits, _Allocator>& __str); |
| 4621 | |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4622 | #if _LIBCPP_STD_VER > 17 |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4623 | template <class _CharT, class _Traits, class _Allocator, class _Up> |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4624 | inline _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4625 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4626 | erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v) { |
| 4627 | auto __old_size = __str.size(); |
| 4628 | __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); |
| 4629 | return __old_size - __str.size(); |
| 4630 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4631 | |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4632 | template <class _CharT, class _Traits, class _Allocator, class _Predicate> |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4633 | inline _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | a98b141 | 2020-05-02 13:58:03 +0200 | [diff] [blame] | 4634 | typename basic_string<_CharT, _Traits, _Allocator>::size_type |
| 4635 | erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, |
| 4636 | _Predicate __pred) { |
| 4637 | auto __old_size = __str.size(); |
| 4638 | __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), |
| 4639 | __str.end()); |
| 4640 | return __old_size - __str.size(); |
| 4641 | } |
Marshall Clow | 29b53f2 | 2018-12-14 18:49:35 +0000 | [diff] [blame] | 4642 | #endif |
| 4643 | |
Louis Dionne | ba40078 | 2020-10-02 15:02:52 -0400 | [diff] [blame] | 4644 | #if _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4645 | |
| 4646 | template<class _CharT, class _Traits, class _Allocator> |
| 4647 | bool |
| 4648 | basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const |
| 4649 | { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4650 | return data() <= _VSTD::__to_address(__i->base()) && |
| 4651 | _VSTD::__to_address(__i->base()) < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | template<class _CharT, class _Traits, class _Allocator> |
| 4655 | bool |
| 4656 | basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const |
| 4657 | { |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4658 | return data() < _VSTD::__to_address(__i->base()) && |
| 4659 | _VSTD::__to_address(__i->base()) <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | template<class _CharT, class _Traits, class _Allocator> |
| 4663 | bool |
| 4664 | basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 4665 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 4666 | const value_type* __p = _VSTD::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4667 | return data() <= __p && __p <= data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | template<class _CharT, class _Traits, class _Allocator> |
| 4671 | bool |
| 4672 | basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 4673 | { |
Eric Fiselier | c1b87a7 | 2019-11-16 17:13:26 -0500 | [diff] [blame] | 4674 | const value_type* __p = _VSTD::__to_address(__i->base()) + __n; |
Nikolas Klauser | 00ba7f8 | 2021-12-28 13:09:40 +0100 | [diff] [blame] | 4675 | return data() <= __p && __p < data() + size(); |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4676 | } |
| 4677 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4678 | #endif // _LIBCPP_DEBUG_LEVEL == 2 |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 4679 | |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4680 | #if _LIBCPP_STD_VER > 11 |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4681 | // Literal suffixes for basic_string [basic.string.literals] |
Marshall Clow | ac86837 | 2013-10-05 21:18:32 +0000 | [diff] [blame] | 4682 | inline namespace literals |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4683 | { |
| 4684 | inline namespace string_literals |
| 4685 | { |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4686 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4687 | basic_string<char> operator "" s( const char *__str, size_t __len ) |
| 4688 | { |
| 4689 | return basic_string<char> (__str, __len); |
| 4690 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4691 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4692 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4693 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4694 | basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len ) |
| 4695 | { |
| 4696 | return basic_string<wchar_t> (__str, __len); |
| 4697 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4698 | #endif |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4699 | |
Arthur O'Dwyer | afa5d5f | 2021-04-18 21:47:08 -0400 | [diff] [blame] | 4700 | #ifndef _LIBCPP_HAS_NO_CHAR8_T |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4701 | inline _LIBCPP_INLINE_VISIBILITY constexpr |
Marshall Clow | 8732fed | 2018-12-11 04:35:44 +0000 | [diff] [blame] | 4702 | basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT |
| 4703 | { |
| 4704 | return basic_string<char8_t> (__str, __len); |
| 4705 | } |
| 4706 | #endif |
| 4707 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4708 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4709 | basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len ) |
| 4710 | { |
| 4711 | return basic_string<char16_t> (__str, __len); |
| 4712 | } |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4713 | |
Nikolas Klauser | 80b3cf3 | 2022-04-27 10:11:44 +0200 | [diff] [blame^] | 4714 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | 5c16756 | 2013-08-07 19:39:48 +0000 | [diff] [blame] | 4715 | basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len ) |
| 4716 | { |
| 4717 | return basic_string<char32_t> (__str, __len); |
| 4718 | } |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 4719 | } // namespace string_literals |
| 4720 | } // namespace literals |
Mark de Wever | df3e0d4 | 2021-09-26 15:47:42 +0200 | [diff] [blame] | 4721 | |
| 4722 | #if _LIBCPP_STD_VER > 17 |
| 4723 | template <> |
| 4724 | inline constexpr bool __format::__enable_insertable<std::basic_string<char>> = true; |
| 4725 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4726 | template <> |
| 4727 | inline constexpr bool __format::__enable_insertable<std::basic_string<wchar_t>> = true; |
| 4728 | #endif |
| 4729 | #endif |
| 4730 | |
Marshall Clow | cba751f | 2013-07-23 17:05:24 +0000 | [diff] [blame] | 4731 | #endif |
| 4732 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4733 | _LIBCPP_END_NAMESPACE_STD |
| 4734 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 4735 | _LIBCPP_POP_MACROS |
| 4736 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 4737 | #endif // _LIBCPP_STRING |