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