- tmp/tmp4vuxf2bb/{from.md → to.md} +141 -104
tmp/tmp4vuxf2bb/{from.md → to.md}
RENAMED
|
@@ -36,17 +36,17 @@ requirements.
|
|
| 36 |
Most classes specified in Clauses [[string.classes]] and
|
| 37 |
[[input.output]] need a set of related types and functions to complete
|
| 38 |
the definition of their semantics. These types and functions are
|
| 39 |
provided as a set of member typedefs and functions in the template
|
| 40 |
parameter ‘traits’ used by each such template. This subclause defines
|
| 41 |
-
the semantics
|
| 42 |
|
| 43 |
To specialize those templates to generate a string or iostream class to
|
| 44 |
handle a particular character container type `CharT`, that and its
|
| 45 |
related character traits class `Traits` are passed as a pair of
|
| 46 |
-
parameters to the string or iostream template as
|
| 47 |
-
`
|
| 48 |
|
| 49 |
This subclause specifies a struct template, `char_traits<charT>`, and
|
| 50 |
four explicit specializations of it, `char_traits<{}char>`,
|
| 51 |
`char_traits<char16_t>`, `char_traits<char32_t>`, and
|
| 52 |
`char_traits<wchar_t>`, all of which appear in the header `<string>` and
|
|
@@ -386,58 +386,58 @@ namespace std {
|
|
| 386 |
basic_string<charT,traits,Allocator>
|
| 387 |
operator+(basic_string<charT,traits,Allocator>&& lhs, charT rhs);
|
| 388 |
|
| 389 |
template<class charT, class traits, class Allocator>
|
| 390 |
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
| 391 |
-
const basic_string<charT,traits,Allocator>& rhs);
|
| 392 |
template<class charT, class traits, class Allocator>
|
| 393 |
bool operator==(const charT* lhs,
|
| 394 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 395 |
template<class charT, class traits, class Allocator>
|
| 396 |
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
| 397 |
const charT* rhs);
|
| 398 |
template<class charT, class traits, class Allocator>
|
| 399 |
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
| 400 |
-
const basic_string<charT,traits,Allocator>& rhs);
|
| 401 |
template<class charT, class traits, class Allocator>
|
| 402 |
bool operator!=(const charT* lhs,
|
| 403 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 404 |
template<class charT, class traits, class Allocator>
|
| 405 |
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
| 406 |
const charT* rhs);
|
| 407 |
|
| 408 |
template<class charT, class traits, class Allocator>
|
| 409 |
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
|
| 410 |
-
const basic_string<charT,traits,Allocator>& rhs);
|
| 411 |
template<class charT, class traits, class Allocator>
|
| 412 |
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
|
| 413 |
const charT* rhs);
|
| 414 |
template<class charT, class traits, class Allocator>
|
| 415 |
bool operator< (const charT* lhs,
|
| 416 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 417 |
template<class charT, class traits, class Allocator>
|
| 418 |
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
|
| 419 |
-
const basic_string<charT,traits,Allocator>& rhs);
|
| 420 |
template<class charT, class traits, class Allocator>
|
| 421 |
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
|
| 422 |
const charT* rhs);
|
| 423 |
template<class charT, class traits, class Allocator>
|
| 424 |
bool operator> (const charT* lhs,
|
| 425 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 426 |
|
| 427 |
template<class charT, class traits, class Allocator>
|
| 428 |
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
|
| 429 |
-
const basic_string<charT,traits,Allocator>& rhs);
|
| 430 |
template<class charT, class traits, class Allocator>
|
| 431 |
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
|
| 432 |
const charT* rhs);
|
| 433 |
template<class charT, class traits, class Allocator>
|
| 434 |
bool operator<=(const charT* lhs,
|
| 435 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 436 |
template<class charT, class traits, class Allocator>
|
| 437 |
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
|
| 438 |
-
const basic_string<charT,traits,Allocator>& rhs);
|
| 439 |
template<class charT, class traits, class Allocator>
|
| 440 |
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
|
| 441 |
const charT* rhs);
|
| 442 |
template<class charT, class traits, class Allocator>
|
| 443 |
bool operator>=(const charT* lhs,
|
|
@@ -523,10 +523,22 @@ namespace std {
|
|
| 523 |
template <class T> struct hash;
|
| 524 |
template <> struct hash<string>;
|
| 525 |
template <> struct hash<u16string>;
|
| 526 |
template <> struct hash<u32string>;
|
| 527 |
template <> struct hash<wstring>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
}
|
| 529 |
```
|
| 530 |
|
| 531 |
## Class template `basic_string` <a id="basic.string">[[basic.string]]</a>
|
| 532 |
|
|
@@ -578,11 +590,12 @@ namespace std {
|
|
| 578 |
typedef std::reverse_iterator<iterator> reverse_iterator;
|
| 579 |
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
| 580 |
static const size_type npos = -1;
|
| 581 |
|
| 582 |
// [string.cons], construct/copy/destroy:
|
| 583 |
-
|
|
|
|
| 584 |
basic_string(const basic_string& str);
|
| 585 |
basic_string(basic_string&& str) noexcept;
|
| 586 |
basic_string(const basic_string& str, size_type pos, size_type n = npos,
|
| 587 |
const Allocator& a = Allocator());
|
| 588 |
basic_string(const charT* s,
|
|
@@ -647,11 +660,11 @@ namespace std {
|
|
| 647 |
basic_string& operator+=(const charT* s);
|
| 648 |
basic_string& operator+=(charT c);
|
| 649 |
basic_string& operator+=(initializer_list<charT>);
|
| 650 |
basic_string& append(const basic_string& str);
|
| 651 |
basic_string& append(const basic_string& str, size_type pos,
|
| 652 |
-
size_type n);
|
| 653 |
basic_string& append(const charT* s, size_type n);
|
| 654 |
basic_string& append(const charT* s);
|
| 655 |
basic_string& append(size_type n, charT c);
|
| 656 |
template<class InputIterator>
|
| 657 |
basic_string& append(InputIterator first, InputIterator last);
|
|
@@ -659,21 +672,21 @@ namespace std {
|
|
| 659 |
void push_back(charT c);
|
| 660 |
|
| 661 |
basic_string& assign(const basic_string& str);
|
| 662 |
basic_string& assign(basic_string&& str) noexcept;
|
| 663 |
basic_string& assign(const basic_string& str, size_type pos,
|
| 664 |
-
size_type n);
|
| 665 |
basic_string& assign(const charT* s, size_type n);
|
| 666 |
basic_string& assign(const charT* s);
|
| 667 |
basic_string& assign(size_type n, charT c);
|
| 668 |
template<class InputIterator>
|
| 669 |
basic_string& assign(InputIterator first, InputIterator last);
|
| 670 |
basic_string& assign(initializer_list<charT>);
|
| 671 |
|
| 672 |
basic_string& insert(size_type pos1, const basic_string& str);
|
| 673 |
basic_string& insert(size_type pos1, const basic_string& str,
|
| 674 |
-
size_type pos2, size_type n);
|
| 675 |
basic_string& insert(size_type pos, const charT* s, size_type n);
|
| 676 |
basic_string& insert(size_type pos, const charT* s);
|
| 677 |
basic_string& insert(size_type pos, size_type n, charT c);
|
| 678 |
iterator insert(const_iterator p, charT c);
|
| 679 |
iterator insert(const_iterator p, size_type n, charT c);
|
|
@@ -689,11 +702,11 @@ namespace std {
|
|
| 689 |
|
| 690 |
basic_string& replace(size_type pos1, size_type n1,
|
| 691 |
const basic_string& str);
|
| 692 |
basic_string& replace(size_type pos1, size_type n1,
|
| 693 |
const basic_string& str,
|
| 694 |
-
size_type pos2, size_type n2);
|
| 695 |
basic_string& replace(size_type pos, size_type n1, const charT* s,
|
| 696 |
size_type n2);
|
| 697 |
basic_string& replace(size_type pos, size_type n1, const charT* s);
|
| 698 |
basic_string& replace(size_type pos, size_type n1, size_type n2,
|
| 699 |
charT c);
|
|
@@ -719,50 +732,50 @@ namespace std {
|
|
| 719 |
allocator_type get_allocator() const noexcept;
|
| 720 |
|
| 721 |
size_type find (const basic_string& str, size_type pos = 0) const noexcept;
|
| 722 |
size_type find (const charT* s, size_type pos, size_type n) const;
|
| 723 |
size_type find (const charT* s, size_type pos = 0) const;
|
| 724 |
-
size_type find (charT c, size_type pos = 0) const
|
| 725 |
size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
|
| 726 |
size_type rfind(const charT* s, size_type pos, size_type n) const;
|
| 727 |
size_type rfind(const charT* s, size_type pos = npos) const;
|
| 728 |
-
size_type rfind(charT c, size_type pos = npos) const
|
| 729 |
|
| 730 |
size_type find_first_of(const basic_string& str,
|
| 731 |
size_type pos = 0) const noexcept;
|
| 732 |
size_type find_first_of(const charT* s,
|
| 733 |
size_type pos, size_type n) const;
|
| 734 |
size_type find_first_of(const charT* s, size_type pos = 0) const;
|
| 735 |
-
size_type find_first_of(charT c, size_type pos = 0) const
|
| 736 |
size_type find_last_of (const basic_string& str,
|
| 737 |
size_type pos = npos) const noexcept;
|
| 738 |
size_type find_last_of (const charT* s,
|
| 739 |
size_type pos, size_type n) const;
|
| 740 |
size_type find_last_of (const charT* s, size_type pos = npos) const;
|
| 741 |
-
size_type find_last_of (charT c, size_type pos = npos) const
|
| 742 |
|
| 743 |
size_type find_first_not_of(const basic_string& str,
|
| 744 |
size_type pos = 0) const noexcept;
|
| 745 |
size_type find_first_not_of(const charT* s, size_type pos,
|
| 746 |
size_type n) const;
|
| 747 |
size_type find_first_not_of(const charT* s, size_type pos = 0) const;
|
| 748 |
-
size_type find_first_not_of(charT c, size_type pos = 0) const
|
| 749 |
size_type find_last_not_of (const basic_string& str,
|
| 750 |
size_type pos = npos) const noexcept;
|
| 751 |
size_type find_last_not_of (const charT* s, size_type pos,
|
| 752 |
size_type n) const;
|
| 753 |
size_type find_last_not_of (const charT* s,
|
| 754 |
size_type pos = npos) const;
|
| 755 |
-
size_type find_last_not_of (charT c, size_type pos = npos) const
|
| 756 |
|
| 757 |
basic_string substr(size_type pos = 0, size_type n = npos) const;
|
| 758 |
int compare(const basic_string& str) const noexcept;
|
| 759 |
int compare(size_type pos1, size_type n1,
|
| 760 |
const basic_string& str) const;
|
| 761 |
int compare(size_type pos1, size_type n1,
|
| 762 |
const basic_string& str,
|
| 763 |
-
size_type pos2, size_type n2) const;
|
| 764 |
int compare(const charT* s) const;
|
| 765 |
int compare(size_type pos1, size_type n1,
|
| 766 |
const charT* s) const;
|
| 767 |
int compare(size_type pos1, size_type n1,
|
| 768 |
const charT* s, size_type n2) const;
|
|
@@ -776,12 +789,10 @@ If any operation would cause `size()` to exceed `max_size()`, that
|
|
| 776 |
operation shall throw an exception object of type `length_error`.
|
| 777 |
|
| 778 |
If any member function or operator of `basic_string` throws an
|
| 779 |
exception, that function or operator shall have no other effect.
|
| 780 |
|
| 781 |
-
No `erase()` or `pop_back()` member function shall throw any exceptions.
|
| 782 |
-
|
| 783 |
In every specialization `basic_string<charT, traits, Allocator>`, the
|
| 784 |
type `allocator_traits<Allocator>::value_type` shall name the same type
|
| 785 |
as `charT`. Every object of type
|
| 786 |
`basic_string<charT, traits, Allocator>` shall use an object of type
|
| 787 |
`Allocator` to allocate and free storage for the contained `charT`
|
|
@@ -803,11 +814,11 @@ References, pointers, and iterators referring to the elements of a
|
|
| 803 |
`front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
|
| 804 |
|
| 805 |
### `basic_string` constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
|
| 806 |
|
| 807 |
``` cpp
|
| 808 |
-
explicit basic_string(const Allocator& a
|
| 809 |
```
|
| 810 |
|
| 811 |
*Effects:* Constructs an object of class `basic_string`. The
|
| 812 |
postconditions of this function are indicated in
|
| 813 |
Table [[tab:strings.ctr.1]].
|
|
@@ -819,31 +830,28 @@ Table [[tab:strings.ctr.1]].
|
|
| 819 |
| `data()` | a non-null pointer that is copyable and can have 0 added to it |
|
| 820 |
| `size()` | 0 |
|
| 821 |
| `capacity()` | an unspecified value |
|
| 822 |
|
| 823 |
``` cpp
|
| 824 |
-
basic_string(const basic_string
|
| 825 |
-
basic_string(basic_string
|
| 826 |
```
|
| 827 |
|
| 828 |
*Effects:* Constructs an object of class `basic_string` as indicated in
|
| 829 |
Table [[tab:strings.ctr.cpy]]. In the second form, `str` is left in a
|
| 830 |
valid state with an unspecified value.
|
| 831 |
|
| 832 |
-
*Throws:* The second form throws nothing if the allocator’s move
|
| 833 |
-
constructor throws nothing.
|
| 834 |
-
|
| 835 |
**Table: `basic_string(const basic_string&)` effects** <a id="tab:strings.ctr.cpy">[tab:strings.ctr.cpy]</a>
|
| 836 |
|
| 837 |
| Element | Value |
|
| 838 |
| ------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 839 |
| `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
|
| 840 |
| `size()` | `str.size()` |
|
| 841 |
| `capacity()` | a value at least as large as `size()` |
|
| 842 |
|
| 843 |
``` cpp
|
| 844 |
-
basic_string(const basic_string
|
| 845 |
size_type pos, size_type n = npos,
|
| 846 |
const Allocator& a = Allocator());
|
| 847 |
```
|
| 848 |
|
| 849 |
*Requires:* `pos <= str.size()`
|
|
@@ -866,11 +874,11 @@ Table [[tab:strings.ctr.2]].
|
|
| 866 |
``` cpp
|
| 867 |
basic_string(const charT* s, size_type n,
|
| 868 |
const Allocator& a = Allocator());
|
| 869 |
```
|
| 870 |
|
| 871 |
-
*Requires:* `s`
|
| 872 |
|
| 873 |
*Effects:* Constructs an object of class `basic_string` and determines
|
| 874 |
its initial string value from the array of `charT` of length `n` whose
|
| 875 |
first element is designated by `s`, as indicated in
|
| 876 |
Table [[tab:strings.ctr.3]].
|
|
@@ -885,11 +893,12 @@ Table [[tab:strings.ctr.3]].
|
|
| 885 |
|
| 886 |
``` cpp
|
| 887 |
basic_string(const charT* s, const Allocator& a = Allocator());
|
| 888 |
```
|
| 889 |
|
| 890 |
-
*Requires:* `s`
|
|
|
|
| 891 |
|
| 892 |
*Effects:* Constructs an object of class `basic_string` and determines
|
| 893 |
its initial string value from the array of `charT` of length
|
| 894 |
`traits::length(s)` whose first element is designated by `s`, as
|
| 895 |
indicated in Table [[tab:strings.ctr.4]].
|
|
@@ -965,68 +974,64 @@ unspecified value.
|
|
| 965 |
| `capacity()` | a value at least as large as `size()` |
|
| 966 |
| `get_allocator()` | `alloc` |
|
| 967 |
|
| 968 |
|
| 969 |
*Throws:* The second form throws nothing if
|
| 970 |
-
`alloc == str.get_allocator()`
|
| 971 |
-
`Allocator` throws.
|
| 972 |
|
| 973 |
``` cpp
|
| 974 |
-
basic_string
|
| 975 |
-
operator=(const basic_string<charT,traits,Allocator>& str);
|
| 976 |
```
|
| 977 |
|
| 978 |
*Effects:* If `*this` and `str` are not the same object, modifies
|
| 979 |
`*this` as shown in Table [[tab:strings.op=]].
|
| 980 |
|
| 981 |
If `*this` and `str` are the same object, the member has no effect.
|
| 982 |
|
| 983 |
*Returns:* `*this`
|
| 984 |
|
| 985 |
-
**Table: `operator=(const basic_string
|
| 986 |
|
| 987 |
| Element | Value |
|
| 988 |
| ------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 989 |
| `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
|
| 990 |
| `size()` | `str.size()` |
|
| 991 |
| `capacity()` | a value at least as large as `size()` |
|
| 992 |
|
| 993 |
``` cpp
|
| 994 |
-
basic_string
|
| 995 |
-
operator=(basic_string<charT,traits,Allocator>&& str) noexcept;
|
| 996 |
```
|
| 997 |
|
| 998 |
*Effects:* If `*this` and `str` are not the same object, modifies
|
| 999 |
`*this` as shown in Table [[tab:strings.op=rv]]. A valid implementation
|
| 1000 |
is `swap(str)`.
|
| 1001 |
|
| 1002 |
If `*this` and `str` are the same object, the member has no effect.
|
| 1003 |
|
| 1004 |
*Returns:* `*this`
|
| 1005 |
|
| 1006 |
-
**Table: `operator=(
|
| 1007 |
|
| 1008 |
| Element | Value |
|
| 1009 |
| ------------ | ---------------------------------------------------------------------- |
|
| 1010 |
| `data()` | points at the array whose first element was pointed at by `str.data()` |
|
| 1011 |
| `size()` | previous value of `str.size()` |
|
| 1012 |
| `capacity()` | a value at least as large as `size()` |
|
| 1013 |
|
| 1014 |
``` cpp
|
| 1015 |
-
basic_string
|
| 1016 |
-
operator=(const charT* s);
|
| 1017 |
```
|
| 1018 |
|
| 1019 |
-
*Returns:* `*this = basic_string
|
| 1020 |
|
| 1021 |
*Remarks:* Uses `traits::length()`.
|
| 1022 |
|
| 1023 |
``` cpp
|
| 1024 |
-
basic_string
|
| 1025 |
```
|
| 1026 |
|
| 1027 |
-
*Returns:* `*this = basic_string
|
| 1028 |
|
| 1029 |
``` cpp
|
| 1030 |
basic_string& operator=(initializer_list<charT> il);
|
| 1031 |
```
|
| 1032 |
|
|
@@ -1077,11 +1082,11 @@ size_type size() const noexcept;
|
|
| 1077 |
```
|
| 1078 |
|
| 1079 |
*Returns:* A count of the number of char-like objects currently in the
|
| 1080 |
string.
|
| 1081 |
|
| 1082 |
-
*Complexity:*
|
| 1083 |
|
| 1084 |
``` cpp
|
| 1085 |
size_type length() const noexcept;
|
| 1086 |
```
|
| 1087 |
|
|
@@ -1091,11 +1096,11 @@ size_type length() const noexcept;
|
|
| 1091 |
size_type max_size() const noexcept;
|
| 1092 |
```
|
| 1093 |
|
| 1094 |
*Returns:* The size of the largest possible string.
|
| 1095 |
|
| 1096 |
-
*Complexity:*
|
| 1097 |
|
| 1098 |
``` cpp
|
| 1099 |
void resize(size_type n, charT c);
|
| 1100 |
```
|
| 1101 |
|
|
@@ -1179,19 +1184,17 @@ reference operator[](size_type pos);
|
|
| 1179 |
reference to an object of type `charT` with value `charT()`, where
|
| 1180 |
modifying the object leads to undefined behavior.
|
| 1181 |
|
| 1182 |
*Throws:* Nothing.
|
| 1183 |
|
| 1184 |
-
*Complexity:*
|
| 1185 |
|
| 1186 |
``` cpp
|
| 1187 |
const_reference at(size_type pos) const;
|
| 1188 |
reference at(size_type pos);
|
| 1189 |
```
|
| 1190 |
|
| 1191 |
-
*Requires:* `pos < size()`
|
| 1192 |
-
|
| 1193 |
*Throws:* `out_of_range` if `pos >= size()`.
|
| 1194 |
|
| 1195 |
*Returns:* `operator[](pos)`.
|
| 1196 |
|
| 1197 |
``` cpp
|
|
@@ -1260,11 +1263,11 @@ basic_string&
|
|
| 1260 |
|
| 1261 |
*Returns:* `*this`.
|
| 1262 |
|
| 1263 |
``` cpp
|
| 1264 |
basic_string&
|
| 1265 |
-
append(const basic_string& str, size_type pos, size_type n);
|
| 1266 |
```
|
| 1267 |
|
| 1268 |
*Requires:* `pos <= str.size()`
|
| 1269 |
|
| 1270 |
*Throws:* `out_of_range` if `pos > str.size()`.
|
|
@@ -1328,11 +1331,11 @@ basic_string& append(initializer_list<charT> il);
|
|
| 1328 |
*Effects:* Calls `append(il.begin(), il.size())`.
|
| 1329 |
|
| 1330 |
*Returns:* `*this`.
|
| 1331 |
|
| 1332 |
``` cpp
|
| 1333 |
-
void push_back(charT c)
|
| 1334 |
```
|
| 1335 |
|
| 1336 |
*Effects:* Equivalent to `append(static_cast<size_type>(1), c)`.
|
| 1337 |
|
| 1338 |
#### `basic_string::assign` <a id="string::assign">[[string::assign]]</a>
|
|
@@ -1356,11 +1359,11 @@ controlled by `str`. A valid implementation is `swap(str)`.
|
|
| 1356 |
*Returns:* `*this`.
|
| 1357 |
|
| 1358 |
``` cpp
|
| 1359 |
basic_string&
|
| 1360 |
assign(const basic_string& str, size_type pos,
|
| 1361 |
-
size_type n);
|
| 1362 |
```
|
| 1363 |
|
| 1364 |
*Requires:* `pos <= str.size()`
|
| 1365 |
|
| 1366 |
*Throws:* `out_of_range` if `pos > str.size()`.
|
|
@@ -1438,11 +1441,11 @@ basic_string&
|
|
| 1438 |
|
| 1439 |
``` cpp
|
| 1440 |
basic_string&
|
| 1441 |
insert(size_type pos1,
|
| 1442 |
const basic_string& str,
|
| 1443 |
-
size_type pos2, size_type n);
|
| 1444 |
```
|
| 1445 |
|
| 1446 |
*Requires:* `pos1 <= size()` and `pos2 <= str.size()`
|
| 1447 |
|
| 1448 |
*Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
|
|
@@ -1542,12 +1545,11 @@ iterator insert(const_iterator p, initializer_list<charT> il);
|
|
| 1542 |
character, or `p` if `i1` is empty.
|
| 1543 |
|
| 1544 |
#### `basic_string::erase` <a id="string::erase">[[string::erase]]</a>
|
| 1545 |
|
| 1546 |
``` cpp
|
| 1547 |
-
basic_string
|
| 1548 |
-
erase(size_type pos = 0, size_type n = npos);
|
| 1549 |
```
|
| 1550 |
|
| 1551 |
*Requires:* `pos` ` <= size()`
|
| 1552 |
|
| 1553 |
*Throws:* `out_of_range` if `pos` `> size()`.
|
|
@@ -1565,10 +1567,12 @@ string controlled by `*this` beginning at position `pos + xlen`.
|
|
| 1565 |
|
| 1566 |
``` cpp
|
| 1567 |
iterator erase(const_iterator p);
|
| 1568 |
```
|
| 1569 |
|
|
|
|
|
|
|
| 1570 |
*Effects:* removes the character referred to by `p`.
|
| 1571 |
|
| 1572 |
*Returns:* An iterator which points to the element immediately following
|
| 1573 |
`p` prior to the element being erased. If no such element exists,
|
| 1574 |
`end()` is returned.
|
|
@@ -1578,10 +1582,12 @@ iterator erase(const_iterator first, const_iterator last);
|
|
| 1578 |
```
|
| 1579 |
|
| 1580 |
*Requires:* `first` and `last` are valid iterators on `*this`, defining
|
| 1581 |
a range `[first,last)`.
|
| 1582 |
|
|
|
|
|
|
|
| 1583 |
*Effects:* removes the characters in the range `[first,last)`.
|
| 1584 |
|
| 1585 |
*Returns:* An iterator which points to the element pointed to by `last`
|
| 1586 |
prior to the other elements being erased. If no such element exists,
|
| 1587 |
`end()` is returned.
|
|
@@ -1590,10 +1596,12 @@ prior to the other elements being erased. If no such element exists,
|
|
| 1590 |
void pop_back();
|
| 1591 |
```
|
| 1592 |
|
| 1593 |
*Requires:* `!empty()`
|
| 1594 |
|
|
|
|
|
|
|
| 1595 |
*Effects:* Equivalent to `erase(size() - 1, 1)`.
|
| 1596 |
|
| 1597 |
#### `basic_string::replace` <a id="string::replace">[[string::replace]]</a>
|
| 1598 |
|
| 1599 |
``` cpp
|
|
@@ -1612,11 +1620,11 @@ basic_string&
|
|
| 1612 |
|
| 1613 |
``` cpp
|
| 1614 |
basic_string&
|
| 1615 |
replace(size_type pos1, size_type n1,
|
| 1616 |
const basic_string& str,
|
| 1617 |
-
size_type pos2, size_type n2);
|
| 1618 |
```
|
| 1619 |
|
| 1620 |
*Requires:* `pos1 <= size()` and `pos2 <= str.size()`.
|
| 1621 |
|
| 1622 |
*Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
|
|
@@ -1738,11 +1746,11 @@ basic_string& replace(const_iterator i1, const_iterator i2,
|
|
| 1738 |
*Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
|
| 1739 |
|
| 1740 |
*Effects:* Calls
|
| 1741 |
`replace(i1 - begin(), i2 - i1, il.begin(), il.size())`.
|
| 1742 |
|
| 1743 |
-
`*this`.
|
| 1744 |
|
| 1745 |
#### `basic_string::copy` <a id="string::copy">[[string::copy]]</a>
|
| 1746 |
|
| 1747 |
``` cpp
|
| 1748 |
size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
|
@@ -1766,19 +1774,19 @@ The function does not append a null object to the string designated by
|
|
| 1766 |
*Returns:* `rlen`.
|
| 1767 |
|
| 1768 |
#### `basic_string::swap` <a id="string::swap">[[string::swap]]</a>
|
| 1769 |
|
| 1770 |
``` cpp
|
| 1771 |
-
void swap(basic_string
|
| 1772 |
```
|
| 1773 |
|
| 1774 |
`*this` contains the same sequence of characters that was in `s`, `s`
|
| 1775 |
contains the same sequence of characters that was in `*this`.
|
| 1776 |
|
| 1777 |
*Throws:* Nothing.
|
| 1778 |
|
| 1779 |
-
*Complexity:*
|
| 1780 |
|
| 1781 |
### `basic_string` string operations <a id="string.ops">[[string.ops]]</a>
|
| 1782 |
|
| 1783 |
#### `basic_string` accessors <a id="string.accessors">[[string.accessors]]</a>
|
| 1784 |
|
|
@@ -1788,11 +1796,11 @@ const charT* data() const noexcept;
|
|
| 1788 |
```
|
| 1789 |
|
| 1790 |
*Returns:* A pointer `p` such that `p + i == &operator[](i)` for each
|
| 1791 |
`i` in \[`0`, `size()`\].
|
| 1792 |
|
| 1793 |
-
*Complexity:*
|
| 1794 |
|
| 1795 |
*Requires:* The program shall not alter any of the values stored in the
|
| 1796 |
character array.
|
| 1797 |
|
| 1798 |
``` cpp
|
|
@@ -1824,26 +1832,26 @@ Otherwise, returns `npos`.
|
|
| 1824 |
|
| 1825 |
``` cpp
|
| 1826 |
size_type find(const charT* s, size_type pos, size_type n) const;
|
| 1827 |
```
|
| 1828 |
|
| 1829 |
-
*Returns:* `find(basic_string
|
| 1830 |
|
| 1831 |
``` cpp
|
| 1832 |
-
size_type find(const charT* s, size_type pos = 0) const
|
| 1833 |
```
|
| 1834 |
|
| 1835 |
*Requires:* `s` points to an array of at least `traits::length(s) + 1`
|
| 1836 |
elements of `charT`.
|
| 1837 |
|
| 1838 |
*Returns:* `find(basic_string(s), pos)`.
|
| 1839 |
|
| 1840 |
``` cpp
|
| 1841 |
-
size_type find(charT c, size_type pos = 0) const
|
| 1842 |
```
|
| 1843 |
|
| 1844 |
-
*Returns:* `find(basic_string
|
| 1845 |
|
| 1846 |
#### `basic_string::rfind` <a id="string::rfind">[[string::rfind]]</a>
|
| 1847 |
|
| 1848 |
``` cpp
|
| 1849 |
size_type rfind(const basic_string& str,
|
|
@@ -1876,14 +1884,14 @@ size_type rfind(const charT* s, size_type pos = npos) const;
|
|
| 1876 |
elements of `charT`.
|
| 1877 |
|
| 1878 |
*Returns:* `rfind(basic_string(s), pos)`.
|
| 1879 |
|
| 1880 |
``` cpp
|
| 1881 |
-
size_type rfind(charT c, size_type pos = npos) const
|
| 1882 |
```
|
| 1883 |
|
| 1884 |
-
*Returns:* `rfind(basic_string
|
| 1885 |
|
| 1886 |
#### `basic_string::find_first_of` <a id="string::find.first.of">[[string::find.first.of]]</a>
|
| 1887 |
|
| 1888 |
``` cpp
|
| 1889 |
size_type
|
|
@@ -1918,15 +1926,14 @@ size_type find_first_of(const charT* s, size_type pos = 0) const;
|
|
| 1918 |
elements of `charT`.
|
| 1919 |
|
| 1920 |
*Returns:* `find_first_of(basic_string(s), pos)`.
|
| 1921 |
|
| 1922 |
``` cpp
|
| 1923 |
-
size_type find_first_of(charT c, size_type pos = 0) const
|
| 1924 |
```
|
| 1925 |
|
| 1926 |
-
*Returns:*
|
| 1927 |
-
`find_first_of(basic_string<charT,traits,Allocator>(1,c), pos)`.
|
| 1928 |
|
| 1929 |
#### `basic_string::find_last_of` <a id="string::find.last.of">[[string::find.last.of]]</a>
|
| 1930 |
|
| 1931 |
``` cpp
|
| 1932 |
size_type
|
|
@@ -1960,15 +1967,14 @@ size_type find_last_of(const charT* s, size_type pos = npos) const;
|
|
| 1960 |
elements of `charT`.
|
| 1961 |
|
| 1962 |
*Returns:* `find_last_of(basic_string(s), pos)`.
|
| 1963 |
|
| 1964 |
``` cpp
|
| 1965 |
-
size_type find_last_of(charT c, size_type pos = npos) const
|
| 1966 |
```
|
| 1967 |
|
| 1968 |
-
*Returns:*
|
| 1969 |
-
`find_last_of(basic_string<charT,traits,Allocator>(1,c),pos)`.
|
| 1970 |
|
| 1971 |
#### `basic_string::find_first_not_of` <a id="string::find.first.not.of">[[string::find.first.not.of]]</a>
|
| 1972 |
|
| 1973 |
``` cpp
|
| 1974 |
size_type
|
|
@@ -2003,11 +2009,11 @@ size_type find_first_not_of(const charT* s, size_type pos = 0) const;
|
|
| 2003 |
elements of `charT`.
|
| 2004 |
|
| 2005 |
*Returns:* `find_first_not_of(basic_string(s), pos)`.
|
| 2006 |
|
| 2007 |
``` cpp
|
| 2008 |
-
size_type find_first_not_of(charT c, size_type pos = 0) const
|
| 2009 |
```
|
| 2010 |
|
| 2011 |
*Returns:* `find_first_not_of(basic_string(1, c), pos)`.
|
| 2012 |
|
| 2013 |
#### `basic_string::find_last_not_of` <a id="string::find.last.not.of">[[string::find.last.not.of]]</a>
|
|
@@ -2045,30 +2051,29 @@ size_type find_last_not_of(const charT* s, size_type pos = npos) const;
|
|
| 2045 |
elements of `charT`.
|
| 2046 |
|
| 2047 |
*Returns:* `find_last_not_of(basic_string(s), pos)`.
|
| 2048 |
|
| 2049 |
``` cpp
|
| 2050 |
-
size_type find_last_not_of(charT c, size_type pos = npos) const
|
| 2051 |
```
|
| 2052 |
|
| 2053 |
*Returns:* `find_last_not_of(basic_string(1, c), pos)`.
|
| 2054 |
|
| 2055 |
#### `basic_string::substr` <a id="string::substr">[[string::substr]]</a>
|
| 2056 |
|
| 2057 |
``` cpp
|
| 2058 |
-
basic_string
|
| 2059 |
-
substr(size_type pos = 0, size_type n = npos) const;
|
| 2060 |
```
|
| 2061 |
|
| 2062 |
*Requires:* `pos <= size()`
|
| 2063 |
|
| 2064 |
*Throws:* `out_of_range` if `pos > size()`.
|
| 2065 |
|
| 2066 |
*Effects:* Determines the effective length `rlen` of the string to copy
|
| 2067 |
as the smaller of `n` and `size() - pos`.
|
| 2068 |
|
| 2069 |
-
*Returns:* `basic_string
|
| 2070 |
|
| 2071 |
#### `basic_string::compare` <a id="string::compare">[[string::compare]]</a>
|
| 2072 |
|
| 2073 |
``` cpp
|
| 2074 |
int compare(const basic_string& str) const noexcept;
|
|
@@ -2099,11 +2104,11 @@ int compare(size_type pos1, size_type n1,
|
|
| 2099 |
*Returns:* `basic_string(*this,pos1,n1).compare(str)`.
|
| 2100 |
|
| 2101 |
``` cpp
|
| 2102 |
int compare(size_type pos1, size_type n1,
|
| 2103 |
const basic_string& str,
|
| 2104 |
-
size_type pos2, size_type n2 ) const;
|
| 2105 |
```
|
| 2106 |
|
| 2107 |
*Returns:*
|
| 2108 |
`basic_string(*this, pos1, n1).compare(basic_string(str, pos2, n2))`.
|
| 2109 |
|
|
@@ -2259,19 +2264,19 @@ template<class charT, class traits, class Allocator>
|
|
| 2259 |
*Returns:* `lhs.compare(rhs) == 0`.
|
| 2260 |
|
| 2261 |
``` cpp
|
| 2262 |
template<class charT, class traits, class Allocator>
|
| 2263 |
bool operator==(const charT* lhs,
|
| 2264 |
-
const basic_string<charT,traits,Allocator>& rhs)
|
| 2265 |
```
|
| 2266 |
|
| 2267 |
*Returns:* `rhs == lhs`.
|
| 2268 |
|
| 2269 |
``` cpp
|
| 2270 |
template<class charT, class traits, class Allocator>
|
| 2271 |
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
| 2272 |
-
const charT* rhs)
|
| 2273 |
```
|
| 2274 |
|
| 2275 |
*Requires:* `rhs` points to an array of at least
|
| 2276 |
`traits::length(rhs) + 1` elements of `charT`.
|
| 2277 |
|
|
@@ -2288,19 +2293,19 @@ template<class charT, class traits, class Allocator>
|
|
| 2288 |
*Returns:* `!(lhs == rhs)`.
|
| 2289 |
|
| 2290 |
``` cpp
|
| 2291 |
template<class charT, class traits, class Allocator>
|
| 2292 |
bool operator!=(const charT* lhs,
|
| 2293 |
-
const basic_string<charT,traits,Allocator>& rhs)
|
| 2294 |
```
|
| 2295 |
|
| 2296 |
*Returns:* `rhs != lhs`.
|
| 2297 |
|
| 2298 |
``` cpp
|
| 2299 |
template<class charT, class traits, class Allocator>
|
| 2300 |
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
| 2301 |
-
const charT* rhs)
|
| 2302 |
```
|
| 2303 |
|
| 2304 |
*Requires:* `rhs` points to an array of at least
|
| 2305 |
`traits::length(rhs) + 1` elements of `charT`.
|
| 2306 |
|
|
@@ -2317,19 +2322,19 @@ template<class charT, class traits, class Allocator>
|
|
| 2317 |
*Returns:* `lhs.compare(rhs) < 0`.
|
| 2318 |
|
| 2319 |
``` cpp
|
| 2320 |
template<class charT, class traits, class Allocator>
|
| 2321 |
bool operator< (const charT* lhs,
|
| 2322 |
-
const basic_string<charT,traits,Allocator>& rhs)
|
| 2323 |
```
|
| 2324 |
|
| 2325 |
*Returns:* `rhs.compare(lhs) > 0`.
|
| 2326 |
|
| 2327 |
``` cpp
|
| 2328 |
template<class charT, class traits, class Allocator>
|
| 2329 |
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
|
| 2330 |
-
const charT* rhs)
|
| 2331 |
```
|
| 2332 |
|
| 2333 |
*Returns:* `lhs.compare(rhs) < 0`.
|
| 2334 |
|
| 2335 |
#### `operator>` <a id="string::op>">[[string::op>]]</a>
|
|
@@ -2343,19 +2348,19 @@ template<class charT, class traits, class Allocator>
|
|
| 2343 |
*Returns:* `lhs.compare(rhs) > 0`.
|
| 2344 |
|
| 2345 |
``` cpp
|
| 2346 |
template<class charT, class traits, class Allocator>
|
| 2347 |
bool operator> (const charT* lhs,
|
| 2348 |
-
const basic_string<charT,traits,Allocator>& rhs)
|
| 2349 |
```
|
| 2350 |
|
| 2351 |
*Returns:* `rhs.compare(lhs) < 0`.
|
| 2352 |
|
| 2353 |
``` cpp
|
| 2354 |
template<class charT, class traits, class Allocator>
|
| 2355 |
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
|
| 2356 |
-
const charT* rhs)
|
| 2357 |
```
|
| 2358 |
|
| 2359 |
*Returns:* `lhs.compare(rhs) > 0`.
|
| 2360 |
|
| 2361 |
#### `operator<=` <a id="string::op<=">[[string::op<=]]</a>
|
|
@@ -2369,19 +2374,19 @@ template<class charT, class traits, class Allocator>
|
|
| 2369 |
*Returns:* `lhs.compare(rhs) <= 0`.
|
| 2370 |
|
| 2371 |
``` cpp
|
| 2372 |
template<class charT, class traits, class Allocator>
|
| 2373 |
bool operator<=(const charT* lhs,
|
| 2374 |
-
const basic_string<charT,traits,Allocator>& rhs)
|
| 2375 |
```
|
| 2376 |
|
| 2377 |
*Returns:* `rhs.compare(lhs) >= 0`.
|
| 2378 |
|
| 2379 |
``` cpp
|
| 2380 |
template<class charT, class traits, class Allocator>
|
| 2381 |
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
|
| 2382 |
-
const charT* rhs)
|
| 2383 |
```
|
| 2384 |
|
| 2385 |
*Returns:* `lhs.compare(rhs) <= 0`.
|
| 2386 |
|
| 2387 |
#### `operator>=` <a id="string::op>=">[[string::op>=]]</a>
|
|
@@ -2395,32 +2400,32 @@ template<class charT, class traits, class Allocator>
|
|
| 2395 |
*Returns:* `lhs.compare(rhs) >= 0`.
|
| 2396 |
|
| 2397 |
``` cpp
|
| 2398 |
template<class charT, class traits, class Allocator>
|
| 2399 |
bool operator>=(const charT* lhs,
|
| 2400 |
-
const basic_string<charT,traits,Allocator>& rhs)
|
| 2401 |
```
|
| 2402 |
|
| 2403 |
*Returns:* `rhs.compare(lhs) <= 0`.
|
| 2404 |
|
| 2405 |
``` cpp
|
| 2406 |
template<class charT, class traits, class Allocator>
|
| 2407 |
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
|
| 2408 |
-
const charT* rhs)
|
| 2409 |
```
|
| 2410 |
|
| 2411 |
*Returns:* `lhs.compare(rhs) >= 0`.
|
| 2412 |
|
| 2413 |
#### `swap` <a id="string.special">[[string.special]]</a>
|
| 2414 |
|
| 2415 |
``` cpp
|
| 2416 |
template<class charT, class traits, class Allocator>
|
| 2417 |
void swap(basic_string<charT,traits,Allocator>& lhs,
|
| 2418 |
-
basic_string<charT,traits,Allocator>& rhs)
|
| 2419 |
```
|
| 2420 |
|
| 2421 |
-
*Effects:* `lhs.swap(rhs);`
|
| 2422 |
|
| 2423 |
#### Inserters and extractors <a id="string.io">[[string.io]]</a>
|
| 2424 |
|
| 2425 |
``` cpp
|
| 2426 |
template<class charT, class traits, class Allocator>
|
|
@@ -2458,16 +2463,16 @@ template<class charT, class traits, class Allocator>
|
|
| 2458 |
operator<<(basic_ostream<charT, traits>& os,
|
| 2459 |
const basic_string<charT,traits,Allocator>& str);
|
| 2460 |
```
|
| 2461 |
|
| 2462 |
*Effects:* Behaves as a formatted output
|
| 2463 |
-
function ([[ostream.formatted.reqmts]])
|
| 2464 |
-
|
| 2465 |
-
`
|
| 2466 |
-
|
| 2467 |
-
`os.rdbuf()->sputn(seq, n)`, where `n` is the larger of
|
| 2468 |
-
`str.size()`; then calls `os.width(0)`.
|
| 2469 |
|
| 2470 |
*Returns:* `os`
|
| 2471 |
|
| 2472 |
``` cpp
|
| 2473 |
template<class charT, class traits, class Allocator>
|
|
@@ -2541,11 +2546,12 @@ unconverted element of `str`.
|
|
| 2541 |
|
| 2542 |
*Returns:* The converted result.
|
| 2543 |
|
| 2544 |
*Throws:* `invalid_argument` if `strtol`, `strtoul`, `strtoll`, or
|
| 2545 |
`strtoull` reports that no conversion could be performed. Throws
|
| 2546 |
-
`out_of_range` if
|
|
|
|
| 2547 |
representable values for the return type.
|
| 2548 |
|
| 2549 |
``` cpp
|
| 2550 |
float stof(const string& str, size_t* idx = 0);
|
| 2551 |
double stod(const string& str, size_t* idx = 0);
|
|
@@ -2562,11 +2568,12 @@ unconverted element of `str`.
|
|
| 2562 |
|
| 2563 |
*Returns:* The converted result.
|
| 2564 |
|
| 2565 |
*Throws:* `invalid_argument` if `strtod` or `strtold` reports that no
|
| 2566 |
conversion could be performed. Throws `out_of_range` if `strtod` or
|
| 2567 |
-
`strtold` sets `errno` to `ERANGE`
|
|
|
|
| 2568 |
|
| 2569 |
``` cpp
|
| 2570 |
string to_string(int val);
|
| 2571 |
string to_string(unsigned val);
|
| 2572 |
string to_string(long val);
|
|
@@ -2656,12 +2663,42 @@ template <> struct hash<string>;
|
|
| 2656 |
template <> struct hash<u16string>;
|
| 2657 |
template <> struct hash<u32string>;
|
| 2658 |
template <> struct hash<wstring>;
|
| 2659 |
```
|
| 2660 |
|
| 2661 |
-
|
| 2662 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2663 |
|
| 2664 |
## Null-terminated sequence utilities <a id="c.strings">[[c.strings]]</a>
|
| 2665 |
|
| 2666 |
Tables [[tab:strings.hdr.cctype]], [[tab:strings.hdr.cwctype]],
|
| 2667 |
[[tab:strings.hdr.cstring]], [[tab:strings.hdr.cwchar]],
|
|
@@ -2796,10 +2833,11 @@ an `mbstate_t*` argument of `NULL` may introduce a data race (
|
|
| 2796 |
ISO C 7.3, 7.10.7, 7.10.8, and 7.11. Amendment 1 4.4, 4.5, and 4.6.
|
| 2797 |
|
| 2798 |
<!-- Link reference definitions -->
|
| 2799 |
[basic.string]: #basic.string
|
| 2800 |
[basic.string.hash]: #basic.string.hash
|
|
|
|
| 2801 |
[basic.types]: basic.md#basic.types
|
| 2802 |
[c.strings]: #c.strings
|
| 2803 |
[char.traits]: #char.traits
|
| 2804 |
[char.traits.require]: #char.traits.require
|
| 2805 |
[char.traits.specializations]: #char.traits.specializations
|
|
@@ -2810,11 +2848,10 @@ ISO C 7.3, 7.10.7, 7.10.8, and 7.11. Amendment 1 4.4, 4.5, and 4.6.
|
|
| 2810 |
[char.traits.typedefs]: #char.traits.typedefs
|
| 2811 |
[container.requirements.general]: containers.md#container.requirements.general
|
| 2812 |
[copyassignable]: #copyassignable
|
| 2813 |
[copyconstructible]: #copyconstructible
|
| 2814 |
[defaultconstructible]: #defaultconstructible
|
| 2815 |
-
[facet.num.put.virtuals]: localization.md#facet.num.put.virtuals
|
| 2816 |
[input.output]: input.md#input.output
|
| 2817 |
[iostate.flags]: input.md#iostate.flags
|
| 2818 |
[iostream.forward]: input.md#iostream.forward
|
| 2819 |
[iostreams.limits.pos]: input.md#iostreams.limits.pos
|
| 2820 |
[istream.formatted.reqmts]: input.md#istream.formatted.reqmts
|
|
|
|
| 36 |
Most classes specified in Clauses [[string.classes]] and
|
| 37 |
[[input.output]] need a set of related types and functions to complete
|
| 38 |
the definition of their semantics. These types and functions are
|
| 39 |
provided as a set of member typedefs and functions in the template
|
| 40 |
parameter ‘traits’ used by each such template. This subclause defines
|
| 41 |
+
the semantics of these members.
|
| 42 |
|
| 43 |
To specialize those templates to generate a string or iostream class to
|
| 44 |
handle a particular character container type `CharT`, that and its
|
| 45 |
related character traits class `Traits` are passed as a pair of
|
| 46 |
+
parameters to the string or iostream template as parameters `charT` and
|
| 47 |
+
`traits`. `Traits::char_type` shall be the same as `CharT`.
|
| 48 |
|
| 49 |
This subclause specifies a struct template, `char_traits<charT>`, and
|
| 50 |
four explicit specializations of it, `char_traits<{}char>`,
|
| 51 |
`char_traits<char16_t>`, `char_traits<char32_t>`, and
|
| 52 |
`char_traits<wchar_t>`, all of which appear in the header `<string>` and
|
|
|
|
| 386 |
basic_string<charT,traits,Allocator>
|
| 387 |
operator+(basic_string<charT,traits,Allocator>&& lhs, charT rhs);
|
| 388 |
|
| 389 |
template<class charT, class traits, class Allocator>
|
| 390 |
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
| 391 |
+
const basic_string<charT,traits,Allocator>& rhs) noexcept;
|
| 392 |
template<class charT, class traits, class Allocator>
|
| 393 |
bool operator==(const charT* lhs,
|
| 394 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 395 |
template<class charT, class traits, class Allocator>
|
| 396 |
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
| 397 |
const charT* rhs);
|
| 398 |
template<class charT, class traits, class Allocator>
|
| 399 |
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
| 400 |
+
const basic_string<charT,traits,Allocator>& rhs) noexcept;
|
| 401 |
template<class charT, class traits, class Allocator>
|
| 402 |
bool operator!=(const charT* lhs,
|
| 403 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 404 |
template<class charT, class traits, class Allocator>
|
| 405 |
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
| 406 |
const charT* rhs);
|
| 407 |
|
| 408 |
template<class charT, class traits, class Allocator>
|
| 409 |
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
|
| 410 |
+
const basic_string<charT,traits,Allocator>& rhs) noexcept;
|
| 411 |
template<class charT, class traits, class Allocator>
|
| 412 |
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
|
| 413 |
const charT* rhs);
|
| 414 |
template<class charT, class traits, class Allocator>
|
| 415 |
bool operator< (const charT* lhs,
|
| 416 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 417 |
template<class charT, class traits, class Allocator>
|
| 418 |
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
|
| 419 |
+
const basic_string<charT,traits,Allocator>& rhs) noexcept;
|
| 420 |
template<class charT, class traits, class Allocator>
|
| 421 |
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
|
| 422 |
const charT* rhs);
|
| 423 |
template<class charT, class traits, class Allocator>
|
| 424 |
bool operator> (const charT* lhs,
|
| 425 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 426 |
|
| 427 |
template<class charT, class traits, class Allocator>
|
| 428 |
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
|
| 429 |
+
const basic_string<charT,traits,Allocator>& rhs) noexcept;
|
| 430 |
template<class charT, class traits, class Allocator>
|
| 431 |
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
|
| 432 |
const charT* rhs);
|
| 433 |
template<class charT, class traits, class Allocator>
|
| 434 |
bool operator<=(const charT* lhs,
|
| 435 |
const basic_string<charT,traits,Allocator>& rhs);
|
| 436 |
template<class charT, class traits, class Allocator>
|
| 437 |
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
|
| 438 |
+
const basic_string<charT,traits,Allocator>& rhs) noexcept;
|
| 439 |
template<class charT, class traits, class Allocator>
|
| 440 |
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
|
| 441 |
const charT* rhs);
|
| 442 |
template<class charT, class traits, class Allocator>
|
| 443 |
bool operator>=(const charT* lhs,
|
|
|
|
| 523 |
template <class T> struct hash;
|
| 524 |
template <> struct hash<string>;
|
| 525 |
template <> struct hash<u16string>;
|
| 526 |
template <> struct hash<u32string>;
|
| 527 |
template <> struct hash<wstring>;
|
| 528 |
+
|
| 529 |
+
inline namespace literals {
|
| 530 |
+
inline namespace string_literals {
|
| 531 |
+
|
| 532 |
+
// [basic.string.literals], suffix for basic_string literals:
|
| 533 |
+
string operator "" s(const char* str, size_t len);
|
| 534 |
+
u16string operator "" s(const char16_t* str, size_t len);
|
| 535 |
+
u32string operator "" s(const char32_t* str, size_t len);
|
| 536 |
+
wstring operator "" s(const wchar_t* str, size_t len);
|
| 537 |
+
|
| 538 |
+
}
|
| 539 |
+
}
|
| 540 |
}
|
| 541 |
```
|
| 542 |
|
| 543 |
## Class template `basic_string` <a id="basic.string">[[basic.string]]</a>
|
| 544 |
|
|
|
|
| 590 |
typedef std::reverse_iterator<iterator> reverse_iterator;
|
| 591 |
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
| 592 |
static const size_type npos = -1;
|
| 593 |
|
| 594 |
// [string.cons], construct/copy/destroy:
|
| 595 |
+
basic_string() : basic_string(Allocator()) { }
|
| 596 |
+
explicit basic_string(const Allocator& a);
|
| 597 |
basic_string(const basic_string& str);
|
| 598 |
basic_string(basic_string&& str) noexcept;
|
| 599 |
basic_string(const basic_string& str, size_type pos, size_type n = npos,
|
| 600 |
const Allocator& a = Allocator());
|
| 601 |
basic_string(const charT* s,
|
|
|
|
| 660 |
basic_string& operator+=(const charT* s);
|
| 661 |
basic_string& operator+=(charT c);
|
| 662 |
basic_string& operator+=(initializer_list<charT>);
|
| 663 |
basic_string& append(const basic_string& str);
|
| 664 |
basic_string& append(const basic_string& str, size_type pos,
|
| 665 |
+
size_type n = npos);
|
| 666 |
basic_string& append(const charT* s, size_type n);
|
| 667 |
basic_string& append(const charT* s);
|
| 668 |
basic_string& append(size_type n, charT c);
|
| 669 |
template<class InputIterator>
|
| 670 |
basic_string& append(InputIterator first, InputIterator last);
|
|
|
|
| 672 |
void push_back(charT c);
|
| 673 |
|
| 674 |
basic_string& assign(const basic_string& str);
|
| 675 |
basic_string& assign(basic_string&& str) noexcept;
|
| 676 |
basic_string& assign(const basic_string& str, size_type pos,
|
| 677 |
+
size_type n = npos);
|
| 678 |
basic_string& assign(const charT* s, size_type n);
|
| 679 |
basic_string& assign(const charT* s);
|
| 680 |
basic_string& assign(size_type n, charT c);
|
| 681 |
template<class InputIterator>
|
| 682 |
basic_string& assign(InputIterator first, InputIterator last);
|
| 683 |
basic_string& assign(initializer_list<charT>);
|
| 684 |
|
| 685 |
basic_string& insert(size_type pos1, const basic_string& str);
|
| 686 |
basic_string& insert(size_type pos1, const basic_string& str,
|
| 687 |
+
size_type pos2, size_type n = npos);
|
| 688 |
basic_string& insert(size_type pos, const charT* s, size_type n);
|
| 689 |
basic_string& insert(size_type pos, const charT* s);
|
| 690 |
basic_string& insert(size_type pos, size_type n, charT c);
|
| 691 |
iterator insert(const_iterator p, charT c);
|
| 692 |
iterator insert(const_iterator p, size_type n, charT c);
|
|
|
|
| 702 |
|
| 703 |
basic_string& replace(size_type pos1, size_type n1,
|
| 704 |
const basic_string& str);
|
| 705 |
basic_string& replace(size_type pos1, size_type n1,
|
| 706 |
const basic_string& str,
|
| 707 |
+
size_type pos2, size_type n2 = npos);
|
| 708 |
basic_string& replace(size_type pos, size_type n1, const charT* s,
|
| 709 |
size_type n2);
|
| 710 |
basic_string& replace(size_type pos, size_type n1, const charT* s);
|
| 711 |
basic_string& replace(size_type pos, size_type n1, size_type n2,
|
| 712 |
charT c);
|
|
|
|
| 732 |
allocator_type get_allocator() const noexcept;
|
| 733 |
|
| 734 |
size_type find (const basic_string& str, size_type pos = 0) const noexcept;
|
| 735 |
size_type find (const charT* s, size_type pos, size_type n) const;
|
| 736 |
size_type find (const charT* s, size_type pos = 0) const;
|
| 737 |
+
size_type find (charT c, size_type pos = 0) const;
|
| 738 |
size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
|
| 739 |
size_type rfind(const charT* s, size_type pos, size_type n) const;
|
| 740 |
size_type rfind(const charT* s, size_type pos = npos) const;
|
| 741 |
+
size_type rfind(charT c, size_type pos = npos) const;
|
| 742 |
|
| 743 |
size_type find_first_of(const basic_string& str,
|
| 744 |
size_type pos = 0) const noexcept;
|
| 745 |
size_type find_first_of(const charT* s,
|
| 746 |
size_type pos, size_type n) const;
|
| 747 |
size_type find_first_of(const charT* s, size_type pos = 0) const;
|
| 748 |
+
size_type find_first_of(charT c, size_type pos = 0) const;
|
| 749 |
size_type find_last_of (const basic_string& str,
|
| 750 |
size_type pos = npos) const noexcept;
|
| 751 |
size_type find_last_of (const charT* s,
|
| 752 |
size_type pos, size_type n) const;
|
| 753 |
size_type find_last_of (const charT* s, size_type pos = npos) const;
|
| 754 |
+
size_type find_last_of (charT c, size_type pos = npos) const;
|
| 755 |
|
| 756 |
size_type find_first_not_of(const basic_string& str,
|
| 757 |
size_type pos = 0) const noexcept;
|
| 758 |
size_type find_first_not_of(const charT* s, size_type pos,
|
| 759 |
size_type n) const;
|
| 760 |
size_type find_first_not_of(const charT* s, size_type pos = 0) const;
|
| 761 |
+
size_type find_first_not_of(charT c, size_type pos = 0) const;
|
| 762 |
size_type find_last_not_of (const basic_string& str,
|
| 763 |
size_type pos = npos) const noexcept;
|
| 764 |
size_type find_last_not_of (const charT* s, size_type pos,
|
| 765 |
size_type n) const;
|
| 766 |
size_type find_last_not_of (const charT* s,
|
| 767 |
size_type pos = npos) const;
|
| 768 |
+
size_type find_last_not_of (charT c, size_type pos = npos) const;
|
| 769 |
|
| 770 |
basic_string substr(size_type pos = 0, size_type n = npos) const;
|
| 771 |
int compare(const basic_string& str) const noexcept;
|
| 772 |
int compare(size_type pos1, size_type n1,
|
| 773 |
const basic_string& str) const;
|
| 774 |
int compare(size_type pos1, size_type n1,
|
| 775 |
const basic_string& str,
|
| 776 |
+
size_type pos2, size_type n2 = npos) const;
|
| 777 |
int compare(const charT* s) const;
|
| 778 |
int compare(size_type pos1, size_type n1,
|
| 779 |
const charT* s) const;
|
| 780 |
int compare(size_type pos1, size_type n1,
|
| 781 |
const charT* s, size_type n2) const;
|
|
|
|
| 789 |
operation shall throw an exception object of type `length_error`.
|
| 790 |
|
| 791 |
If any member function or operator of `basic_string` throws an
|
| 792 |
exception, that function or operator shall have no other effect.
|
| 793 |
|
|
|
|
|
|
|
| 794 |
In every specialization `basic_string<charT, traits, Allocator>`, the
|
| 795 |
type `allocator_traits<Allocator>::value_type` shall name the same type
|
| 796 |
as `charT`. Every object of type
|
| 797 |
`basic_string<charT, traits, Allocator>` shall use an object of type
|
| 798 |
`Allocator` to allocate and free storage for the contained `charT`
|
|
|
|
| 814 |
`front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
|
| 815 |
|
| 816 |
### `basic_string` constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
|
| 817 |
|
| 818 |
``` cpp
|
| 819 |
+
explicit basic_string(const Allocator& a);
|
| 820 |
```
|
| 821 |
|
| 822 |
*Effects:* Constructs an object of class `basic_string`. The
|
| 823 |
postconditions of this function are indicated in
|
| 824 |
Table [[tab:strings.ctr.1]].
|
|
|
|
| 830 |
| `data()` | a non-null pointer that is copyable and can have 0 added to it |
|
| 831 |
| `size()` | 0 |
|
| 832 |
| `capacity()` | an unspecified value |
|
| 833 |
|
| 834 |
``` cpp
|
| 835 |
+
basic_string(const basic_string& str);
|
| 836 |
+
basic_string(basic_string&& str) noexcept;
|
| 837 |
```
|
| 838 |
|
| 839 |
*Effects:* Constructs an object of class `basic_string` as indicated in
|
| 840 |
Table [[tab:strings.ctr.cpy]]. In the second form, `str` is left in a
|
| 841 |
valid state with an unspecified value.
|
| 842 |
|
|
|
|
|
|
|
|
|
|
| 843 |
**Table: `basic_string(const basic_string&)` effects** <a id="tab:strings.ctr.cpy">[tab:strings.ctr.cpy]</a>
|
| 844 |
|
| 845 |
| Element | Value |
|
| 846 |
| ------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 847 |
| `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
|
| 848 |
| `size()` | `str.size()` |
|
| 849 |
| `capacity()` | a value at least as large as `size()` |
|
| 850 |
|
| 851 |
``` cpp
|
| 852 |
+
basic_string(const basic_string& str,
|
| 853 |
size_type pos, size_type n = npos,
|
| 854 |
const Allocator& a = Allocator());
|
| 855 |
```
|
| 856 |
|
| 857 |
*Requires:* `pos <= str.size()`
|
|
|
|
| 874 |
``` cpp
|
| 875 |
basic_string(const charT* s, size_type n,
|
| 876 |
const Allocator& a = Allocator());
|
| 877 |
```
|
| 878 |
|
| 879 |
+
*Requires:* `s` points to an array of at least `n` elements of `charT`.
|
| 880 |
|
| 881 |
*Effects:* Constructs an object of class `basic_string` and determines
|
| 882 |
its initial string value from the array of `charT` of length `n` whose
|
| 883 |
first element is designated by `s`, as indicated in
|
| 884 |
Table [[tab:strings.ctr.3]].
|
|
|
|
| 893 |
|
| 894 |
``` cpp
|
| 895 |
basic_string(const charT* s, const Allocator& a = Allocator());
|
| 896 |
```
|
| 897 |
|
| 898 |
+
*Requires:* `s` points to an array of at least `traits::length(s) + 1`
|
| 899 |
+
elements of `charT`.
|
| 900 |
|
| 901 |
*Effects:* Constructs an object of class `basic_string` and determines
|
| 902 |
its initial string value from the array of `charT` of length
|
| 903 |
`traits::length(s)` whose first element is designated by `s`, as
|
| 904 |
indicated in Table [[tab:strings.ctr.4]].
|
|
|
|
| 974 |
| `capacity()` | a value at least as large as `size()` |
|
| 975 |
| `get_allocator()` | `alloc` |
|
| 976 |
|
| 977 |
|
| 978 |
*Throws:* The second form throws nothing if
|
| 979 |
+
`alloc == str.get_allocator()`.
|
|
|
|
| 980 |
|
| 981 |
``` cpp
|
| 982 |
+
basic_string& operator=(const basic_string& str);
|
|
|
|
| 983 |
```
|
| 984 |
|
| 985 |
*Effects:* If `*this` and `str` are not the same object, modifies
|
| 986 |
`*this` as shown in Table [[tab:strings.op=]].
|
| 987 |
|
| 988 |
If `*this` and `str` are the same object, the member has no effect.
|
| 989 |
|
| 990 |
*Returns:* `*this`
|
| 991 |
|
| 992 |
+
**Table: `operator=(const basic_string&)` effects** <a id="tab:strings.op=">[tab:strings.op=]</a>
|
| 993 |
|
| 994 |
| Element | Value |
|
| 995 |
| ------------ | --------------------------------------------------------------------------------------------------------------- |
|
| 996 |
| `data()` | points at the first element of an allocated copy of the array whose first element is pointed at by `str.data()` |
|
| 997 |
| `size()` | `str.size()` |
|
| 998 |
| `capacity()` | a value at least as large as `size()` |
|
| 999 |
|
| 1000 |
``` cpp
|
| 1001 |
+
basic_string& operator=(basic_string&& str) noexcept;
|
|
|
|
| 1002 |
```
|
| 1003 |
|
| 1004 |
*Effects:* If `*this` and `str` are not the same object, modifies
|
| 1005 |
`*this` as shown in Table [[tab:strings.op=rv]]. A valid implementation
|
| 1006 |
is `swap(str)`.
|
| 1007 |
|
| 1008 |
If `*this` and `str` are the same object, the member has no effect.
|
| 1009 |
|
| 1010 |
*Returns:* `*this`
|
| 1011 |
|
| 1012 |
+
**Table: `operator=(basic_string&&)` effects** <a id="tab:strings.op=rv">[tab:strings.op=rv]</a>
|
| 1013 |
|
| 1014 |
| Element | Value |
|
| 1015 |
| ------------ | ---------------------------------------------------------------------- |
|
| 1016 |
| `data()` | points at the array whose first element was pointed at by `str.data()` |
|
| 1017 |
| `size()` | previous value of `str.size()` |
|
| 1018 |
| `capacity()` | a value at least as large as `size()` |
|
| 1019 |
|
| 1020 |
``` cpp
|
| 1021 |
+
basic_string& operator=(const charT* s);
|
|
|
|
| 1022 |
```
|
| 1023 |
|
| 1024 |
+
*Returns:* `*this = basic_string(s)`.
|
| 1025 |
|
| 1026 |
*Remarks:* Uses `traits::length()`.
|
| 1027 |
|
| 1028 |
``` cpp
|
| 1029 |
+
basic_string& operator=(charT c);
|
| 1030 |
```
|
| 1031 |
|
| 1032 |
+
*Returns:* `*this = basic_string(1,c)`.
|
| 1033 |
|
| 1034 |
``` cpp
|
| 1035 |
basic_string& operator=(initializer_list<charT> il);
|
| 1036 |
```
|
| 1037 |
|
|
|
|
| 1082 |
```
|
| 1083 |
|
| 1084 |
*Returns:* A count of the number of char-like objects currently in the
|
| 1085 |
string.
|
| 1086 |
|
| 1087 |
+
*Complexity:* Constant time.
|
| 1088 |
|
| 1089 |
``` cpp
|
| 1090 |
size_type length() const noexcept;
|
| 1091 |
```
|
| 1092 |
|
|
|
|
| 1096 |
size_type max_size() const noexcept;
|
| 1097 |
```
|
| 1098 |
|
| 1099 |
*Returns:* The size of the largest possible string.
|
| 1100 |
|
| 1101 |
+
*Complexity:* Constant time.
|
| 1102 |
|
| 1103 |
``` cpp
|
| 1104 |
void resize(size_type n, charT c);
|
| 1105 |
```
|
| 1106 |
|
|
|
|
| 1184 |
reference to an object of type `charT` with value `charT()`, where
|
| 1185 |
modifying the object leads to undefined behavior.
|
| 1186 |
|
| 1187 |
*Throws:* Nothing.
|
| 1188 |
|
| 1189 |
+
*Complexity:* Constant time.
|
| 1190 |
|
| 1191 |
``` cpp
|
| 1192 |
const_reference at(size_type pos) const;
|
| 1193 |
reference at(size_type pos);
|
| 1194 |
```
|
| 1195 |
|
|
|
|
|
|
|
| 1196 |
*Throws:* `out_of_range` if `pos >= size()`.
|
| 1197 |
|
| 1198 |
*Returns:* `operator[](pos)`.
|
| 1199 |
|
| 1200 |
``` cpp
|
|
|
|
| 1263 |
|
| 1264 |
*Returns:* `*this`.
|
| 1265 |
|
| 1266 |
``` cpp
|
| 1267 |
basic_string&
|
| 1268 |
+
append(const basic_string& str, size_type pos, size_type n = npos);
|
| 1269 |
```
|
| 1270 |
|
| 1271 |
*Requires:* `pos <= str.size()`
|
| 1272 |
|
| 1273 |
*Throws:* `out_of_range` if `pos > str.size()`.
|
|
|
|
| 1331 |
*Effects:* Calls `append(il.begin(), il.size())`.
|
| 1332 |
|
| 1333 |
*Returns:* `*this`.
|
| 1334 |
|
| 1335 |
``` cpp
|
| 1336 |
+
void push_back(charT c);
|
| 1337 |
```
|
| 1338 |
|
| 1339 |
*Effects:* Equivalent to `append(static_cast<size_type>(1), c)`.
|
| 1340 |
|
| 1341 |
#### `basic_string::assign` <a id="string::assign">[[string::assign]]</a>
|
|
|
|
| 1359 |
*Returns:* `*this`.
|
| 1360 |
|
| 1361 |
``` cpp
|
| 1362 |
basic_string&
|
| 1363 |
assign(const basic_string& str, size_type pos,
|
| 1364 |
+
size_type n = npos);
|
| 1365 |
```
|
| 1366 |
|
| 1367 |
*Requires:* `pos <= str.size()`
|
| 1368 |
|
| 1369 |
*Throws:* `out_of_range` if `pos > str.size()`.
|
|
|
|
| 1441 |
|
| 1442 |
``` cpp
|
| 1443 |
basic_string&
|
| 1444 |
insert(size_type pos1,
|
| 1445 |
const basic_string& str,
|
| 1446 |
+
size_type pos2, size_type n = npos);
|
| 1447 |
```
|
| 1448 |
|
| 1449 |
*Requires:* `pos1 <= size()` and `pos2 <= str.size()`
|
| 1450 |
|
| 1451 |
*Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
|
|
|
|
| 1545 |
character, or `p` if `i1` is empty.
|
| 1546 |
|
| 1547 |
#### `basic_string::erase` <a id="string::erase">[[string::erase]]</a>
|
| 1548 |
|
| 1549 |
``` cpp
|
| 1550 |
+
basic_string& erase(size_type pos = 0, size_type n = npos);
|
|
|
|
| 1551 |
```
|
| 1552 |
|
| 1553 |
*Requires:* `pos` ` <= size()`
|
| 1554 |
|
| 1555 |
*Throws:* `out_of_range` if `pos` `> size()`.
|
|
|
|
| 1567 |
|
| 1568 |
``` cpp
|
| 1569 |
iterator erase(const_iterator p);
|
| 1570 |
```
|
| 1571 |
|
| 1572 |
+
*Throws:* Nothing.
|
| 1573 |
+
|
| 1574 |
*Effects:* removes the character referred to by `p`.
|
| 1575 |
|
| 1576 |
*Returns:* An iterator which points to the element immediately following
|
| 1577 |
`p` prior to the element being erased. If no such element exists,
|
| 1578 |
`end()` is returned.
|
|
|
|
| 1582 |
```
|
| 1583 |
|
| 1584 |
*Requires:* `first` and `last` are valid iterators on `*this`, defining
|
| 1585 |
a range `[first,last)`.
|
| 1586 |
|
| 1587 |
+
*Throws:* Nothing.
|
| 1588 |
+
|
| 1589 |
*Effects:* removes the characters in the range `[first,last)`.
|
| 1590 |
|
| 1591 |
*Returns:* An iterator which points to the element pointed to by `last`
|
| 1592 |
prior to the other elements being erased. If no such element exists,
|
| 1593 |
`end()` is returned.
|
|
|
|
| 1596 |
void pop_back();
|
| 1597 |
```
|
| 1598 |
|
| 1599 |
*Requires:* `!empty()`
|
| 1600 |
|
| 1601 |
+
*Throws:* Nothing.
|
| 1602 |
+
|
| 1603 |
*Effects:* Equivalent to `erase(size() - 1, 1)`.
|
| 1604 |
|
| 1605 |
#### `basic_string::replace` <a id="string::replace">[[string::replace]]</a>
|
| 1606 |
|
| 1607 |
``` cpp
|
|
|
|
| 1620 |
|
| 1621 |
``` cpp
|
| 1622 |
basic_string&
|
| 1623 |
replace(size_type pos1, size_type n1,
|
| 1624 |
const basic_string& str,
|
| 1625 |
+
size_type pos2, size_type n2 = npos);
|
| 1626 |
```
|
| 1627 |
|
| 1628 |
*Requires:* `pos1 <= size()` and `pos2 <= str.size()`.
|
| 1629 |
|
| 1630 |
*Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
|
|
|
|
| 1746 |
*Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
|
| 1747 |
|
| 1748 |
*Effects:* Calls
|
| 1749 |
`replace(i1 - begin(), i2 - i1, il.begin(), il.size())`.
|
| 1750 |
|
| 1751 |
+
*Returns:* `*this`.
|
| 1752 |
|
| 1753 |
#### `basic_string::copy` <a id="string::copy">[[string::copy]]</a>
|
| 1754 |
|
| 1755 |
``` cpp
|
| 1756 |
size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
|
|
|
| 1774 |
*Returns:* `rlen`.
|
| 1775 |
|
| 1776 |
#### `basic_string::swap` <a id="string::swap">[[string::swap]]</a>
|
| 1777 |
|
| 1778 |
``` cpp
|
| 1779 |
+
void swap(basic_string& s);
|
| 1780 |
```
|
| 1781 |
|
| 1782 |
`*this` contains the same sequence of characters that was in `s`, `s`
|
| 1783 |
contains the same sequence of characters that was in `*this`.
|
| 1784 |
|
| 1785 |
*Throws:* Nothing.
|
| 1786 |
|
| 1787 |
+
*Complexity:* Constant time.
|
| 1788 |
|
| 1789 |
### `basic_string` string operations <a id="string.ops">[[string.ops]]</a>
|
| 1790 |
|
| 1791 |
#### `basic_string` accessors <a id="string.accessors">[[string.accessors]]</a>
|
| 1792 |
|
|
|
|
| 1796 |
```
|
| 1797 |
|
| 1798 |
*Returns:* A pointer `p` such that `p + i == &operator[](i)` for each
|
| 1799 |
`i` in \[`0`, `size()`\].
|
| 1800 |
|
| 1801 |
+
*Complexity:* Constant time.
|
| 1802 |
|
| 1803 |
*Requires:* The program shall not alter any of the values stored in the
|
| 1804 |
character array.
|
| 1805 |
|
| 1806 |
``` cpp
|
|
|
|
| 1832 |
|
| 1833 |
``` cpp
|
| 1834 |
size_type find(const charT* s, size_type pos, size_type n) const;
|
| 1835 |
```
|
| 1836 |
|
| 1837 |
+
*Returns:* `find(basic_string(s,n),pos)`.
|
| 1838 |
|
| 1839 |
``` cpp
|
| 1840 |
+
size_type find(const charT* s, size_type pos = 0) const;
|
| 1841 |
```
|
| 1842 |
|
| 1843 |
*Requires:* `s` points to an array of at least `traits::length(s) + 1`
|
| 1844 |
elements of `charT`.
|
| 1845 |
|
| 1846 |
*Returns:* `find(basic_string(s), pos)`.
|
| 1847 |
|
| 1848 |
``` cpp
|
| 1849 |
+
size_type find(charT c, size_type pos = 0) const;
|
| 1850 |
```
|
| 1851 |
|
| 1852 |
+
*Returns:* `find(basic_string(1,c), pos)`.
|
| 1853 |
|
| 1854 |
#### `basic_string::rfind` <a id="string::rfind">[[string::rfind]]</a>
|
| 1855 |
|
| 1856 |
``` cpp
|
| 1857 |
size_type rfind(const basic_string& str,
|
|
|
|
| 1884 |
elements of `charT`.
|
| 1885 |
|
| 1886 |
*Returns:* `rfind(basic_string(s), pos)`.
|
| 1887 |
|
| 1888 |
``` cpp
|
| 1889 |
+
size_type rfind(charT c, size_type pos = npos) const;
|
| 1890 |
```
|
| 1891 |
|
| 1892 |
+
*Returns:* `rfind(basic_string(1,c),pos)`.
|
| 1893 |
|
| 1894 |
#### `basic_string::find_first_of` <a id="string::find.first.of">[[string::find.first.of]]</a>
|
| 1895 |
|
| 1896 |
``` cpp
|
| 1897 |
size_type
|
|
|
|
| 1926 |
elements of `charT`.
|
| 1927 |
|
| 1928 |
*Returns:* `find_first_of(basic_string(s), pos)`.
|
| 1929 |
|
| 1930 |
``` cpp
|
| 1931 |
+
size_type find_first_of(charT c, size_type pos = 0) const;
|
| 1932 |
```
|
| 1933 |
|
| 1934 |
+
*Returns:* `find_first_of(basic_string(1,c), pos)`.
|
|
|
|
| 1935 |
|
| 1936 |
#### `basic_string::find_last_of` <a id="string::find.last.of">[[string::find.last.of]]</a>
|
| 1937 |
|
| 1938 |
``` cpp
|
| 1939 |
size_type
|
|
|
|
| 1967 |
elements of `charT`.
|
| 1968 |
|
| 1969 |
*Returns:* `find_last_of(basic_string(s), pos)`.
|
| 1970 |
|
| 1971 |
``` cpp
|
| 1972 |
+
size_type find_last_of(charT c, size_type pos = npos) const;
|
| 1973 |
```
|
| 1974 |
|
| 1975 |
+
*Returns:* `find_last_of(basic_string(1,c),pos)`.
|
|
|
|
| 1976 |
|
| 1977 |
#### `basic_string::find_first_not_of` <a id="string::find.first.not.of">[[string::find.first.not.of]]</a>
|
| 1978 |
|
| 1979 |
``` cpp
|
| 1980 |
size_type
|
|
|
|
| 2009 |
elements of `charT`.
|
| 2010 |
|
| 2011 |
*Returns:* `find_first_not_of(basic_string(s), pos)`.
|
| 2012 |
|
| 2013 |
``` cpp
|
| 2014 |
+
size_type find_first_not_of(charT c, size_type pos = 0) const;
|
| 2015 |
```
|
| 2016 |
|
| 2017 |
*Returns:* `find_first_not_of(basic_string(1, c), pos)`.
|
| 2018 |
|
| 2019 |
#### `basic_string::find_last_not_of` <a id="string::find.last.not.of">[[string::find.last.not.of]]</a>
|
|
|
|
| 2051 |
elements of `charT`.
|
| 2052 |
|
| 2053 |
*Returns:* `find_last_not_of(basic_string(s), pos)`.
|
| 2054 |
|
| 2055 |
``` cpp
|
| 2056 |
+
size_type find_last_not_of(charT c, size_type pos = npos) const;
|
| 2057 |
```
|
| 2058 |
|
| 2059 |
*Returns:* `find_last_not_of(basic_string(1, c), pos)`.
|
| 2060 |
|
| 2061 |
#### `basic_string::substr` <a id="string::substr">[[string::substr]]</a>
|
| 2062 |
|
| 2063 |
``` cpp
|
| 2064 |
+
basic_string substr(size_type pos = 0, size_type n = npos) const;
|
|
|
|
| 2065 |
```
|
| 2066 |
|
| 2067 |
*Requires:* `pos <= size()`
|
| 2068 |
|
| 2069 |
*Throws:* `out_of_range` if `pos > size()`.
|
| 2070 |
|
| 2071 |
*Effects:* Determines the effective length `rlen` of the string to copy
|
| 2072 |
as the smaller of `n` and `size() - pos`.
|
| 2073 |
|
| 2074 |
+
*Returns:* `basic_string(data()+pos,rlen)`.
|
| 2075 |
|
| 2076 |
#### `basic_string::compare` <a id="string::compare">[[string::compare]]</a>
|
| 2077 |
|
| 2078 |
``` cpp
|
| 2079 |
int compare(const basic_string& str) const noexcept;
|
|
|
|
| 2104 |
*Returns:* `basic_string(*this,pos1,n1).compare(str)`.
|
| 2105 |
|
| 2106 |
``` cpp
|
| 2107 |
int compare(size_type pos1, size_type n1,
|
| 2108 |
const basic_string& str,
|
| 2109 |
+
size_type pos2, size_type n2 = npos) const;
|
| 2110 |
```
|
| 2111 |
|
| 2112 |
*Returns:*
|
| 2113 |
`basic_string(*this, pos1, n1).compare(basic_string(str, pos2, n2))`.
|
| 2114 |
|
|
|
|
| 2264 |
*Returns:* `lhs.compare(rhs) == 0`.
|
| 2265 |
|
| 2266 |
``` cpp
|
| 2267 |
template<class charT, class traits, class Allocator>
|
| 2268 |
bool operator==(const charT* lhs,
|
| 2269 |
+
const basic_string<charT,traits,Allocator>& rhs);
|
| 2270 |
```
|
| 2271 |
|
| 2272 |
*Returns:* `rhs == lhs`.
|
| 2273 |
|
| 2274 |
``` cpp
|
| 2275 |
template<class charT, class traits, class Allocator>
|
| 2276 |
bool operator==(const basic_string<charT,traits,Allocator>& lhs,
|
| 2277 |
+
const charT* rhs);
|
| 2278 |
```
|
| 2279 |
|
| 2280 |
*Requires:* `rhs` points to an array of at least
|
| 2281 |
`traits::length(rhs) + 1` elements of `charT`.
|
| 2282 |
|
|
|
|
| 2293 |
*Returns:* `!(lhs == rhs)`.
|
| 2294 |
|
| 2295 |
``` cpp
|
| 2296 |
template<class charT, class traits, class Allocator>
|
| 2297 |
bool operator!=(const charT* lhs,
|
| 2298 |
+
const basic_string<charT,traits,Allocator>& rhs);
|
| 2299 |
```
|
| 2300 |
|
| 2301 |
*Returns:* `rhs != lhs`.
|
| 2302 |
|
| 2303 |
``` cpp
|
| 2304 |
template<class charT, class traits, class Allocator>
|
| 2305 |
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
|
| 2306 |
+
const charT* rhs);
|
| 2307 |
```
|
| 2308 |
|
| 2309 |
*Requires:* `rhs` points to an array of at least
|
| 2310 |
`traits::length(rhs) + 1` elements of `charT`.
|
| 2311 |
|
|
|
|
| 2322 |
*Returns:* `lhs.compare(rhs) < 0`.
|
| 2323 |
|
| 2324 |
``` cpp
|
| 2325 |
template<class charT, class traits, class Allocator>
|
| 2326 |
bool operator< (const charT* lhs,
|
| 2327 |
+
const basic_string<charT,traits,Allocator>& rhs);
|
| 2328 |
```
|
| 2329 |
|
| 2330 |
*Returns:* `rhs.compare(lhs) > 0`.
|
| 2331 |
|
| 2332 |
``` cpp
|
| 2333 |
template<class charT, class traits, class Allocator>
|
| 2334 |
bool operator< (const basic_string<charT,traits,Allocator>& lhs,
|
| 2335 |
+
const charT* rhs);
|
| 2336 |
```
|
| 2337 |
|
| 2338 |
*Returns:* `lhs.compare(rhs) < 0`.
|
| 2339 |
|
| 2340 |
#### `operator>` <a id="string::op>">[[string::op>]]</a>
|
|
|
|
| 2348 |
*Returns:* `lhs.compare(rhs) > 0`.
|
| 2349 |
|
| 2350 |
``` cpp
|
| 2351 |
template<class charT, class traits, class Allocator>
|
| 2352 |
bool operator> (const charT* lhs,
|
| 2353 |
+
const basic_string<charT,traits,Allocator>& rhs);
|
| 2354 |
```
|
| 2355 |
|
| 2356 |
*Returns:* `rhs.compare(lhs) < 0`.
|
| 2357 |
|
| 2358 |
``` cpp
|
| 2359 |
template<class charT, class traits, class Allocator>
|
| 2360 |
bool operator> (const basic_string<charT,traits,Allocator>& lhs,
|
| 2361 |
+
const charT* rhs);
|
| 2362 |
```
|
| 2363 |
|
| 2364 |
*Returns:* `lhs.compare(rhs) > 0`.
|
| 2365 |
|
| 2366 |
#### `operator<=` <a id="string::op<=">[[string::op<=]]</a>
|
|
|
|
| 2374 |
*Returns:* `lhs.compare(rhs) <= 0`.
|
| 2375 |
|
| 2376 |
``` cpp
|
| 2377 |
template<class charT, class traits, class Allocator>
|
| 2378 |
bool operator<=(const charT* lhs,
|
| 2379 |
+
const basic_string<charT,traits,Allocator>& rhs);
|
| 2380 |
```
|
| 2381 |
|
| 2382 |
*Returns:* `rhs.compare(lhs) >= 0`.
|
| 2383 |
|
| 2384 |
``` cpp
|
| 2385 |
template<class charT, class traits, class Allocator>
|
| 2386 |
bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
|
| 2387 |
+
const charT* rhs);
|
| 2388 |
```
|
| 2389 |
|
| 2390 |
*Returns:* `lhs.compare(rhs) <= 0`.
|
| 2391 |
|
| 2392 |
#### `operator>=` <a id="string::op>=">[[string::op>=]]</a>
|
|
|
|
| 2400 |
*Returns:* `lhs.compare(rhs) >= 0`.
|
| 2401 |
|
| 2402 |
``` cpp
|
| 2403 |
template<class charT, class traits, class Allocator>
|
| 2404 |
bool operator>=(const charT* lhs,
|
| 2405 |
+
const basic_string<charT,traits,Allocator>& rhs);
|
| 2406 |
```
|
| 2407 |
|
| 2408 |
*Returns:* `rhs.compare(lhs) <= 0`.
|
| 2409 |
|
| 2410 |
``` cpp
|
| 2411 |
template<class charT, class traits, class Allocator>
|
| 2412 |
bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
|
| 2413 |
+
const charT* rhs);
|
| 2414 |
```
|
| 2415 |
|
| 2416 |
*Returns:* `lhs.compare(rhs) >= 0`.
|
| 2417 |
|
| 2418 |
#### `swap` <a id="string.special">[[string.special]]</a>
|
| 2419 |
|
| 2420 |
``` cpp
|
| 2421 |
template<class charT, class traits, class Allocator>
|
| 2422 |
void swap(basic_string<charT,traits,Allocator>& lhs,
|
| 2423 |
+
basic_string<charT,traits,Allocator>& rhs);
|
| 2424 |
```
|
| 2425 |
|
| 2426 |
+
*Effects:* Equivalent to `lhs.swap(rhs);`
|
| 2427 |
|
| 2428 |
#### Inserters and extractors <a id="string.io">[[string.io]]</a>
|
| 2429 |
|
| 2430 |
``` cpp
|
| 2431 |
template<class charT, class traits, class Allocator>
|
|
|
|
| 2463 |
operator<<(basic_ostream<charT, traits>& os,
|
| 2464 |
const basic_string<charT,traits,Allocator>& str);
|
| 2465 |
```
|
| 2466 |
|
| 2467 |
*Effects:* Behaves as a formatted output
|
| 2468 |
+
function ([[ostream.formatted.reqmts]]) of `os`. Forms a character
|
| 2469 |
+
sequence `seq`, initially consisting of the elements defined by the
|
| 2470 |
+
range \[`str.begin(), str.end()`). Determines padding for `seq` as
|
| 2471 |
+
described in [[ostream.formatted.reqmts]]. Then inserts `seq` as if by
|
| 2472 |
+
calling `os.rdbuf()->sputn(seq, n)`, where `n` is the larger of
|
| 2473 |
+
`os.width()` and `str.size()`; then calls `os.width(0)`.
|
| 2474 |
|
| 2475 |
*Returns:* `os`
|
| 2476 |
|
| 2477 |
``` cpp
|
| 2478 |
template<class charT, class traits, class Allocator>
|
|
|
|
| 2546 |
|
| 2547 |
*Returns:* The converted result.
|
| 2548 |
|
| 2549 |
*Throws:* `invalid_argument` if `strtol`, `strtoul`, `strtoll`, or
|
| 2550 |
`strtoull` reports that no conversion could be performed. Throws
|
| 2551 |
+
`out_of_range` if `strtol`, `strtoul`, `strtoll` or `strtoull` sets
|
| 2552 |
+
`errno` to `ERANGE`, or if the converted value is outside the range of
|
| 2553 |
representable values for the return type.
|
| 2554 |
|
| 2555 |
``` cpp
|
| 2556 |
float stof(const string& str, size_t* idx = 0);
|
| 2557 |
double stod(const string& str, size_t* idx = 0);
|
|
|
|
| 2568 |
|
| 2569 |
*Returns:* The converted result.
|
| 2570 |
|
| 2571 |
*Throws:* `invalid_argument` if `strtod` or `strtold` reports that no
|
| 2572 |
conversion could be performed. Throws `out_of_range` if `strtod` or
|
| 2573 |
+
`strtold` sets `errno` to `ERANGE` or if the converted value is outside
|
| 2574 |
+
the range of representable values for the return type.
|
| 2575 |
|
| 2576 |
``` cpp
|
| 2577 |
string to_string(int val);
|
| 2578 |
string to_string(unsigned val);
|
| 2579 |
string to_string(long val);
|
|
|
|
| 2663 |
template <> struct hash<u16string>;
|
| 2664 |
template <> struct hash<u32string>;
|
| 2665 |
template <> struct hash<wstring>;
|
| 2666 |
```
|
| 2667 |
|
| 2668 |
+
The template specializations shall meet the requirements of class
|
| 2669 |
+
template `hash` ([[unord.hash]]).
|
| 2670 |
+
|
| 2671 |
+
## Suffix for `basic_string` literals <a id="basic.string.literals">[[basic.string.literals]]</a>
|
| 2672 |
+
|
| 2673 |
+
``` cpp
|
| 2674 |
+
string operator "" s(const char* str, size_t len);
|
| 2675 |
+
```
|
| 2676 |
+
|
| 2677 |
+
*Returns:* `string{str,len}`
|
| 2678 |
+
|
| 2679 |
+
``` cpp
|
| 2680 |
+
u16string operator "" s(const char16_t* str, size_t len);
|
| 2681 |
+
```
|
| 2682 |
+
|
| 2683 |
+
*Returns:* `u16string{str,len}`
|
| 2684 |
+
|
| 2685 |
+
``` cpp
|
| 2686 |
+
u32string operator "" s(const char32_t* str, size_t len);
|
| 2687 |
+
```
|
| 2688 |
+
|
| 2689 |
+
*Returns:* `u32string{str,len}`
|
| 2690 |
+
|
| 2691 |
+
``` cpp
|
| 2692 |
+
wstring operator "" s(const wchar_t* str, size_t len);
|
| 2693 |
+
```
|
| 2694 |
+
|
| 2695 |
+
*Returns:* `wstring{str,len}`
|
| 2696 |
+
|
| 2697 |
+
The same suffix `s` is used for `chrono::duration` literals denoting
|
| 2698 |
+
seconds but there is no conflict, since duration suffixes apply to
|
| 2699 |
+
numbers and string literal suffixes apply to character array literals.
|
| 2700 |
|
| 2701 |
## Null-terminated sequence utilities <a id="c.strings">[[c.strings]]</a>
|
| 2702 |
|
| 2703 |
Tables [[tab:strings.hdr.cctype]], [[tab:strings.hdr.cwctype]],
|
| 2704 |
[[tab:strings.hdr.cstring]], [[tab:strings.hdr.cwchar]],
|
|
|
|
| 2833 |
ISO C 7.3, 7.10.7, 7.10.8, and 7.11. Amendment 1 4.4, 4.5, and 4.6.
|
| 2834 |
|
| 2835 |
<!-- Link reference definitions -->
|
| 2836 |
[basic.string]: #basic.string
|
| 2837 |
[basic.string.hash]: #basic.string.hash
|
| 2838 |
+
[basic.string.literals]: #basic.string.literals
|
| 2839 |
[basic.types]: basic.md#basic.types
|
| 2840 |
[c.strings]: #c.strings
|
| 2841 |
[char.traits]: #char.traits
|
| 2842 |
[char.traits.require]: #char.traits.require
|
| 2843 |
[char.traits.specializations]: #char.traits.specializations
|
|
|
|
| 2848 |
[char.traits.typedefs]: #char.traits.typedefs
|
| 2849 |
[container.requirements.general]: containers.md#container.requirements.general
|
| 2850 |
[copyassignable]: #copyassignable
|
| 2851 |
[copyconstructible]: #copyconstructible
|
| 2852 |
[defaultconstructible]: #defaultconstructible
|
|
|
|
| 2853 |
[input.output]: input.md#input.output
|
| 2854 |
[iostate.flags]: input.md#iostate.flags
|
| 2855 |
[iostream.forward]: input.md#iostream.forward
|
| 2856 |
[iostreams.limits.pos]: input.md#iostreams.limits.pos
|
| 2857 |
[istream.formatted.reqmts]: input.md#istream.formatted.reqmts
|