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