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