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