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