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