Where Online Learning is simpler!
The C and C++ Include Header Files
/usr/include/c++/13/ext/vstring.h
$ cat -n /usr/include/c++/13/ext/vstring.h 1 // Versatile string -*- C++ -*- 2 3 // Copyright (C) 2005-2023 Free Software Foundation, Inc. 4 // 5 // This file is part of the GNU ISO C++ Library. This library is free 6 // software; you can redistribute it and/or modify it under the 7 // terms of the GNU General Public License as published by the 8 // Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 11 // This library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 16 // Under Section 7 of GPL version 3, you are granted additional 17 // permissions described in the GCC Runtime Library Exception, version 18 // 3.1, as published by the Free Software Foundation. 19 20 // You should have received a copy of the GNU General Public License and 21 // a copy of the GCC Runtime Library Exception along with this program; 22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 //
. 24 25 /** @file ext/vstring.h 26 * This file is a GNU extension to the Standard C++ Library. 27 */ 28 29 #ifndef _VSTRING_H 30 #define _VSTRING_H 1 31 32 #pragma GCC system_header 33 34 #include
// GNU extensions are currently omitted 35 36 #if __cplusplus >= 201103L 37 #include
38 #endif 39 40 #include
41 #include
42 #include
43 #include
// std::min 44 45 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 46 { 47 _GLIBCXX_BEGIN_NAMESPACE_VERSION 48 49 /** 50 * @class __versa_string vstring.h 51 * @brief Template class __versa_string. 52 * @ingroup extensions 53 * 54 * Data structure managing sequences of characters and 55 * character-like objects. 56 */ 57 template
class _Base> 59 class __versa_string 60 : private _Base<_CharT, _Traits, _Alloc> 61 { 62 typedef _Base<_CharT, _Traits, _Alloc> __vstring_base; 63 typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type; 64 typedef __alloc_traits<_CharT_alloc_type> _CharT_alloc_traits; 65 66 // Types: 67 public: 68 typedef _Traits traits_type; 69 typedef typename _Traits::char_type value_type; 70 typedef _Alloc allocator_type; 71 typedef typename _CharT_alloc_type::size_type size_type; 72 typedef typename _CharT_alloc_type::difference_type difference_type; 73 typedef value_type& reference; 74 typedef const value_type& const_reference; 75 typedef typename _CharT_alloc_traits::pointer pointer; 76 typedef typename _CharT_alloc_traits::const_pointer const_pointer; 77 typedef __gnu_cxx::__normal_iterator
iterator; 78 typedef __gnu_cxx::__normal_iterator
79 const_iterator; 80 typedef std::reverse_iterator
const_reverse_iterator; 81 typedef std::reverse_iterator
reverse_iterator; 82 83 // Data Member (public): 84 /// Value returned by various member functions when they fail. 85 static const size_type npos = static_cast
(-1); 86 87 private: 88 size_type 89 _M_check(size_type __pos, const char* __s) const 90 { 91 if (__pos > this->size()) 92 std::__throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " 93 "this->size() (which is %zu)"), 94 __s, __pos, this->size()); 95 return __pos; 96 } 97 98 void 99 _M_check_length(size_type __n1, size_type __n2, const char* __s) const 100 { 101 if (this->max_size() - (this->size() - __n1) < __n2) 102 std::__throw_length_error(__N(__s)); 103 } 104 105 // NB: _M_limit doesn't check for a bad __pos value. 106 size_type 107 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT 108 { 109 const bool __testoff = __off < this->size() - __pos; 110 return __testoff ? __off : this->size() - __pos; 111 } 112 113 // True if _Rep and source do not overlap. 114 bool 115 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT 116 { 117 return (std::less
()(__s, this->_M_data()) 118 || std::less
()(this->_M_data() 119 + this->size(), __s)); 120 } 121 122 // For the internal use we have functions similar to `begin'/`end' 123 // but they do not call _M_leak. 124 iterator 125 _M_ibegin() const _GLIBCXX_NOEXCEPT 126 { return iterator(this->_M_data()); } 127 128 iterator 129 _M_iend() const _GLIBCXX_NOEXCEPT 130 { return iterator(this->_M_data() + this->_M_length()); } 131 132 public: 133 // Construct/copy/destroy: 134 // NB: We overload ctors in some cases instead of using default 135 // arguments, per 17.4.4.4 para. 2 item 2. 136 137 /** 138 * @brief Construct an empty string using allocator @a a. 139 */ 140 explicit 141 __versa_string(const _Alloc& __a = _Alloc()) _GLIBCXX_NOEXCEPT 142 : __vstring_base(__a) { } 143 144 // NB: per LWG issue 42, semantics different from IS: 145 /** 146 * @brief Construct string with copy of value of @a __str. 147 * @param __str Source string. 148 */ 149 __versa_string(const __versa_string& __str) 150 : __vstring_base(__str) { } 151 152 #if __cplusplus >= 201103L 153 /** 154 * @brief String move constructor. 155 * @param __str Source string. 156 * 157 * The newly-constructed %string contains the exact contents of 158 * @a __str. The contents of @a __str are a valid, but unspecified 159 * string. 160 */ 161 __versa_string(__versa_string&& __str) noexcept 162 : __vstring_base(std::move(__str)) { } 163 164 /** 165 * @brief Construct string from an initializer list. 166 * @param __l std::initializer_list of characters. 167 * @param __a Allocator to use (default is default allocator). 168 */ 169 __versa_string(std::initializer_list<_CharT> __l, 170 const _Alloc& __a = _Alloc()) 171 : __vstring_base(__l.begin(), __l.end(), __a) { } 172 #endif 173 174 /** 175 * @brief Construct string as copy of a substring. 176 * @param __str Source string. 177 * @param __pos Index of first character to copy from. 178 * @param __n Number of characters to copy (default remainder). 179 */ 180 __versa_string(const __versa_string& __str, size_type __pos, 181 size_type __n = npos) 182 : __vstring_base(__str._M_data() 183 + __str._M_check(__pos, 184 "__versa_string::__versa_string"), 185 __str._M_data() + __str._M_limit(__pos, __n) 186 + __pos, _Alloc()) { } 187 188 /** 189 * @brief Construct string as copy of a substring. 190 * @param __str Source string. 191 * @param __pos Index of first character to copy from. 192 * @param __n Number of characters to copy. 193 * @param __a Allocator to use. 194 */ 195 __versa_string(const __versa_string& __str, size_type __pos, 196 size_type __n, const _Alloc& __a) 197 : __vstring_base(__str._M_data() 198 + __str._M_check(__pos, 199 "__versa_string::__versa_string"), 200 __str._M_data() + __str._M_limit(__pos, __n) 201 + __pos, __a) { } 202 203 /** 204 * @brief Construct string initialized by a character array. 205 * @param __s Source character array. 206 * @param __n Number of characters to copy. 207 * @param __a Allocator to use (default is default allocator). 208 * 209 * NB: @a __s must have at least @a __n characters, '\\0' has no special 210 * meaning. 211 */ 212 __versa_string(const _CharT* __s, size_type __n, 213 const _Alloc& __a = _Alloc()) 214 : __vstring_base(__s, __s + __n, __a) { } 215 216 /** 217 * @brief Construct string as copy of a C string. 218 * @param __s Source C string. 219 * @param __a Allocator to use (default is default allocator). 220 */ 221 __versa_string(const _CharT* __s, const _Alloc& __a = _Alloc()) 222 : __vstring_base(__s, __s ? __s + traits_type::length(__s) : 223 __s + npos, __a) { } 224 225 /** 226 * @brief Construct string as multiple characters. 227 * @param __n Number of characters. 228 * @param __c Character to use. 229 * @param __a Allocator to use (default is default allocator). 230 */ 231 __versa_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) 232 : __vstring_base(__n, __c, __a) { } 233 234 /** 235 * @brief Construct string as copy of a range. 236 * @param __beg Start of range. 237 * @param __end End of range. 238 * @param __a Allocator to use (default is default allocator). 239 */ 240 #if __cplusplus >= 201103L 241 template
> 243 #else 244 template
245 #endif 246 __versa_string(_InputIterator __beg, _InputIterator __end, 247 const _Alloc& __a = _Alloc()) 248 : __vstring_base(__beg, __end, __a) { } 249 250 /** 251 * @brief Destroy the string instance. 252 */ 253 ~__versa_string() _GLIBCXX_NOEXCEPT { } 254 255 /** 256 * @brief Assign the value of @a str to this string. 257 * @param __str Source string. 258 */ 259 __versa_string& 260 operator=(const __versa_string& __str) 261 { return this->assign(__str); } 262 263 #if __cplusplus >= 201103L 264 /** 265 * @brief String move assignment operator. 266 * @param __str Source string. 267 * 268 * The contents of @a __str are moved into this string (without 269 * copying). @a __str is a valid, but unspecified string. 270 */ 271 __versa_string& 272 operator=(__versa_string&& __str) noexcept 273 { 274 // NB: DR 1204. 275 this->swap(__str); 276 return *this; 277 } 278 279 /** 280 * @brief Set value to string constructed from initializer list. 281 * @param __l std::initializer_list. 282 */ 283 __versa_string& 284 operator=(std::initializer_list<_CharT> __l) 285 { 286 this->assign(__l.begin(), __l.end()); 287 return *this; 288 } 289 #endif 290 291 /** 292 * @brief Copy contents of @a __s into this string. 293 * @param __s Source null-terminated string. 294 */ 295 __versa_string& 296 operator=(const _CharT* __s) 297 { return this->assign(__s); } 298 299 /** 300 * @brief Set value to string of length 1. 301 * @param __c Source character. 302 * 303 * Assigning to a character makes this string length 1 and 304 * (*this)[0] == @a __c. 305 */ 306 __versa_string& 307 operator=(_CharT __c) 308 { 309 this->assign(1, __c); 310 return *this; 311 } 312 313 // Iterators: 314 /** 315 * Returns a read/write iterator that points to the first character in 316 * the %string. Unshares the string. 317 */ 318 iterator 319 begin() _GLIBCXX_NOEXCEPT 320 { 321 this->_M_leak(); 322 return iterator(this->_M_data()); 323 } 324 325 /** 326 * Returns a read-only (constant) iterator that points to the first 327 * character in the %string. 328 */ 329 const_iterator 330 begin() const _GLIBCXX_NOEXCEPT 331 { return const_iterator(this->_M_data()); } 332 333 /** 334 * Returns a read/write iterator that points one past the last 335 * character in the %string. Unshares the string. 336 */ 337 iterator 338 end() _GLIBCXX_NOEXCEPT 339 { 340 this->_M_leak(); 341 return iterator(this->_M_data() + this->size()); 342 } 343 344 /** 345 * Returns a read-only (constant) iterator that points one past the 346 * last character in the %string. 347 */ 348 const_iterator 349 end() const _GLIBCXX_NOEXCEPT 350 { return const_iterator(this->_M_data() + this->size()); } 351 352 /** 353 * Returns a read/write reverse iterator that points to the last 354 * character in the %string. Iteration is done in reverse element 355 * order. Unshares the string. 356 */ 357 reverse_iterator 358 rbegin() _GLIBCXX_NOEXCEPT 359 { return reverse_iterator(this->end()); } 360 361 /** 362 * Returns a read-only (constant) reverse iterator that points 363 * to the last character in the %string. Iteration is done in 364 * reverse element order. 365 */ 366 const_reverse_iterator 367 rbegin() const _GLIBCXX_NOEXCEPT 368 { return const_reverse_iterator(this->end()); } 369 370 /** 371 * Returns a read/write reverse iterator that points to one before the 372 * first character in the %string. Iteration is done in reverse 373 * element order. Unshares the string. 374 */ 375 reverse_iterator 376 rend() _GLIBCXX_NOEXCEPT 377 { return reverse_iterator(this->begin()); } 378 379 /** 380 * Returns a read-only (constant) reverse iterator that points 381 * to one before the first character in the %string. Iteration 382 * is done in reverse element order. 383 */ 384 const_reverse_iterator 385 rend() const _GLIBCXX_NOEXCEPT 386 { return const_reverse_iterator(this->begin()); } 387 388 #if __cplusplus >= 201103L 389 /** 390 * Returns a read-only (constant) iterator that points to the first 391 * character in the %string. 392 */ 393 const_iterator 394 cbegin() const noexcept 395 { return const_iterator(this->_M_data()); } 396 397 /** 398 * Returns a read-only (constant) iterator that points one past the 399 * last character in the %string. 400 */ 401 const_iterator 402 cend() const noexcept 403 { return const_iterator(this->_M_data() + this->size()); } 404 405 /** 406 * Returns a read-only (constant) reverse iterator that points 407 * to the last character in the %string. Iteration is done in 408 * reverse element order. 409 */ 410 const_reverse_iterator 411 crbegin() const noexcept 412 { return const_reverse_iterator(this->end()); } 413 414 /** 415 * Returns a read-only (constant) reverse iterator that points 416 * to one before the first character in the %string. Iteration 417 * is done in reverse element order. 418 */ 419 const_reverse_iterator 420 crend() const noexcept 421 { return const_reverse_iterator(this->begin()); } 422 #endif 423 424 public: 425 // Capacity: 426 /// Returns the number of characters in the string, not including any 427 /// null-termination. 428 size_type 429 size() const _GLIBCXX_NOEXCEPT 430 { return this->_M_length(); } 431 432 /// Returns the number of characters in the string, not including any 433 /// null-termination. 434 size_type 435 length() const _GLIBCXX_NOEXCEPT 436 { return this->_M_length(); } 437 438 /// Returns the size() of the largest possible %string. 439 size_type 440 max_size() const _GLIBCXX_NOEXCEPT 441 { return this->_M_max_size(); } 442 443 /** 444 * @brief Resizes the %string to the specified number of characters. 445 * @param __n Number of characters the %string should contain. 446 * @param __c Character to fill any new elements. 447 * 448 * This function will %resize the %string to the specified 449 * number of characters. If the number is smaller than the 450 * %string's current size the %string is truncated, otherwise 451 * the %string is extended and new elements are set to @a __c. 452 */ 453 void 454 resize(size_type __n, _CharT __c); 455 456 /** 457 * @brief Resizes the %string to the specified number of characters. 458 * @param __n Number of characters the %string should contain. 459 * 460 * This function will resize the %string to the specified 461 * length. If the new size is smaller than the %string's 462 * current size the %string is truncated, otherwise the %string 463 * is extended and new characters are default-constructed. For 464 * basic types such as char, this means setting them to 0. 465 */ 466 void 467 resize(size_type __n) 468 { this->resize(__n, _CharT()); } 469 470 #if __cplusplus >= 201103L 471 /// A non-binding request to reduce capacity() to size(). 472 void 473 shrink_to_fit() noexcept 474 { 475 if (capacity() > size()) 476 { 477 __try 478 { this->reserve(0); } 479 __catch(...) 480 { } 481 } 482 } 483 #endif 484 485 /** 486 * Returns the total number of characters that the %string can 487 * hold before needing to allocate more memory. 488 */ 489 size_type 490 capacity() const _GLIBCXX_NOEXCEPT 491 { return this->_M_capacity(); } 492 493 /** 494 * @brief Attempt to preallocate enough memory for specified number of 495 * characters. 496 * @param __res_arg Number of characters required. 497 * @throw std::length_error If @a __res_arg exceeds @c max_size(). 498 * 499 * This function attempts to reserve enough memory for the 500 * %string to hold the specified number of characters. If the 501 * number requested is more than max_size(), length_error is 502 * thrown. 503 * 504 * The advantage of this function is that if optimal code is a 505 * necessity and the user can determine the string length that 506 * will be required, the user can reserve the memory in 507 * %advance, and thus prevent a possible reallocation of memory 508 * and copying of %string data. 509 */ 510 void 511 reserve(size_type __res_arg = 0) 512 { this->_M_reserve(__res_arg); } 513 514 /** 515 * Erases the string, making it empty. 516 */ 517 void 518 clear() _GLIBCXX_NOEXCEPT 519 { this->_M_clear(); } 520 521 /** 522 * Returns true if the %string is empty. Equivalent to 523 *
*this == ""
. 524 */ 525 _GLIBCXX_NODISCARD bool 526 empty() const _GLIBCXX_NOEXCEPT 527 { return this->size() == 0; } 528 529 // Element access: 530 /** 531 * @brief Subscript access to the data contained in the %string. 532 * @param __pos The index of the character to access. 533 * @return Read-only (constant) reference to the character. 534 * 535 * This operator allows for easy, array-style, data access. 536 * Note that data access with this operator is unchecked and 537 * out_of_range lookups are not defined. (For checked lookups 538 * see at().) 539 */ 540 const_reference 541 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT 542 { 543 __glibcxx_assert(__pos <= this->size()); 544 return this->_M_data()[__pos]; 545 } 546 547 /** 548 * @brief Subscript access to the data contained in the %string. 549 * @param __pos The index of the character to access. 550 * @return Read/write reference to the character. 551 * 552 * This operator allows for easy, array-style, data access. 553 * Note that data access with this operator is unchecked and 554 * out_of_range lookups are not defined. (For checked lookups 555 * see at().) Unshares the string. 556 */ 557 reference 558 operator[](size_type __pos) _GLIBCXX_NOEXCEPT 559 { 560 // Allow pos == size() both in C++98 mode, as v3 extension, 561 // and in C++11 mode. 562 __glibcxx_assert(__pos <= this->size()); 563 // In pedantic mode be strict in C++98 mode. 564 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L 565 || __pos < this->size()); 566 this->_M_leak(); 567 return this->_M_data()[__pos]; 568 } 569 570 /** 571 * @brief Provides access to the data contained in the %string. 572 * @param __n The index of the character to access. 573 * @return Read-only (const) reference to the character. 574 * @throw std::out_of_range If @a __n is an invalid index. 575 * 576 * This function provides for safer data access. The parameter 577 * is first checked that it is in the range of the string. The 578 * function throws out_of_range if the check fails. 579 */ 580 const_reference 581 at(size_type __n) const 582 { 583 if (__n >= this->size()) 584 std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " 585 "(which is %zu) >= this->size() " 586 "(which is %zu)"), 587 __n, this->size()); 588 return this->_M_data()[__n]; 589 } 590 591 /** 592 * @brief Provides access to the data contained in the %string. 593 * @param __n The index of the character to access. 594 * @return Read/write reference to the character. 595 * @throw std::out_of_range If @a __n is an invalid index. 596 * 597 * This function provides for safer data access. The parameter 598 * is first checked that it is in the range of the string. The 599 * function throws out_of_range if the check fails. Success 600 * results in unsharing the string. 601 */ 602 reference 603 at(size_type __n) 604 { 605 if (__n >= this->size()) 606 std::__throw_out_of_range_fmt(__N("__versa_string::at: __n " 607 "(which is %zu) >= this->size() " 608 "(which is %zu)"), 609 __n, this->size()); 610 this->_M_leak(); 611 return this->_M_data()[__n]; 612 } 613 614 #if __cplusplus >= 201103L 615 /** 616 * Returns a read/write reference to the data at the first 617 * element of the %string. 618 */ 619 reference 620 front() noexcept 621 { return operator[](0); } 622 623 /** 624 * Returns a read-only (constant) reference to the data at the first 625 * element of the %string. 626 */ 627 const_reference 628 front() const noexcept 629 { return operator[](0); } 630 631 /** 632 * Returns a read/write reference to the data at the last 633 * element of the %string. 634 */ 635 reference 636 back() noexcept 637 { return operator[](this->size() - 1); } 638 639 /** 640 * Returns a read-only (constant) reference to the data at the 641 * last element of the %string. 642 */ 643 const_reference 644 back() const noexcept 645 { return operator[](this->size() - 1); } 646 #endif 647 648 // Modifiers: 649 /** 650 * @brief Append a string to this string. 651 * @param __str The string to append. 652 * @return Reference to this string. 653 */ 654 __versa_string& 655 operator+=(const __versa_string& __str) 656 { return this->append(__str); } 657 658 /** 659 * @brief Append a C string. 660 * @param __s The C string to append. 661 * @return Reference to this string. 662 */ 663 __versa_string& 664 operator+=(const _CharT* __s) 665 { return this->append(__s); } 666 667 /** 668 * @brief Append a character. 669 * @param __c The character to append. 670 * @return Reference to this string. 671 */ 672 __versa_string& 673 operator+=(_CharT __c) 674 { 675 this->push_back(__c); 676 return *this; 677 } 678 679 #if __cplusplus >= 201103L 680 /** 681 * @brief Append an initializer_list of characters. 682 * @param __l The initializer_list of characters to be appended. 683 * @return Reference to this string. 684 */ 685 __versa_string& 686 operator+=(std::initializer_list<_CharT> __l) 687 { return this->append(__l.begin(), __l.end()); } 688 #endif // C++11 689 690 /** 691 * @brief Append a string to this string. 692 * @param __str The string to append. 693 * @return Reference to this string. 694 */ 695 __versa_string& 696 append(const __versa_string& __str) 697 { return _M_append(__str._M_data(), __str.size()); } 698 699 /** 700 * @brief Append a substring. 701 * @param __str The string to append. 702 * @param __pos Index of the first character of str to append. 703 * @param __n The number of characters to append. 704 * @return Reference to this string. 705 * @throw std::out_of_range if @a pos is not a valid index. 706 * 707 * This function appends @a __n characters from @a __str 708 * starting at @a __pos to this string. If @a __n is is larger 709 * than the number of available characters in @a __str, the 710 * remainder of @a __str is appended. 711 */ 712 __versa_string& 713 append(const __versa_string& __str, size_type __pos, size_type __n) 714 { return _M_append(__str._M_data() 715 + __str._M_check(__pos, "__versa_string::append"), 716 __str._M_limit(__pos, __n)); } 717 718 /** 719 * @brief Append a C substring. 720 * @param __s The C string to append. 721 * @param __n The number of characters to append. 722 * @return Reference to this string. 723 */ 724 __versa_string& 725 append(const _CharT* __s, size_type __n) 726 { 727 __glibcxx_requires_string_len(__s, __n); 728 _M_check_length(size_type(0), __n, "__versa_string::append"); 729 return _M_append(__s, __n); 730 } 731 732 /** 733 * @brief Append a C string. 734 * @param __s The C string to append. 735 * @return Reference to this string. 736 */ 737 __versa_string& 738 append(const _CharT* __s) 739 { 740 __glibcxx_requires_string(__s); 741 const size_type __n = traits_type::length(__s); 742 _M_check_length(size_type(0), __n, "__versa_string::append"); 743 return _M_append(__s, __n); 744 } 745 746 /** 747 * @brief Append multiple characters. 748 * @param __n The number of characters to append. 749 * @param __c The character to use. 750 * @return Reference to this string. 751 * 752 * Appends n copies of c to this string. 753 */ 754 __versa_string& 755 append(size_type __n, _CharT __c) 756 { return _M_replace_aux(this->size(), size_type(0), __n, __c); } 757 758 #if __cplusplus >= 201103L 759 /** 760 * @brief Append an initializer_list of characters. 761 * @param __l The initializer_list of characters to append. 762 * @return Reference to this string. 763 */ 764 __versa_string& 765 append(std::initializer_list<_CharT> __l) 766 { return this->append(__l.begin(), __l.end()); } 767 #endif // C++11 768 769 /** 770 * @brief Append a range of characters. 771 * @param __first Iterator referencing the first character to append. 772 * @param __last Iterator marking the end of the range. 773 * @return Reference to this string. 774 * 775 * Appends characters in the range [first,last) to this string. 776 */ 777 #if __cplusplus >= 201103L 778 template
> 780 #else 781 template
782 #endif 783 __versa_string& 784 append(_InputIterator __first, _InputIterator __last) 785 { return this->replace(_M_iend(), _M_iend(), __first, __last); } 786 787 /** 788 * @brief Append a single character. 789 * @param __c Character to append. 790 */ 791 void 792 push_back(_CharT __c) 793 { 794 const size_type __size = this->size(); 795 if (__size + 1 > this->capacity() || this->_M_is_shared()) 796 this->_M_mutate(__size, size_type(0), 0, size_type(1)); 797 traits_type::assign(this->_M_data()[__size], __c); 798 this->_M_set_length(__size + 1); 799 } 800 801 /** 802 * @brief Set value to contents of another string. 803 * @param __str Source string to use. 804 * @return Reference to this string. 805 */ 806 __versa_string& 807 assign(const __versa_string& __str) 808 { 809 this->_M_assign(__str); 810 return *this; 811 } 812 813 #if __cplusplus >= 201103L 814 /** 815 * @brief Set value to contents of another string. 816 * @param __str Source string to use. 817 * @return Reference to this string. 818 * 819 * This function sets this string to the exact contents of @a __str. 820 * @a __str is a valid, but unspecified string. 821 */ 822 __versa_string& 823 assign(__versa_string&& __str) noexcept 824 { 825 this->swap(__str); 826 return *this; 827 } 828 #endif // C++11 829 830 /** 831 * @brief Set value to a substring of a string. 832 * @param __str The string to use. 833 * @param __pos Index of the first character of str. 834 * @param __n Number of characters to use. 835 * @return Reference to this string. 836 * @throw std::out_of_range if @a __pos is not a valid index. 837 * 838 * This function sets this string to the substring of @a __str 839 * consisting of @a __n characters at @a __pos. If @a __n is 840 * is larger than the number of available characters in @a 841 * __str, the remainder of @a __str is used. 842 */ 843 __versa_string& 844 assign(const __versa_string& __str, size_type __pos, size_type __n) 845 { return _M_replace(size_type(0), this->size(), __str._M_data() 846 + __str._M_check(__pos, "__versa_string::assign"), 847 __str._M_limit(__pos, __n)); } 848 849 /** 850 * @brief Set value to a C substring. 851 * @param __s The C string to use. 852 * @param __n Number of characters to use. 853 * @return Reference to this string. 854 * 855 * This function sets the value of this string to the first @a 856 * __n characters of @a __s. If @a __n is is larger than the 857 * number of available characters in @a __s, the remainder of 858 * @a __s is used. 859 */ 860 __versa_string& 861 assign(const _CharT* __s, size_type __n) 862 { 863 __glibcxx_requires_string_len(__s, __n); 864 return _M_replace(size_type(0), this->size(), __s, __n); 865 } 866 867 /** 868 * @brief Set value to contents of a C string. 869 * @param __s The C string to use. 870 * @return Reference to this string. 871 * 872 * This function sets the value of this string to the value of 873 * @a __s. The data is copied, so there is no dependence on @a 874 * __s once the function returns. 875 */ 876 __versa_string& 877 assign(const _CharT* __s) 878 { 879 __glibcxx_requires_string(__s); 880 return _M_replace(size_type(0), this->size(), __s, 881 traits_type::length(__s)); 882 } 883 884 /** 885 * @brief Set value to multiple characters. 886 * @param __n Length of the resulting string. 887 * @param __c The character to use. 888 * @return Reference to this string. 889 * 890 * This function sets the value of this string to @a __n copies of 891 * character @a __c. 892 */ 893 __versa_string& 894 assign(size_type __n, _CharT __c) 895 { return _M_replace_aux(size_type(0), this->size(), __n, __c); } 896 897 /** 898 * @brief Set value to a range of characters. 899 * @param __first Iterator referencing the first character to append. 900 * @param __last Iterator marking the end of the range. 901 * @return Reference to this string. 902 * 903 * Sets value of string to characters in the range 904 * [first,last). 905 */ 906 #if __cplusplus >= 201103L 907 template
> 909 #else 910 template
911 #endif 912 __versa_string& 913 assign(_InputIterator __first, _InputIterator __last) 914 { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } 915 916 #if __cplusplus >= 201103L 917 /** 918 * @brief Set value to an initializer_list of characters. 919 * @param __l The initializer_list of characters to assign. 920 * @return Reference to this string. 921 */ 922 __versa_string& 923 assign(std::initializer_list<_CharT> __l) 924 { return this->assign(__l.begin(), __l.end()); } 925 #endif // C++11 926 927 #if __cplusplus >= 201103L 928 /** 929 * @brief Insert multiple characters. 930 * @param __p Const_iterator referencing location in string to 931 * insert at. 932 * @param __n Number of characters to insert 933 * @param __c The character to insert. 934 * @return Iterator referencing the first inserted char. 935 * @throw std::length_error If new length exceeds @c max_size(). 936 * 937 * Inserts @a __n copies of character @a __c starting at the 938 * position referenced by iterator @a __p. If adding 939 * characters causes the length to exceed max_size(), 940 * length_error is thrown. The value of the string doesn't 941 * change if an error is thrown. 942 */ 943 iterator 944 insert(const_iterator __p, size_type __n, _CharT __c) 945 { 946 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 947 const size_type __pos = __p - _M_ibegin(); 948 this->replace(__p, __p, __n, __c); 949 return iterator(this->_M_data() + __pos); 950 } 951 #else 952 /** 953 * @brief Insert multiple characters. 954 * @param __p Iterator referencing location in string to insert at. 955 * @param __n Number of characters to insert 956 * @param __c The character to insert. 957 * @throw std::length_error If new length exceeds @c max_size(). 958 * 959 * Inserts @a __n copies of character @a __c starting at the 960 * position referenced by iterator @a __p. If adding 961 * characters causes the length to exceed max_size(), 962 * length_error is thrown. The value of the string doesn't 963 * change if an error is thrown. 964 */ 965 void 966 insert(iterator __p, size_type __n, _CharT __c) 967 { this->replace(__p, __p, __n, __c); } 968 #endif 969 970 #if __cplusplus >= 201103L 971 /** 972 * @brief Insert a range of characters. 973 * @param __p Const_iterator referencing location in string to 974 * insert at. 975 * @param __beg Start of range. 976 * @param __end End of range. 977 * @return Iterator referencing the first inserted char. 978 * @throw std::length_error If new length exceeds @c max_size(). 979 * 980 * Inserts characters in range [beg,end). If adding characters 981 * causes the length to exceed max_size(), length_error is 982 * thrown. The value of the string doesn't change if an error 983 * is thrown. 984 */ 985 template
> 987 iterator 988 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) 989 { 990 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 991 const size_type __pos = __p - _M_ibegin(); 992 this->replace(__p, __p, __beg, __end); 993 return iterator(this->_M_data() + __pos); 994 } 995 #else 996 /** 997 * @brief Insert a range of characters. 998 * @param __p Iterator referencing location in string to insert at. 999 * @param __beg Start of range. 1000 * @param __end End of range. 1001 * @throw std::length_error If new length exceeds @c max_size(). 1002 * 1003 * Inserts characters in range [beg,end). If adding characters 1004 * causes the length to exceed max_size(), length_error is 1005 * thrown. The value of the string doesn't change if an error 1006 * is thrown. 1007 */ 1008 template
1009 void 1010 insert(iterator __p, _InputIterator __beg, _InputIterator __end) 1011 { this->replace(__p, __p, __beg, __end); } 1012 #endif 1013 1014 #if __cplusplus >= 201103L 1015 /** 1016 * @brief Insert an initializer_list of characters. 1017 * @param __p Const_iterator referencing location in string to 1018 * insert at. 1019 * @param __l The initializer_list of characters to insert. 1020 * @return Iterator referencing the first inserted char. 1021 * @throw std::length_error If new length exceeds @c max_size(). 1022 */ 1023 iterator 1024 insert(const_iterator __p, std::initializer_list<_CharT> __l) 1025 { return this->insert(__p, __l.begin(), __l.end()); } 1026 #endif // C++11 1027 1028 /** 1029 * @brief Insert value of a string. 1030 * @param __pos1 Iterator referencing location in string to insert at. 1031 * @param __str The string to insert. 1032 * @return Reference to this string. 1033 * @throw std::length_error If new length exceeds @c max_size(). 1034 * 1035 * Inserts value of @a __str starting at @a __pos1. If adding 1036 * characters causes the length to exceed max_size(), 1037 * length_error is thrown. The value of the string doesn't 1038 * change if an error is thrown. 1039 */ 1040 __versa_string& 1041 insert(size_type __pos1, const __versa_string& __str) 1042 { return this->replace(__pos1, size_type(0), 1043 __str._M_data(), __str.size()); } 1044 1045 /** 1046 * @brief Insert a substring. 1047 * @param __pos1 Iterator referencing location in string to insert at. 1048 * @param __str The string to insert. 1049 * @param __pos2 Start of characters in str to insert. 1050 * @param __n Number of characters to insert. 1051 * @return Reference to this string. 1052 * @throw std::length_error If new length exceeds @c max_size(). 1053 * @throw std::out_of_range If @a __pos1 > size() or 1054 * @a __pos2 > @a __str.size(). 1055 * 1056 * Starting at @a __pos1, insert @a __n character of @a __str 1057 * beginning with @a __pos2. If adding characters causes the 1058 * length to exceed max_size(), length_error is thrown. If @a 1059 * __pos1 is beyond the end of this string or @a __pos2 is 1060 * beyond the end of @a __str, out_of_range is thrown. The 1061 * value of the string doesn't change if an error is thrown. 1062 */ 1063 __versa_string& 1064 insert(size_type __pos1, const __versa_string& __str, 1065 size_type __pos2, size_type __n) 1066 { return this->replace(__pos1, size_type(0), __str._M_data() 1067 + __str._M_check(__pos2, "__versa_string::insert"), 1068 __str._M_limit(__pos2, __n)); } 1069 1070 /** 1071 * @brief Insert a C substring. 1072 * @param __pos Iterator referencing location in string to insert at. 1073 * @param __s The C string to insert. 1074 * @param __n The number of characters to insert. 1075 * @return Reference to this string. 1076 * @throw std::length_error If new length exceeds @c max_size(). 1077 * @throw std::out_of_range If @a __pos is beyond the end of this 1078 * string. 1079 * 1080 * Inserts the first @a __n characters of @a __s starting at @a 1081 * __pos. If adding characters causes the length to exceed 1082 * max_size(), length_error is thrown. If @a __pos is beyond 1083 * end(), out_of_range is thrown. The value of the string 1084 * doesn't change if an error is thrown. 1085 */ 1086 __versa_string& 1087 insert(size_type __pos, const _CharT* __s, size_type __n) 1088 { return this->replace(__pos, size_type(0), __s, __n); } 1089 1090 /** 1091 * @brief Insert a C string. 1092 * @param __pos Iterator referencing location in string to insert at. 1093 * @param __s The C string to insert. 1094 * @return Reference to this string. 1095 * @throw std::length_error If new length exceeds @c max_size(). 1096 * @throw std::out_of_range If @a __pos is beyond the end of this 1097 * string. 1098 * 1099 * Inserts the first @a __n characters of @a __s starting at @a 1100 * __pos. If adding characters causes the length to exceed 1101 * max_size(), length_error is thrown. If @a __pos is beyond 1102 * end(), out_of_range is thrown. The value of the string 1103 * doesn't change if an error is thrown. 1104 */ 1105 __versa_string& 1106 insert(size_type __pos, const _CharT* __s) 1107 { 1108 __glibcxx_requires_string(__s); 1109 return this->replace(__pos, size_type(0), __s, 1110 traits_type::length(__s)); 1111 } 1112 1113 /** 1114 * @brief Insert multiple characters. 1115 * @param __pos Index in string to insert at. 1116 * @param __n Number of characters to insert 1117 * @param __c The character to insert. 1118 * @return Reference to this string. 1119 * @throw std::length_error If new length exceeds @c max_size(). 1120 * @throw std::out_of_range If @a __pos is beyond the end of this 1121 * string. 1122 * 1123 * Inserts @a __n copies of character @a __c starting at index 1124 * @a __pos. If adding characters causes the length to exceed 1125 * max_size(), length_error is thrown. If @a __pos > length(), 1126 * out_of_range is thrown. The value of the string doesn't 1127 * change if an error is thrown. 1128 */ 1129 __versa_string& 1130 insert(size_type __pos, size_type __n, _CharT __c) 1131 { return _M_replace_aux(_M_check(__pos, "__versa_string::insert"), 1132 size_type(0), __n, __c); } 1133 1134 /** 1135 * @brief Insert one character. 1136 * @param __p Iterator referencing position in string to insert at. 1137 * @param __c The character to insert. 1138 * @return Iterator referencing newly inserted char. 1139 * @throw std::length_error If new length exceeds @c max_size(). 1140 * 1141 * Inserts character @a __c at position referenced by @a __p. 1142 * If adding character causes the length to exceed max_size(), 1143 * length_error is thrown. If @a __p is beyond end of string, 1144 * out_of_range is thrown. The value of the string doesn't 1145 * change if an error is thrown. 1146 */ 1147 iterator 1148 #if __cplusplus >= 201103L 1149 insert(const_iterator __p, _CharT __c) 1150 #else 1151 insert(iterator __p, _CharT __c) 1152 #endif 1153 { 1154 _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); 1155 const size_type __pos = __p - _M_ibegin(); 1156 _M_replace_aux(__pos, size_type(0), size_type(1), __c); 1157 this->_M_set_leaked(); 1158 return iterator(this->_M_data() + __pos); 1159 } 1160 1161 /** 1162 * @brief Remove characters. 1163 * @param __pos Index of first character to remove (default 0). 1164 * @param __n Number of characters to remove (default remainder). 1165 * @return Reference to this string. 1166 * @throw std::out_of_range If @a __pos is beyond the end of this 1167 * string. 1168 * 1169 * Removes @a __n characters from this string starting at @a 1170 * __pos. The length of the string is reduced by @a __n. If 1171 * there are < @a __n characters to remove, the remainder of 1172 * the string is truncated. If @a __p is beyond end of string, 1173 * out_of_range is thrown. The value of the string doesn't 1174 * change if an error is thrown. 1175 */ 1176 __versa_string& 1177 erase(size_type __pos = 0, size_type __n = npos) 1178 { 1179 this->_M_erase(_M_check(__pos, "__versa_string::erase"), 1180 _M_limit(__pos, __n)); 1181 return *this; 1182 } 1183 1184 /** 1185 * @brief Remove one character. 1186 * @param __position Iterator referencing the character to remove. 1187 * @return iterator referencing same location after removal. 1188 * 1189 * Removes the character at @a __position from this string. The 1190 * value of the string doesn't change if an error is thrown. 1191 */ 1192 iterator 1193 #if __cplusplus >= 201103L 1194 erase(const_iterator __position) 1195 #else 1196 erase(iterator __position) 1197 #endif 1198 { 1199 _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() 1200 && __position < _M_iend()); 1201 const size_type __pos = __position - _M_ibegin(); 1202 this->_M_erase(__pos, size_type(1)); 1203 this->_M_set_leaked(); 1204 return iterator(this->_M_data() + __pos); 1205 } 1206 1207 /** 1208 * @brief Remove a range of characters. 1209 * @param __first Iterator referencing the first character to remove. 1210 * @param __last Iterator referencing the end of the range. 1211 * @return Iterator referencing location of first after removal. 1212 * 1213 * Removes the characters in the range [first,last) from this 1214 * string. The value of the string doesn't change if an error 1215 * is thrown. 1216 */ 1217 iterator 1218 #if __cplusplus >= 201103L 1219 erase(const_iterator __first, const_iterator __last) 1220 #else 1221 erase(iterator __first, iterator __last) 1222 #endif 1223 { 1224 _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last 1225 && __last <= _M_iend()); 1226 const size_type __pos = __first - _M_ibegin(); 1227 this->_M_erase(__pos, __last - __first); 1228 this->_M_set_leaked(); 1229 return iterator(this->_M_data() + __pos); 1230 } 1231 1232 #if __cplusplus >= 201103L 1233 /** 1234 * @brief Remove the last character. 1235 * 1236 * The string must be non-empty. 1237 */ 1238 void 1239 pop_back() 1240 { this->_M_erase(size()-1, 1); } 1241 #endif // C++11 1242 1243 /** 1244 * @brief Replace characters with value from another string. 1245 * @param __pos Index of first character to replace. 1246 * @param __n Number of characters to be replaced. 1247 * @param __str String to insert. 1248 * @return Reference to this string. 1249 * @throw std::out_of_range If @a __pos is beyond the end of this 1250 * string. 1251 * @throw std::length_error If new length exceeds @c max_size(). 1252 * 1253 * Removes the characters in the range [pos,pos+n) from this 1254 * string. In place, the value of @a __str is inserted. If @a 1255 * __pos is beyond end of string, out_of_range is thrown. If 1256 * the length of the result exceeds max_size(), length_error is 1257 * thrown. The value of the string doesn't change if an error 1258 * is thrown. 1259 */ 1260 __versa_string& 1261 replace(size_type __pos, size_type __n, const __versa_string& __str) 1262 { return this->replace(__pos, __n, __str._M_data(), __str.size()); } 1263 1264 /** 1265 * @brief Replace characters with value from another string. 1266 * @param __pos1 Index of first character to replace. 1267 * @param __n1 Number of characters to be replaced. 1268 * @param __str String to insert. 1269 * @param __pos2 Index of first character of str to use. 1270 * @param __n2 Number of characters from str to use. 1271 * @return Reference to this string. 1272 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > 1273 * str.size(). 1274 * @throw std::length_error If new length exceeds @c max_size(). 1275 * 1276 * Removes the characters in the range [pos1,pos1 + n) from 1277 * this string. In place, the value of @a __str is inserted. 1278 * If @a __pos is beyond end of string, out_of_range is thrown. 1279 * If the length of the result exceeds max_size(), length_error 1280 * is thrown. The value of the string doesn't change if an 1281 * error is thrown. 1282 */ 1283 __versa_string& 1284 replace(size_type __pos1, size_type __n1, const __versa_string& __str, 1285 size_type __pos2, size_type __n2) 1286 { 1287 return this->replace(__pos1, __n1, __str._M_data() 1288 + __str._M_check(__pos2, 1289 "__versa_string::replace"), 1290 __str._M_limit(__pos2, __n2)); 1291 } 1292 1293 /** 1294 * @brief Replace characters with value of a C substring. 1295 * @param __pos Index of first character to replace. 1296 * @param __n1 Number of characters to be replaced. 1297 * @param __s C string to insert. 1298 * @param __n2 Number of characters from @a __s to use. 1299 * @return Reference to this string. 1300 * @throw std::out_of_range If @a __pos1 > size(). 1301 * @throw std::length_error If new length exceeds @c max_size(). 1302 * 1303 * Removes the characters in the range [pos,pos + n1) from this 1304 * string. In place, the first @a __n2 characters of @a __s 1305 * are inserted, or all of @a __s if @a __n2 is too large. If 1306 * @a __pos is beyond end of string, out_of_range is thrown. 1307 * If the length of result exceeds max_size(), length_error is 1308 * thrown. The value of the string doesn't change if an error 1309 * is thrown. 1310 */ 1311 __versa_string& 1312 replace(size_type __pos, size_type __n1, const _CharT* __s, 1313 size_type __n2) 1314 { 1315 __glibcxx_requires_string_len(__s, __n2); 1316 return _M_replace(_M_check(__pos, "__versa_string::replace"), 1317 _M_limit(__pos, __n1), __s, __n2); 1318 } 1319 1320 /** 1321 * @brief Replace characters with value of a C string. 1322 * @param __pos Index of first character to replace. 1323 * @param __n1 Number of characters to be replaced. 1324 * @param __s C string to insert. 1325 * @return Reference to this string. 1326 * @throw std::out_of_range If @a __pos > size(). 1327 * @throw std::length_error If new length exceeds @c max_size(). 1328 * 1329 * Removes the characters in the range [pos,pos + n1) from this 1330 * string. In place, the characters of @a __s are inserted. If 1331 * @a pos is beyond end of string, out_of_range is thrown. If 1332 * the length of result exceeds max_size(), length_error is thrown. 1333 * The value of the string doesn't change if an error is thrown. 1334 */ 1335 __versa_string& 1336 replace(size_type __pos, size_type __n1, const _CharT* __s) 1337 { 1338 __glibcxx_requires_string(__s); 1339 return this->replace(__pos, __n1, __s, traits_type::length(__s)); 1340 } 1341 1342 /** 1343 * @brief Replace characters with multiple characters. 1344 * @param __pos Index of first character to replace. 1345 * @param __n1 Number of characters to be replaced. 1346 * @param __n2 Number of characters to insert. 1347 * @param __c Character to insert. 1348 * @return Reference to this string. 1349 * @throw std::out_of_range If @a __pos > size(). 1350 * @throw std::length_error If new length exceeds @c max_size(). 1351 * 1352 * Removes the characters in the range [pos,pos + n1) from this 1353 * string. In place, @a __n2 copies of @a __c are inserted. 1354 * If @a __pos is beyond end of string, out_of_range is thrown. 1355 * If the length of result exceeds max_size(), length_error is 1356 * thrown. The value of the string doesn't change if an error 1357 * is thrown. 1358 */ 1359 __versa_string& 1360 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) 1361 { return _M_replace_aux(_M_check(__pos, "__versa_string::replace"), 1362 _M_limit(__pos, __n1), __n2, __c); } 1363 1364 /** 1365 * @brief Replace range of characters with string. 1366 * @param __i1 Iterator referencing start of range to replace. 1367 * @param __i2 Iterator referencing end of range to replace. 1368 * @param __str String value to insert. 1369 * @return Reference to this string. 1370 * @throw std::length_error If new length exceeds @c max_size(). 1371 * 1372 * Removes the characters in the range [i1,i2). In place, the 1373 * value of @a __str is inserted. If the length of result 1374 * exceeds max_size(), length_error is thrown. The value of 1375 * the string doesn't change if an error is thrown. 1376 */ 1377 __versa_string& 1378 #if __cplusplus >= 201103L 1379 replace(const_iterator __i1, const_iterator __i2, 1380 const __versa_string& __str) 1381 #else 1382 replace(iterator __i1, iterator __i2, const __versa_string& __str) 1383 #endif 1384 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } 1385 1386 /** 1387 * @brief Replace range of characters with C substring. 1388 * @param __i1 Iterator referencing start of range to replace. 1389 * @param __i2 Iterator referencing end of range to replace. 1390 * @param __s C string value to insert. 1391 * @param __n Number of characters from s to insert. 1392 * @return Reference to this string. 1393 * @throw std::length_error If new length exceeds @c max_size(). 1394 * 1395 * Removes the characters in the range [i1,i2). In place, the 1396 * first @a n characters of @a __s are inserted. If the length 1397 * of result exceeds max_size(), length_error is thrown. The 1398 * value of the string doesn't change if an error is thrown. 1399 */ 1400 __versa_string& 1401 #if __cplusplus >= 201103L 1402 replace(const_iterator __i1, const_iterator __i2, 1403 const _CharT* __s, size_type __n) 1404 #else 1405 replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) 1406 #endif 1407 { 1408 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1409 && __i2 <= _M_iend()); 1410 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); 1411 } 1412 1413 /** 1414 * @brief Replace range of characters with C string. 1415 * @param __i1 Iterator referencing start of range to replace. 1416 * @param __i2 Iterator referencing end of range to replace. 1417 * @param __s C string value to insert. 1418 * @return Reference to this string. 1419 * @throw std::length_error If new length exceeds @c max_size(). 1420 * 1421 * Removes the characters in the range [i1,i2). In place, the 1422 * characters of @a __s are inserted. If the length of result 1423 * exceeds max_size(), length_error is thrown. The value of 1424 * the string doesn't change if an error is thrown. 1425 */ 1426 __versa_string& 1427 #if __cplusplus >= 201103L 1428 replace(const_iterator __i1, const_iterator __i2, const _CharT* __s) 1429 #else 1430 replace(iterator __i1, iterator __i2, const _CharT* __s) 1431 #endif 1432 { 1433 __glibcxx_requires_string(__s); 1434 return this->replace(__i1, __i2, __s, traits_type::length(__s)); 1435 } 1436 1437 /** 1438 * @brief Replace range of characters with multiple characters 1439 * @param __i1 Iterator referencing start of range to replace. 1440 * @param __i2 Iterator referencing end of range to replace. 1441 * @param __n Number of characters to insert. 1442 * @param __c Character to insert. 1443 * @return Reference to this string. 1444 * @throw std::length_error If new length exceeds @c max_size(). 1445 * 1446 * Removes the characters in the range [i1,i2). In place, @a 1447 * __n copies of @a __c are inserted. If the length of result 1448 * exceeds max_size(), length_error is thrown. The value of 1449 * the string doesn't change if an error is thrown. 1450 */ 1451 __versa_string& 1452 #if __cplusplus >= 201103L 1453 replace(const_iterator __i1, const_iterator __i2, size_type __n, 1454 _CharT __c) 1455 #else 1456 replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) 1457 #endif 1458 { 1459 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1460 && __i2 <= _M_iend()); 1461 return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); 1462 } 1463 1464 /** 1465 * @brief Replace range of characters with range. 1466 * @param __i1 Iterator referencing start of range to replace. 1467 * @param __i2 Iterator referencing end of range to replace. 1468 * @param __k1 Iterator referencing start of range to insert. 1469 * @param __k2 Iterator referencing end of range to insert. 1470 * @return Reference to this string. 1471 * @throw std::length_error If new length exceeds @c max_size(). 1472 * 1473 * Removes the characters in the range [i1,i2). In place, 1474 * characters in the range [k1,k2) are inserted. If the length 1475 * of result exceeds max_size(), length_error is thrown. The 1476 * value of the string doesn't change if an error is thrown. 1477 */ 1478 #if __cplusplus >= 201103L 1479 template
> 1481 __versa_string& 1482 replace(const_iterator __i1, const_iterator __i2, 1483 _InputIterator __k1, _InputIterator __k2) 1484 { 1485 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1486 && __i2 <= _M_iend()); 1487 __glibcxx_requires_valid_range(__k1, __k2); 1488 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, 1489 std::__false_type()); 1490 } 1491 #else 1492 template
1493 __versa_string& 1494 replace(iterator __i1, iterator __i2, 1495 _InputIterator __k1, _InputIterator __k2) 1496 { 1497 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1498 && __i2 <= _M_iend()); 1499 __glibcxx_requires_valid_range(__k1, __k2); 1500 typedef typename std::__is_integer<_InputIterator>::__type _Integral; 1501 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); 1502 } 1503 #endif 1504 1505 // Specializations for the common case of pointer and iterator: 1506 // useful to avoid the overhead of temporary buffering in _M_replace. 1507 __versa_string& 1508 #if __cplusplus >= 201103L 1509 replace(const_iterator __i1, const_iterator __i2, 1510 _CharT* __k1, _CharT* __k2) 1511 #else 1512 replace(iterator __i1, iterator __i2, 1513 _CharT* __k1, _CharT* __k2) 1514 #endif 1515 { 1516 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1517 && __i2 <= _M_iend()); 1518 __glibcxx_requires_valid_range(__k1, __k2); 1519 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1520 __k1, __k2 - __k1); 1521 } 1522 1523 __versa_string& 1524 #if __cplusplus >= 201103L 1525 replace(const_iterator __i1, const_iterator __i2, 1526 const _CharT* __k1, const _CharT* __k2) 1527 #else 1528 replace(iterator __i1, iterator __i2, 1529 const _CharT* __k1, const _CharT* __k2) 1530 #endif 1531 { 1532 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1533 && __i2 <= _M_iend()); 1534 __glibcxx_requires_valid_range(__k1, __k2); 1535 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1536 __k1, __k2 - __k1); 1537 } 1538 1539 __versa_string& 1540 #if __cplusplus >= 201103L 1541 replace(const_iterator __i1, const_iterator __i2, 1542 iterator __k1, iterator __k2) 1543 #else 1544 replace(iterator __i1, iterator __i2, 1545 iterator __k1, iterator __k2) 1546 #endif 1547 { 1548 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1549 && __i2 <= _M_iend()); 1550 __glibcxx_requires_valid_range(__k1, __k2); 1551 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1552 __k1.base(), __k2 - __k1); 1553 } 1554 1555 __versa_string& 1556 #if __cplusplus >= 201103L 1557 replace(const_iterator __i1, const_iterator __i2, 1558 const_iterator __k1, const_iterator __k2) 1559 #else 1560 replace(iterator __i1, iterator __i2, 1561 const_iterator __k1, const_iterator __k2) 1562 #endif 1563 { 1564 _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 1565 && __i2 <= _M_iend()); 1566 __glibcxx_requires_valid_range(__k1, __k2); 1567 return this->replace(__i1 - _M_ibegin(), __i2 - __i1, 1568 __k1.base(), __k2 - __k1); 1569 } 1570 1571 #if __cplusplus >= 201103L 1572 /** 1573 * @brief Replace range of characters with initializer_list. 1574 * @param __i1 Iterator referencing start of range to replace. 1575 * @param __i2 Iterator referencing end of range to replace. 1576 * @param __l The initializer_list of characters to insert. 1577 * @return Reference to this string. 1578 * @throw std::length_error If new length exceeds @c max_size(). 1579 * 1580 * Removes the characters in the range [i1,i2). In place, 1581 * characters in the range [k1,k2) are inserted. If the length 1582 * of result exceeds max_size(), length_error is thrown. The 1583 * value of the string doesn't change if an error is thrown. 1584 */ 1585 __versa_string& 1586 replace(const_iterator __i1, const_iterator __i2, 1587 std::initializer_list<_CharT> __l) 1588 { return this->replace(__i1, __i2, __l.begin(), __l.end()); } 1589 #endif // C++11 1590 1591 private: 1592 template
1593 __versa_string& 1594 _M_replace_dispatch(const_iterator __i1, const_iterator __i2, 1595 _Integer __n, _Integer __val, std::__true_type) 1596 { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } 1597 1598 template
1599 __versa_string& 1600 _M_replace_dispatch(const_iterator __i1, const_iterator __i2, 1601 _InputIterator __k1, _InputIterator __k2, 1602 std::__false_type); 1603 1604 __versa_string& 1605 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, 1606 _CharT __c); 1607 1608 __versa_string& 1609 _M_replace(size_type __pos, size_type __len1, const _CharT* __s, 1610 const size_type __len2); 1611 1612 __versa_string& 1613 _M_append(const _CharT* __s, size_type __n); 1614 1615 public: 1616 1617 /** 1618 * @brief Copy substring into C string. 1619 * @param __s C string to copy value into. 1620 * @param __n Number of characters to copy. 1621 * @param __pos Index of first character to copy. 1622 * @return Number of characters actually copied 1623 * @throw std::out_of_range If pos > size(). 1624 * 1625 * Copies up to @a __n characters starting at @a __pos into the 1626 * C string @a s. If @a __pos is greater than size(), 1627 * out_of_range is thrown. 1628 */ 1629 size_type 1630 copy(_CharT* __s, size_type __n, size_type __pos = 0) const; 1631 1632 /** 1633 * @brief Swap contents with another string. 1634 * @param __s String to swap with. 1635 * 1636 * Exchanges the contents of this string with that of @a __s in 1637 * constant time. 1638 */ 1639 void 1640 swap(__versa_string& __s) _GLIBCXX_NOEXCEPT 1641 { this->_M_swap(__s); } 1642 1643 // String operations: 1644 /** 1645 * @brief Return const pointer to null-terminated contents. 1646 * 1647 * This is a handle to internal data. Do not modify or dire things may 1648 * happen. 1649 */ 1650 const _CharT* 1651 c_str() const _GLIBCXX_NOEXCEPT 1652 { return this->_M_data(); } 1653 1654 /** 1655 * @brief Return const pointer to contents. 1656 * 1657 * This is a handle to internal data. Do not modify or dire things may 1658 * happen. 1659 */ 1660 const _CharT* 1661 data() const _GLIBCXX_NOEXCEPT 1662 { return this->_M_data(); } 1663 1664 /** 1665 * @brief Return copy of allocator used to construct this string. 1666 */ 1667 allocator_type 1668 get_allocator() const _GLIBCXX_NOEXCEPT 1669 { return allocator_type(this->_M_get_allocator()); } 1670 1671 /** 1672 * @brief Find position of a C substring. 1673 * @param __s C string to locate. 1674 * @param __pos Index of character to search from. 1675 * @param __n Number of characters from @a __s to search for. 1676 * @return Index of start of first occurrence. 1677 * 1678 * Starting from @a __pos, searches forward for the first @a 1679 * __n characters in @a __s within this string. If found, 1680 * returns the index where it begins. If not found, returns 1681 * npos. 1682 */ 1683 size_type 1684 find(const _CharT* __s, size_type __pos, size_type __n) const; 1685 1686 /** 1687 * @brief Find position of a string. 1688 * @param __str String to locate. 1689 * @param __pos Index of character to search from (default 0). 1690 * @return Index of start of first occurrence. 1691 * 1692 * Starting from @a __pos, searches forward for value of @a 1693 * __str within this string. If found, returns the index where 1694 * it begins. If not found, returns npos. 1695 */ 1696 size_type 1697 find(const __versa_string& __str, size_type __pos = 0) const 1698 _GLIBCXX_NOEXCEPT 1699 { return this->find(__str.data(), __pos, __str.size()); } 1700 1701 /** 1702 * @brief Find position of a C string. 1703 * @param __s C string to locate. 1704 * @param __pos Index of character to search from (default 0). 1705 * @return Index of start of first occurrence. 1706 * 1707 * Starting from @a __pos, searches forward for the value of @a 1708 * __s within this string. If found, returns the index where 1709 * it begins. If not found, returns npos. 1710 */ 1711 size_type 1712 find(const _CharT* __s, size_type __pos = 0) const 1713 { 1714 __glibcxx_requires_string(__s); 1715 return this->find(__s, __pos, traits_type::length(__s)); 1716 } 1717 1718 /** 1719 * @brief Find position of a character. 1720 * @param __c Character to locate. 1721 * @param __pos Index of character to search from (default 0). 1722 * @return Index of first occurrence. 1723 * 1724 * Starting from @a __pos, searches forward for @a __c within 1725 * this string. If found, returns the index where it was 1726 * found. If not found, returns npos. 1727 */ 1728 size_type 1729 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; 1730 1731 /** 1732 * @brief Find last position of a string. 1733 * @param __str String to locate. 1734 * @param __pos Index of character to search back from (default end). 1735 * @return Index of start of last occurrence. 1736 * 1737 * Starting from @a __pos, searches backward for value of @a 1738 * __str within this string. If found, returns the index where 1739 * it begins. If not found, returns npos. 1740 */ 1741 size_type 1742 rfind(const __versa_string& __str, size_type __pos = npos) const 1743 _GLIBCXX_NOEXCEPT 1744 { return this->rfind(__str.data(), __pos, __str.size()); } 1745 1746 /** 1747 * @brief Find last position of a C substring. 1748 * @param __s C string to locate. 1749 * @param __pos Index of character to search back from. 1750 * @param __n Number of characters from s to search for. 1751 * @return Index of start of last occurrence. 1752 * 1753 * Starting from @a __pos, searches backward for the first @a 1754 * __n characters in @a __s within this string. If found, 1755 * returns the index where it begins. If not found, returns 1756 * npos. 1757 */ 1758 size_type 1759 rfind(const _CharT* __s, size_type __pos, size_type __n) const; 1760 1761 /** 1762 * @brief Find last position of a C string. 1763 * @param __s C string to locate. 1764 * @param __pos Index of character to start search at (default end). 1765 * @return Index of start of last occurrence. 1766 * 1767 * Starting from @a __pos, searches backward for the value of 1768 * @a __s within this string. If found, returns the index 1769 * where it begins. If not found, returns npos. 1770 */ 1771 size_type 1772 rfind(const _CharT* __s, size_type __pos = npos) const 1773 { 1774 __glibcxx_requires_string(__s); 1775 return this->rfind(__s, __pos, traits_type::length(__s)); 1776 } 1777 1778 /** 1779 * @brief Find last position of a character. 1780 * @param __c Character to locate. 1781 * @param __pos Index of character to search back from (default end). 1782 * @return Index of last occurrence. 1783 * 1784 * Starting from @a __pos, searches backward for @a __c within 1785 * this string. If found, returns the index where it was 1786 * found. If not found, returns npos. 1787 */ 1788 size_type 1789 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; 1790 1791 /** 1792 * @brief Find position of a character of string. 1793 * @param __str String containing characters to locate. 1794 * @param __pos Index of character to search from (default 0). 1795 * @return Index of first occurrence. 1796 * 1797 * Starting from @a __pos, searches forward for one of the characters of 1798 * @a __str within this string. If found, returns the index where it was 1799 * found. If not found, returns npos. 1800 */ 1801 size_type 1802 find_first_of(const __versa_string& __str, size_type __pos = 0) const 1803 _GLIBCXX_NOEXCEPT 1804 { return this->find_first_of(__str.data(), __pos, __str.size()); } 1805 1806 /** 1807 * @brief Find position of a character of C substring. 1808 * @param __s String containing characters to locate. 1809 * @param __pos Index of character to search from. 1810 * @param __n Number of characters from s to search for. 1811 * @return Index of first occurrence. 1812 * 1813 * Starting from @a __pos, searches forward for one of the 1814 * first @a __n characters of @a __s within this string. If 1815 * found, returns the index where it was found. If not found, 1816 * returns npos. 1817 */ 1818 size_type 1819 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const; 1820 1821 /** 1822 * @brief Find position of a character of C string. 1823 * @param __s String containing characters to locate. 1824 * @param __pos Index of character to search from (default 0). 1825 * @return Index of first occurrence. 1826 * 1827 * Starting from @a __pos, searches forward for one of the 1828 * characters of @a __s within this string. If found, returns 1829 * the index where it was found. If not found, returns npos. 1830 */ 1831 size_type 1832 find_first_of(const _CharT* __s, size_type __pos = 0) const 1833 { 1834 __glibcxx_requires_string(__s); 1835 return this->find_first_of(__s, __pos, traits_type::length(__s)); 1836 } 1837 1838 /** 1839 * @brief Find position of a character. 1840 * @param __c Character to locate. 1841 * @param __pos Index of character to search from (default 0). 1842 * @return Index of first occurrence. 1843 * 1844 * Starting from @a __pos, searches forward for the character 1845 * @a __c within this string. If found, returns the index 1846 * where it was found. If not found, returns npos. 1847 * 1848 * Note: equivalent to find(c, pos). 1849 */ 1850 size_type 1851 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT 1852 { return this->find(__c, __pos); } 1853 1854 /** 1855 * @brief Find last position of a character of string. 1856 * @param __str String containing characters to locate. 1857 * @param __pos Index of character to search back from (default end). 1858 * @return Index of last occurrence. 1859 * 1860 * Starting from @a __pos, searches backward for one of the 1861 * characters of @a __str within this string. If found, 1862 * returns the index where it was found. If not found, returns 1863 * npos. 1864 */ 1865 size_type 1866 find_last_of(const __versa_string& __str, size_type __pos = npos) const 1867 _GLIBCXX_NOEXCEPT 1868 { return this->find_last_of(__str.data(), __pos, __str.size()); } 1869 1870 /** 1871 * @brief Find last position of a character of C substring. 1872 * @param __s C string containing characters to locate. 1873 * @param __pos Index of character to search back from. 1874 * @param __n Number of characters from s to search for. 1875 * @return Index of last occurrence. 1876 * 1877 * Starting from @a __pos, searches backward for one of the 1878 * first @a __n characters of @a __s within this string. If 1879 * found, returns the index where it was found. If not found, 1880 * returns npos. 1881 */ 1882 size_type 1883 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const; 1884 1885 /** 1886 * @brief Find last position of a character of C string. 1887 * @param __s C string containing characters to locate. 1888 * @param __pos Index of character to search back from (default end). 1889 * @return Index of last occurrence. 1890 * 1891 * Starting from @a __pos, searches backward for one of the 1892 * characters of @a __s within this string. If found, returns 1893 * the index where it was found. If not found, returns npos. 1894 */ 1895 size_type 1896 find_last_of(const _CharT* __s, size_type __pos = npos) const 1897 { 1898 __glibcxx_requires_string(__s); 1899 return this->find_last_of(__s, __pos, traits_type::length(__s)); 1900 } 1901 1902 /** 1903 * @brief Find last position of a character. 1904 * @param __c Character to locate. 1905 * @param __pos Index of character to search back from (default end). 1906 * @return Index of last occurrence. 1907 * 1908 * Starting from @a __pos, searches backward for @a __c within 1909 * this string. If found, returns the index where it was 1910 * found. If not found, returns npos. 1911 * 1912 * Note: equivalent to rfind(c, pos). 1913 */ 1914 size_type 1915 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT 1916 { return this->rfind(__c, __pos); } 1917 1918 /** 1919 * @brief Find position of a character not in string. 1920 * @param __str String containing characters to avoid. 1921 * @param __pos Index of character to search from (default 0). 1922 * @return Index of first occurrence. 1923 * 1924 * Starting from @a __pos, searches forward for a character not 1925 * contained in @a __str within this string. If found, returns 1926 * the index where it was found. If not found, returns npos. 1927 */ 1928 size_type 1929 find_first_not_of(const __versa_string& __str, size_type __pos = 0) const 1930 _GLIBCXX_NOEXCEPT 1931 { return this->find_first_not_of(__str.data(), __pos, __str.size()); } 1932 1933 /** 1934 * @brief Find position of a character not in C substring. 1935 * @param __s C string containing characters to avoid. 1936 * @param __pos Index of character to search from. 1937 * @param __n Number of characters from s to consider. 1938 * @return Index of first occurrence. 1939 * 1940 * Starting from @a __pos, searches forward for a character not 1941 * contained in the first @a __n characters of @a __s within 1942 * this string. If found, returns the index where it was 1943 * found. If not found, returns npos. 1944 */ 1945 size_type 1946 find_first_not_of(const _CharT* __s, size_type __pos, 1947 size_type __n) const; 1948 1949 /** 1950 * @brief Find position of a character not in C string. 1951 * @param __s C string containing characters to avoid. 1952 * @param __pos Index of character to search from (default 0). 1953 * @return Index of first occurrence. 1954 * 1955 * Starting from @a __pos, searches forward for a character not 1956 * contained in @a __s within this string. If found, returns 1957 * the index where it was found. If not found, returns npos. 1958 */ 1959 size_type 1960 find_first_not_of(const _CharT* __s, size_type __pos = 0) const 1961 { 1962 __glibcxx_requires_string(__s); 1963 return this->find_first_not_of(__s, __pos, traits_type::length(__s)); 1964 } 1965 1966 /** 1967 * @brief Find position of a different character. 1968 * @param __c Character to avoid. 1969 * @param __pos Index of character to search from (default 0). 1970 * @return Index of first occurrence. 1971 * 1972 * Starting from @a __pos, searches forward for a character 1973 * other than @a __c within this string. If found, returns the 1974 * index where it was found. If not found, returns npos. 1975 */ 1976 size_type 1977 find_first_not_of(_CharT __c, size_type __pos = 0) const 1978 _GLIBCXX_NOEXCEPT; 1979 1980 /** 1981 * @brief Find last position of a character not in string. 1982 * @param __str String containing characters to avoid. 1983 * @param __pos Index of character to search back from (default end). 1984 * @return Index of last occurrence. 1985 * 1986 * Starting from @a __pos, searches backward for a character 1987 * not contained in @a __str within this string. If found, 1988 * returns the index where it was found. If not found, returns 1989 * npos. 1990 */ 1991 size_type 1992 find_last_not_of(const __versa_string& __str, 1993 size_type __pos = npos) const _GLIBCXX_NOEXCEPT 1994 { return this->find_last_not_of(__str.data(), __pos, __str.size()); } 1995 1996 /** 1997 * @brief Find last position of a character not in C substring. 1998 * @param __s C string containing characters to avoid. 1999 * @param __pos Index of character to search back from. 2000 * @param __n Number of characters from s to consider. 2001 * @return Index of last occurrence. 2002 * 2003 * Starting from @a __pos, searches backward for a character 2004 * not contained in the first @a __n characters of @a __s 2005 * within this string. If found, returns the index where it 2006 * was found. If not found, returns npos. 2007 */ 2008 size_type 2009 find_last_not_of(const _CharT* __s, size_type __pos, 2010 size_type __n) const; 2011 /** 2012 * @brief Find last position of a character not in C string. 2013 * @param __s C string containing characters to avoid. 2014 * @param __pos Index of character to search back from (default end). 2015 * @return Index of last occurrence. 2016 * 2017 * Starting from @a __pos, searches backward for a character 2018 * not contained in @a __s within this string. If found, 2019 * returns the index where it was found. If not found, returns 2020 * npos. 2021 */ 2022 size_type 2023 find_last_not_of(const _CharT* __s, size_type __pos = npos) const 2024 { 2025 __glibcxx_requires_string(__s); 2026 return this->find_last_not_of(__s, __pos, traits_type::length(__s)); 2027 } 2028 2029 /** 2030 * @brief Find last position of a different character. 2031 * @param __c Character to avoid. 2032 * @param __pos Index of character to search back from (default end). 2033 * @return Index of last occurrence. 2034 * 2035 * Starting from @a __pos, searches backward for a character 2036 * other than @a __c within this string. If found, returns the 2037 * index where it was found. If not found, returns npos. 2038 */ 2039 size_type 2040 find_last_not_of(_CharT __c, size_type __pos = npos) const 2041 _GLIBCXX_NOEXCEPT; 2042 2043 /** 2044 * @brief Get a substring. 2045 * @param __pos Index of first character (default 0). 2046 * @param __n Number of characters in substring (default remainder). 2047 * @return The new string. 2048 * @throw std::out_of_range If pos > size(). 2049 * 2050 * Construct and return a new string using the @a __n 2051 * characters starting at @a __pos. If the string is too 2052 * short, use the remainder of the characters. If @a __pos is 2053 * beyond the end of the string, out_of_range is thrown. 2054 */ 2055 __versa_string 2056 substr(size_type __pos = 0, size_type __n = npos) const 2057 { 2058 return __versa_string(*this, _M_check(__pos, "__versa_string::substr"), 2059 __n); 2060 } 2061 2062 /** 2063 * @brief Compare to a string. 2064 * @param __str String to compare against. 2065 * @return Integer < 0, 0, or > 0. 2066 * 2067 * Returns an integer < 0 if this string is ordered before @a 2068 * __str, 0 if their values are equivalent, or > 0 if this 2069 * string is ordered after @a __str. Determines the effective 2070 * length rlen of the strings to compare as the smallest of 2071 * size() and str.size(). The function then compares the two 2072 * strings by calling traits::compare(data(), str.data(),rlen). 2073 * If the result of the comparison is nonzero returns it, 2074 * otherwise the shorter one is ordered first. 2075 */ 2076 int 2077 compare(const __versa_string& __str) const 2078 { 2079 if (this->_M_compare(__str)) 2080 return 0; 2081 2082 const size_type __size = this->size(); 2083 const size_type __osize = __str.size(); 2084 const size_type __len = std::min(__size, __osize); 2085 2086 int __r = traits_type::compare(this->_M_data(), __str.data(), __len); 2087 if (!__r) 2088 __r = this->_S_compare(__size, __osize); 2089 return __r; 2090 } 2091 2092 /** 2093 * @brief Compare substring to a string. 2094 * @param __pos Index of first character of substring. 2095 * @param __n Number of characters in substring. 2096 * @param __str String to compare against. 2097 * @return Integer < 0, 0, or > 0. 2098 * 2099 * Form the substring of this string from the @a __n characters 2100 * starting at @a __pos. Returns an integer < 0 if the 2101 * substring is ordered before @a __str, 0 if their values are 2102 * equivalent, or > 0 if the substring is ordered after @a 2103 * __str. Determines the effective length rlen of the strings 2104 * to compare as the smallest of the length of the substring 2105 * and @a __str.size(). The function then compares the two 2106 * strings by calling 2107 * traits::compare(substring.data(),str.data(),rlen). If the 2108 * result of the comparison is nonzero returns it, otherwise 2109 * the shorter one is ordered first. 2110 */ 2111 int 2112 compare(size_type __pos, size_type __n, 2113 const __versa_string& __str) const; 2114 2115 /** 2116 * @brief Compare substring to a substring. 2117 * @param __pos1 Index of first character of substring. 2118 * @param __n1 Number of characters in substring. 2119 * @param __str String to compare against. 2120 * @param __pos2 Index of first character of substring of str. 2121 * @param __n2 Number of characters in substring of str. 2122 * @return Integer < 0, 0, or > 0. 2123 * 2124 * Form the substring of this string from the @a __n1 2125 * characters starting at @a __pos1. Form the substring of @a 2126 * __str from the @a __n2 characters starting at @a __pos2. 2127 * Returns an integer < 0 if this substring is ordered before 2128 * the substring of @a __str, 0 if their values are equivalent, 2129 * or > 0 if this substring is ordered after the substring of 2130 * @a __str. Determines the effective length rlen of the 2131 * strings to compare as the smallest of the lengths of the 2132 * substrings. The function then compares the two strings by 2133 * calling 2134 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). 2135 * If the result of the comparison is nonzero returns it, 2136 * otherwise the shorter one is ordered first. 2137 */ 2138 int 2139 compare(size_type __pos1, size_type __n1, const __versa_string& __str, 2140 size_type __pos2, size_type __n2) const; 2141 2142 /** 2143 * @brief Compare to a C string. 2144 * @param __s C string to compare against. 2145 * @return Integer < 0, 0, or > 0. 2146 * 2147 * Returns an integer < 0 if this string is ordered before @a 2148 * __s, 0 if their values are equivalent, or > 0 if this string 2149 * is ordered after @a __s. Determines the effective length 2150 * rlen of the strings to compare as the smallest of size() and 2151 * the length of a string constructed from @a __s. The 2152 * function then compares the two strings by calling 2153 * traits::compare(data(),s,rlen). If the result of the 2154 * comparison is nonzero returns it, otherwise the shorter one 2155 * is ordered first. 2156 */ 2157 int 2158 compare(const _CharT* __s) const; 2159 2160 // _GLIBCXX_RESOLVE_LIB_DEFECTS 2161 // 5 String::compare specification questionable 2162 /** 2163 * @brief Compare substring to a C string. 2164 * @param __pos Index of first character of substring. 2165 * @param __n1 Number of characters in substring. 2166 * @param __s C string to compare against. 2167 * @return Integer < 0, 0, or > 0. 2168 * 2169 * Form the substring of this string from the @a __n1 2170 * characters starting at @a __pos. Returns an integer < 0 if 2171 * the substring is ordered before @a __s, 0 if their values 2172 * are equivalent, or > 0 if the substring is ordered after @a 2173 * __s. Determines the effective length rlen of the strings to 2174 * compare as the smallest of the length of the substring and 2175 * the length of a string constructed from @a __s. The 2176 * function then compares the two string by calling 2177 * traits::compare(substring.data(),s,rlen). If the result of 2178 * the comparison is nonzero returns it, otherwise the shorter 2179 * one is ordered first. 2180 */ 2181 int 2182 compare(size_type __pos, size_type __n1, const _CharT* __s) const; 2183 2184 /** 2185 * @brief Compare substring against a character array. 2186 * @param __pos Index of first character of substring. 2187 * @param __n1 Number of characters in substring. 2188 * @param __s character array to compare against. 2189 * @param __n2 Number of characters of s. 2190 * @return Integer < 0, 0, or > 0. 2191 * 2192 * Form the substring of this string from the @a __n1 2193 * characters starting at @a __pos. Form a string from the 2194 * first @a __n2 characters of @a __s. Returns an integer < 0 2195 * if this substring is ordered before the string from @a __s, 2196 * 0 if their values are equivalent, or > 0 if this substring 2197 * is ordered after the string from @a __s. Determines the 2198 * effective length rlen of the strings to compare as the 2199 * smallest of the length of the substring and @a __n2. The 2200 * function then compares the two strings by calling 2201 * traits::compare(substring.data(),__s,rlen). If the result of 2202 * the comparison is nonzero returns it, otherwise the shorter 2203 * one is ordered first. 2204 * 2205 * NB: __s must have at least n2 characters,
\\0
has no special 2206 * meaning. 2207 */ 2208 int 2209 compare(size_type __pos, size_type __n1, const _CharT* __s, 2210 size_type __n2) const; 2211 }; 2212 2213 // operator+ 2214 /** 2215 * @brief Concatenate two strings. 2216 * @param __lhs First string. 2217 * @param __rhs Last string. 2218 * @return New string with value of @a __lhs followed by @a __rhs. 2219 */ 2220 template
class _Base> 2222 __versa_string<_CharT, _Traits, _Alloc, _Base> 2223 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2224 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 2225 2226 /** 2227 * @brief Concatenate C string and string. 2228 * @param __lhs First string. 2229 * @param __rhs Last string. 2230 * @return New string with value of @a __lhs followed by @a __rhs. 2231 */ 2232 template
class _Base> 2234 __versa_string<_CharT, _Traits, _Alloc, _Base> 2235 operator+(const _CharT* __lhs, 2236 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 2237 2238 /** 2239 * @brief Concatenate character and string. 2240 * @param __lhs First string. 2241 * @param __rhs Last string. 2242 * @return New string with @a __lhs followed by @a __rhs. 2243 */ 2244 template
class _Base> 2246 __versa_string<_CharT, _Traits, _Alloc, _Base> 2247 operator+(_CharT __lhs, 2248 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs); 2249 2250 /** 2251 * @brief Concatenate string and C string. 2252 * @param __lhs First string. 2253 * @param __rhs Last string. 2254 * @return New string with @a __lhs followed by @a __rhs. 2255 */ 2256 template
class _Base> 2258 __versa_string<_CharT, _Traits, _Alloc, _Base> 2259 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2260 const _CharT* __rhs); 2261 2262 /** 2263 * @brief Concatenate string and character. 2264 * @param __lhs First string. 2265 * @param __rhs Last string. 2266 * @return New string with @a __lhs followed by @a __rhs. 2267 */ 2268 template
class _Base> 2270 __versa_string<_CharT, _Traits, _Alloc, _Base> 2271 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2272 _CharT __rhs); 2273 2274 #if __cplusplus >= 201103L 2275 template
class _Base> 2277 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2278 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2279 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2280 { return std::move(__lhs.append(__rhs)); } 2281 2282 template
class _Base> 2284 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2285 operator+(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2286 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2287 { return std::move(__rhs.insert(0, __lhs)); } 2288 2289 template
class _Base> 2291 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2292 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2293 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2294 { 2295 const auto __size = __lhs.size() + __rhs.size(); 2296 const bool __cond = (__size > __lhs.capacity() 2297 && __size <= __rhs.capacity()); 2298 return __cond ? std::move(__rhs.insert(0, __lhs)) 2299 : std::move(__lhs.append(__rhs)); 2300 } 2301 2302 template
class _Base> 2304 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2305 operator+(const _CharT* __lhs, 2306 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2307 { return std::move(__rhs.insert(0, __lhs)); } 2308 2309 template
class _Base> 2311 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2312 operator+(_CharT __lhs, 2313 __versa_string<_CharT, _Traits, _Alloc, _Base>&& __rhs) 2314 { return std::move(__rhs.insert(0, 1, __lhs)); } 2315 2316 template
class _Base> 2318 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2319 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2320 const _CharT* __rhs) 2321 { return std::move(__lhs.append(__rhs)); } 2322 2323 template
class _Base> 2325 inline __versa_string<_CharT, _Traits, _Alloc, _Base> 2326 operator+(__versa_string<_CharT, _Traits, _Alloc, _Base>&& __lhs, 2327 _CharT __rhs) 2328 { return std::move(__lhs.append(1, __rhs)); } 2329 #endif 2330 2331 // operator == 2332 /** 2333 * @brief Test equivalence of two strings. 2334 * @param __lhs First string. 2335 * @param __rhs Second string. 2336 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 2337 */ 2338 template
class _Base> 2340 inline bool 2341 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2342 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2343 { 2344 return __lhs.size() == __rhs.size() 2345 && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size()); 2346 } 2347 2348 /** 2349 * @brief Test equivalence of string and C string. 2350 * @param __lhs String. 2351 * @param __rhs C string. 2352 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. 2353 */ 2354 template
class _Base> 2356 inline bool 2357 operator==(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2358 const _CharT* __rhs) 2359 { 2360 return __lhs.size() == _Traits::length(__rhs) 2361 && !_Traits::compare(__lhs.data(), __rhs, __lhs.size()); 2362 } 2363 2364 /** 2365 * @brief Test equivalence of C string and string. 2366 * @param __lhs C string. 2367 * @param __rhs String. 2368 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. 2369 */ 2370 template
class _Base> 2372 inline bool 2373 operator==(const _CharT* __lhs, 2374 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2375 { return __rhs == __lhs; } 2376 2377 // operator != 2378 /** 2379 * @brief Test difference of two strings. 2380 * @param __lhs First string. 2381 * @param __rhs Second string. 2382 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 2383 */ 2384 template
class _Base> 2386 inline bool 2387 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2388 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2389 { return !(__lhs == __rhs); } 2390 2391 /** 2392 * @brief Test difference of C string and string. 2393 * @param __lhs C string. 2394 * @param __rhs String. 2395 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. 2396 */ 2397 template
class _Base> 2399 inline bool 2400 operator!=(const _CharT* __lhs, 2401 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2402 { return !(__rhs == __lhs); } 2403 2404 /** 2405 * @brief Test difference of string and C string. 2406 * @param __lhs String. 2407 * @param __rhs C string. 2408 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. 2409 */ 2410 template
class _Base> 2412 inline bool 2413 operator!=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2414 const _CharT* __rhs) 2415 { return !(__lhs == __rhs); } 2416 2417 // operator < 2418 /** 2419 * @brief Test if string precedes string. 2420 * @param __lhs First string. 2421 * @param __rhs Second string. 2422 * @return True if @a __lhs precedes @a __rhs. False otherwise. 2423 */ 2424 template
class _Base> 2426 inline bool 2427 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2428 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2429 { return __lhs.compare(__rhs) < 0; } 2430 2431 /** 2432 * @brief Test if string precedes C string. 2433 * @param __lhs String. 2434 * @param __rhs C string. 2435 * @return True if @a __lhs precedes @a __rhs. False otherwise. 2436 */ 2437 template
class _Base> 2439 inline bool 2440 operator<(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2441 const _CharT* __rhs) 2442 { return __lhs.compare(__rhs) < 0; } 2443 2444 /** 2445 * @brief Test if C string precedes string. 2446 * @param __lhs C string. 2447 * @param __rhs String. 2448 * @return True if @a __lhs precedes @a __rhs. False otherwise. 2449 */ 2450 template
class _Base> 2452 inline bool 2453 operator<(const _CharT* __lhs, 2454 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2455 { return __rhs.compare(__lhs) > 0; } 2456 2457 // operator > 2458 /** 2459 * @brief Test if string follows string. 2460 * @param __lhs First string. 2461 * @param __rhs Second string. 2462 * @return True if @a __lhs follows @a __rhs. False otherwise. 2463 */ 2464 template
class _Base> 2466 inline bool 2467 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2468 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2469 { return __lhs.compare(__rhs) > 0; } 2470 2471 /** 2472 * @brief Test if string follows C string. 2473 * @param __lhs String. 2474 * @param __rhs C string. 2475 * @return True if @a __lhs follows @a __rhs. False otherwise. 2476 */ 2477 template
class _Base> 2479 inline bool 2480 operator>(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2481 const _CharT* __rhs) 2482 { return __lhs.compare(__rhs) > 0; } 2483 2484 /** 2485 * @brief Test if C string follows string. 2486 * @param __lhs C string. 2487 * @param __rhs String. 2488 * @return True if @a __lhs follows @a __rhs. False otherwise. 2489 */ 2490 template
class _Base> 2492 inline bool 2493 operator>(const _CharT* __lhs, 2494 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2495 { return __rhs.compare(__lhs) < 0; } 2496 2497 // operator <= 2498 /** 2499 * @brief Test if string doesn't follow string. 2500 * @param __lhs First string. 2501 * @param __rhs Second string. 2502 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2503 */ 2504 template
class _Base> 2506 inline bool 2507 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2508 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2509 { return __lhs.compare(__rhs) <= 0; } 2510 2511 /** 2512 * @brief Test if string doesn't follow C string. 2513 * @param __lhs String. 2514 * @param __rhs C string. 2515 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2516 */ 2517 template
class _Base> 2519 inline bool 2520 operator<=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2521 const _CharT* __rhs) 2522 { return __lhs.compare(__rhs) <= 0; } 2523 2524 /** 2525 * @brief Test if C string doesn't follow string. 2526 * @param __lhs C string. 2527 * @param __rhs String. 2528 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. 2529 */ 2530 template
class _Base> 2532 inline bool 2533 operator<=(const _CharT* __lhs, 2534 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2535 { return __rhs.compare(__lhs) >= 0; } 2536 2537 // operator >= 2538 /** 2539 * @brief Test if string doesn't precede string. 2540 * @param __lhs First string. 2541 * @param __rhs Second string. 2542 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2543 */ 2544 template
class _Base> 2546 inline bool 2547 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2548 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2549 { return __lhs.compare(__rhs) >= 0; } 2550 2551 /** 2552 * @brief Test if string doesn't precede C string. 2553 * @param __lhs String. 2554 * @param __rhs C string. 2555 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2556 */ 2557 template
class _Base> 2559 inline bool 2560 operator>=(const __versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2561 const _CharT* __rhs) 2562 { return __lhs.compare(__rhs) >= 0; } 2563 2564 /** 2565 * @brief Test if C string doesn't precede string. 2566 * @param __lhs C string. 2567 * @param __rhs String. 2568 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. 2569 */ 2570 template
class _Base> 2572 inline bool 2573 operator>=(const _CharT* __lhs, 2574 const __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2575 { return __rhs.compare(__lhs) <= 0; } 2576 2577 /** 2578 * @brief Swap contents of two strings. 2579 * @param __lhs First string. 2580 * @param __rhs Second string. 2581 * 2582 * Exchanges the contents of @a __lhs and @a __rhs in constant time. 2583 */ 2584 template
class _Base> 2586 inline void 2587 swap(__versa_string<_CharT, _Traits, _Alloc, _Base>& __lhs, 2588 __versa_string<_CharT, _Traits, _Alloc, _Base>& __rhs) 2589 { __lhs.swap(__rhs); } 2590 2591 _GLIBCXX_END_NAMESPACE_VERSION 2592 } // namespace 2593 2594 namespace std _GLIBCXX_VISIBILITY(default) 2595 { 2596 _GLIBCXX_BEGIN_NAMESPACE_VERSION 2597 2598 /** 2599 * @brief Read stream into a string. 2600 * @param __is Input stream. 2601 * @param __str Buffer to store into. 2602 * @return Reference to the input stream. 2603 * 2604 * Stores characters from @a __is into @a __str until whitespace is 2605 * found, the end of the stream is encountered, or str.max_size() 2606 * is reached. If is.width() is non-zero, that is the limit on the 2607 * number of characters stored into @a __str. Any previous 2608 * contents of @a __str are erased. 2609 */ 2610 template
class _Base> 2612 basic_istream<_CharT, _Traits>& 2613 operator>>(basic_istream<_CharT, _Traits>& __is, 2614 __gnu_cxx::__versa_string<_CharT, _Traits, 2615 _Alloc, _Base>& __str); 2616 2617 /** 2618 * @brief Write string to a stream. 2619 * @param __os Output stream. 2620 * @param __str String to write out. 2621 * @return Reference to the output stream. 2622 * 2623 * Output characters of @a __str into os following the same rules as for 2624 * writing a C string. 2625 */ 2626 template
class _Base> 2628 inline basic_ostream<_CharT, _Traits>& 2629 operator<<(basic_ostream<_CharT, _Traits>& __os, 2630 const __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, 2631 _Base>& __str) 2632 { 2633 // _GLIBCXX_RESOLVE_LIB_DEFECTS 2634 // 586. string inserter not a formatted function 2635 return __ostream_insert(__os, __str.data(), __str.size()); 2636 } 2637 2638 /** 2639 * @brief Read a line from stream into a string. 2640 * @param __is Input stream. 2641 * @param __str Buffer to store into. 2642 * @param __delim Character marking end of line. 2643 * @return Reference to the input stream. 2644 * 2645 * Stores characters from @a __is into @a __str until @a __delim is 2646 * found, the end of the stream is encountered, or str.max_size() 2647 * is reached. If is.width() is non-zero, that is the limit on the 2648 * number of characters stored into @a __str. Any previous 2649 * contents of @a __str are erased. If @a delim was encountered, 2650 * it is extracted but not stored into @a __str. 2651 */ 2652 template
class _Base> 2654 basic_istream<_CharT, _Traits>& 2655 getline(basic_istream<_CharT, _Traits>& __is, 2656 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str, 2657 _CharT __delim); 2658 2659 /** 2660 * @brief Read a line from stream into a string. 2661 * @param __is Input stream. 2662 * @param __str Buffer to store into. 2663 * @return Reference to the input stream. 2664 * 2665 * Stores characters from is into @a __str until '\n' is 2666 * found, the end of the stream is encountered, or str.max_size() 2667 * is reached. If is.width() is non-zero, that is the limit on the 2668 * number of characters stored into @a __str. Any previous 2669 * contents of @a __str are erased. If end of line was 2670 * encountered, it is extracted but not stored into @a __str. 2671 */ 2672 template
class _Base> 2674 inline basic_istream<_CharT, _Traits>& 2675 getline(basic_istream<_CharT, _Traits>& __is, 2676 __gnu_cxx::__versa_string<_CharT, _Traits, _Alloc, _Base>& __str) 2677 { return getline(__is, __str, __is.widen('\n')); } 2678 2679 _GLIBCXX_END_NAMESPACE_VERSION 2680 } // namespace 2681 2682 #if __cplusplus >= 201103L 2683 2684 #include
2685 2686 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 2687 { 2688 _GLIBCXX_BEGIN_NAMESPACE_VERSION 2689 2690 #if _GLIBCXX_USE_C99_STDLIB 2691 // 21.4 Numeric Conversions [string.conversions]. 2692 inline int 2693 stoi(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2694 { return __gnu_cxx::__stoa
(&std::strtol, "stoi", __str.c_str(), 2695 __idx, __base); } 2696 2697 inline long 2698 stol(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2699 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), 2700 __idx, __base); } 2701 2702 inline unsigned long 2703 stoul(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2704 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), 2705 __idx, __base); } 2706 2707 inline long long 2708 stoll(const __vstring& __str, std::size_t* __idx = 0, int __base = 10) 2709 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), 2710 __idx, __base); } 2711 2712 inline unsigned long long 2713 stoull(const __vstring& __str, std::size_t* __idx, int __base = 10) 2714 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), 2715 __idx, __base); } 2716 2717 // NB: strtof vs strtod. 2718 inline float 2719 stof(const __vstring& __str, std::size_t* __idx = 0) 2720 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } 2721 2722 inline double 2723 stod(const __vstring& __str, std::size_t* __idx = 0) 2724 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } 2725 2726 inline long double 2727 stold(const __vstring& __str, std::size_t* __idx = 0) 2728 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } 2729 #endif // _GLIBCXX_USE_C99_STDLIB 2730 2731 #if _GLIBCXX_USE_C99_STDIO 2732 // NB: (v)snprintf vs sprintf. 2733 2734 // DR 1261. 2735 inline __vstring 2736 to_string(int __val) 2737 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 4 * sizeof(int), 2738 "%d", __val); } 2739 2740 inline __vstring 2741 to_string(unsigned __val) 2742 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2743 4 * sizeof(unsigned), 2744 "%u", __val); } 2745 2746 inline __vstring 2747 to_string(long __val) 2748 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2749 4 * sizeof(long), 2750 "%ld", __val); } 2751 2752 inline __vstring 2753 to_string(unsigned long __val) 2754 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2755 4 * sizeof(unsigned long), 2756 "%lu", __val); } 2757 2758 2759 inline __vstring 2760 to_string(long long __val) 2761 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2762 4 * sizeof(long long), 2763 "%lld", __val); } 2764 2765 inline __vstring 2766 to_string(unsigned long long __val) 2767 { return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, 2768 4 * sizeof(unsigned long long), 2769 "%llu", __val); } 2770 2771 inline __vstring 2772 to_string(float __val) 2773 { 2774 const int __n = __numeric_traits
::__max_exponent10 + 20; 2775 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 2776 "%f", __val); 2777 } 2778 2779 inline __vstring 2780 to_string(double __val) 2781 { 2782 const int __n = __numeric_traits
::__max_exponent10 + 20; 2783 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 2784 "%f", __val); 2785 } 2786 2787 inline __vstring 2788 to_string(long double __val) 2789 { 2790 const int __n = __numeric_traits
::__max_exponent10 + 20; 2791 return __gnu_cxx::__to_xstring<__vstring>(&std::vsnprintf, __n, 2792 "%Lf", __val); 2793 } 2794 #endif // _GLIBCXX_USE_C99_STDIO 2795 2796 #if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR 2797 inline int 2798 stoi(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2799 { return __gnu_cxx::__stoa
(&std::wcstol, "stoi", __str.c_str(), 2800 __idx, __base); } 2801 2802 inline long 2803 stol(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2804 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), 2805 __idx, __base); } 2806 2807 inline unsigned long 2808 stoul(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2809 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), 2810 __idx, __base); } 2811 2812 inline long long 2813 stoll(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2814 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), 2815 __idx, __base); } 2816 2817 inline unsigned long long 2818 stoull(const __wvstring& __str, std::size_t* __idx = 0, int __base = 10) 2819 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), 2820 __idx, __base); } 2821 2822 // NB: wcstof vs wcstod. 2823 inline float 2824 stof(const __wvstring& __str, std::size_t* __idx = 0) 2825 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } 2826 2827 inline double 2828 stod(const __wvstring& __str, std::size_t* __idx = 0) 2829 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } 2830 2831 inline long double 2832 stold(const __wvstring& __str, std::size_t* __idx = 0) 2833 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } 2834 2835 #ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF 2836 // DR 1261. 2837 inline __wvstring 2838 to_wstring(int __val) 2839 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2840 4 * sizeof(int), 2841 L"%d", __val); } 2842 2843 inline __wvstring 2844 to_wstring(unsigned __val) 2845 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2846 4 * sizeof(unsigned), 2847 L"%u", __val); } 2848 2849 inline __wvstring 2850 to_wstring(long __val) 2851 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2852 4 * sizeof(long), 2853 L"%ld", __val); } 2854 2855 inline __wvstring 2856 to_wstring(unsigned long __val) 2857 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2858 4 * sizeof(unsigned long), 2859 L"%lu", __val); } 2860 2861 inline __wvstring 2862 to_wstring(long long __val) 2863 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2864 4 * sizeof(long long), 2865 L"%lld", __val); } 2866 2867 inline __wvstring 2868 to_wstring(unsigned long long __val) 2869 { return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, 2870 4 * sizeof(unsigned long long), 2871 L"%llu", __val); } 2872 2873 inline __wvstring 2874 to_wstring(float __val) 2875 { 2876 const int __n = __numeric_traits
::__max_exponent10 + 20; 2877 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 2878 L"%f", __val); 2879 } 2880 2881 inline __wvstring 2882 to_wstring(double __val) 2883 { 2884 const int __n = __numeric_traits
::__max_exponent10 + 20; 2885 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 2886 L"%f", __val); 2887 } 2888 2889 inline __wvstring 2890 to_wstring(long double __val) 2891 { 2892 const int __n = __numeric_traits
::__max_exponent10 + 20; 2893 return __gnu_cxx::__to_xstring<__wvstring>(&std::vswprintf, __n, 2894 L"%Lf", __val); 2895 } 2896 #endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF 2897 #endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR 2898 2899 _GLIBCXX_END_NAMESPACE_VERSION 2900 } // namespace 2901 2902 #endif 2903 2904 #if __cplusplus >= 201103L 2905 2906 #include
2907 2908 namespace std _GLIBCXX_VISIBILITY(default) 2909 { 2910 _GLIBCXX_BEGIN_NAMESPACE_VERSION 2911 2912 /// std::hash specialization for __vstring. 2913 template<> 2914 struct hash<__gnu_cxx::__vstring> 2915 : public __hash_base
2916 { 2917 size_t 2918 operator()(const __gnu_cxx::__vstring& __s) const noexcept 2919 { return std::_Hash_impl::hash(__s.data(), __s.length()); } 2920 }; 2921 2922 /// std::hash specialization for __wvstring. 2923 template<> 2924 struct hash<__gnu_cxx::__wvstring> 2925 : public __hash_base
2926 { 2927 size_t 2928 operator()(const __gnu_cxx::__wvstring& __s) const noexcept 2929 { return std::_Hash_impl::hash(__s.data(), 2930 __s.length() * sizeof(wchar_t)); } 2931 }; 2932 2933 /// std::hash specialization for __u16vstring. 2934 template<> 2935 struct hash<__gnu_cxx::__u16vstring> 2936 : public __hash_base
2937 { 2938 size_t 2939 operator()(const __gnu_cxx::__u16vstring& __s) const noexcept 2940 { return std::_Hash_impl::hash(__s.data(), 2941 __s.length() * sizeof(char16_t)); } 2942 }; 2943 2944 /// std::hash specialization for __u32vstring. 2945 template<> 2946 struct hash<__gnu_cxx::__u32vstring> 2947 : public __hash_base
2948 { 2949 size_t 2950 operator()(const __gnu_cxx::__u32vstring& __s) const noexcept 2951 { return std::_Hash_impl::hash(__s.data(), 2952 __s.length() * sizeof(char32_t)); } 2953 }; 2954 2955 _GLIBCXX_END_NAMESPACE_VERSION 2956 } // namespace 2957 2958 #endif // C++11 2959 2960 #include
2961 2962 #endif /* _VSTRING_H */
Contact us
|
About us
|
Term of use
|
Copyright © 2000-2025 MyWebUniversity.com ™