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