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