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