|
|
|
Defined in header <string> | ||
Compare two basic_string objects | ||
template<class CharT,class Traits,class Alloc> bool operator==(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (1) | (noexcept since C++11) (constexpr since C++20) |
template<class CharT,class Traits,class Alloc> bool operator!=(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (2) | (until C++20) (noexcept since C++11) |
template<class CharT,class Traits,class Alloc> bool operator<(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (3) | (until C++20) (noexcept since C++11) |
template<class CharT,class Traits,class Alloc> bool operator<=(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (4) | (until C++20) (noexcept since C++11) |
template<class CharT,class Traits,class Alloc> bool operator>(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (5) | (until C++20) (noexcept since C++11) |
template<class CharT,class Traits,class Alloc> bool operator>=(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (6) | (until C++20) (noexcept since C++11) |
template<class CharT,class Traits,class Alloc> constexpr/*comp-cat*/ | (7) | (since C++20) |
Compare a basic_string object and null-terminated array ofT | ||
template<class CharT,class Traits,class Alloc> bool operator==(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (8) | (constexpr since C++20) |
template<class CharT,class Traits,class Alloc> bool operator==(const CharT* lhs, | (9) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator!=(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (10) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator!=(const CharT* lhs, | (11) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator<(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (12) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator<(const CharT* lhs, | (13) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator<=(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (14) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator<=(const CharT* lhs, | (15) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator>(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (16) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator>(const CharT* lhs, | (17) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator>=(conststd::basic_string<CharT,Traits,Alloc>& lhs, | (18) | (until C++20) |
template<class CharT,class Traits,class Alloc> bool operator>=(const CharT* lhs, | (19) | (until C++20) |
template<class CharT,class Traits,class Alloc> constexpr/*comp-cat*/ | (20) | (since C++20) |
Compares the contents of a string with another string or a null-terminated array ofCharT
.
All comparisons are done via thecompare() member function (which itself is defined in terms ofTraits::compare()
):
basic_string
objects.basic_string
object and a null-terminated array ofCharT
.The return type of three-way comparison operators (/*comp-cat*/) isTraits::comparison_category if that qualified-id exists and denotes a type,std::weak_ordering otherwise. If/*comp-cat*/ is not a comparison category type, the program is ill-formed. The | (since C++20) |
Contents |
lhs, rhs | - | strings whose contents to compare |
Linear in the size of the strings.
If at least one parameter is of typestd::string,std::wstring,std::u8string,std::u16string, orstd::u32string, the return type of | (since C++20) |
This section is incomplete Reason: no example |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 2064 | C++11 | whether overloads taking twobasic_string s are noexcept was inconsistent;overloads taking a CharT* were noexcept but might raise UB | made consistent; noexcept removed |
LWG 3432 | C++20 | the return type ofoperator<=> was not required to be a comparison category type | required |