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