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