operator==,!=,<,<=,>,>=,<=>(std::basic_string)
| Defined in header <string>
|
||
| Compare two basic_string objects |
||
template< class CharT, class Traits, class Alloc >
bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(1) | (noexcept since C++11) (constexpr since C++20) |
template< class CharT, class Traits, class Alloc >
bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(2) | (until C++20) (noexcept since C++11) |
template< class CharT, class Traits, class Alloc >
bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(3) | (until C++20) (noexcept since C++11) |
template< class CharT, class Traits, class Alloc >
bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(4) | (until C++20) (noexcept since C++11) |
template< class CharT, class Traits, class Alloc >
bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(5) | (until C++20) (noexcept since C++11) |
template< class CharT, class Traits, class Alloc >
bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(6) | (until C++20) (noexcept since C++11) |
template< class CharT, class Traits, class Alloc >
constexpr /*comp-cat*/
operator<=>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs ) noexcept;
|
(7) | (since C++20) |
| Compare a basic_string object and null-terminated array of T |
||
template< class CharT, class Traits, class Alloc >
bool operator==( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(8) | (constexpr since C++20) |
template< class CharT, class Traits, class Alloc >
bool operator==( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(9) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator!=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(10) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator!=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(11) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(12) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(13) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(14) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator<=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(15) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(16) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(17) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>=( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(18) | (until C++20) |
template< class CharT, class Traits, class Alloc >
bool operator>=( const CharT* lhs,
const std::basic_string<CharT,Traits,Alloc>& rhs );
|
(19) | (until C++20) |
template< class CharT, class Traits, class Alloc >
constexpr /*comp-cat*/
operator<=>( const std::basic_string<CharT,Traits,Alloc>& lhs,
const CharT* rhs );
|
(20) | (since C++20) |
Compares the contents of a string with another string or a null-terminated array of CharT.
All comparisons are done via the compare() member function (which itself is defined in terms of Traits::compare()):
- Two strings are equal if both the size of
lhsandrhsare equal and each character inlhshas equivalent character inrhsat the same position.
- The ordering comparisons are done lexicographically – the comparison is performed by a function equivalent to std::lexicographical_compareor std::lexicographical_compare_three_way(since C++20).
basic_string objects.basic_string object and a null-terminated array of CharT.|
The return type of three-way comparison operators ( The |
(since C++20) |
Parameters
| lhs, rhs | - | strings whose contents to compare |
Return value
true if the corresponding comparison holds, false otherwise.static_cast</*comp-cat*/>(lhs.compare(rhs) <=> 0).Complexity
Linear in the size of the strings.
Notes
|
If at least one parameter is of type std::string, std::wstring, std::u8string, std::u16string, or std::u32string, the return type of |
(since C++20) |
Example
| This section is incomplete Reason: no example |
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
