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