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