operator==,!=,<,<=,>,>=(std::basic_string)
From cppreference.com
< cpp | string | basic string
Compare two basic_string objects | ||
template<class CharT, class Traits, class Alloc > bool operator==(const basic_string<CharT,Traits,Alloc>& lhs, | (1) | |
template<class CharT, class Traits, class Alloc > bool operator!=(const basic_string<CharT,Traits,Alloc>& lhs, | (2) | |
template<class CharT, class Traits, class Alloc > bool operator<(const basic_string<CharT,Traits,Alloc>& lhs, | (3) | |
template<class CharT, class Traits, class Alloc > bool operator<=(const basic_string<CharT,Traits,Alloc>& lhs, | (4) | |
template<class CharT, class Traits, class Alloc > bool operator>(const basic_string<CharT,Traits,Alloc>& lhs, | (5) | |
template<class CharT, class Traits, class Alloc > bool operator>=(const basic_string<CharT,Traits,Alloc>& lhs, | (6) | |
Compare a basic_string object and null-terminated array of T | ||
template<class CharT, class Traits, class Alloc > bool operator==(const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (7) | |
template<class CharT, class Traits, class Alloc > bool operator==(const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (7) | |
template<class CharT, class Traits, class Alloc > bool operator!=(const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (8) | |
template<class CharT, class Traits, class Alloc > bool operator!=(const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (8) | |
template<class CharT, class Traits, class Alloc > bool operator<(const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (9) | |
template<class CharT, class Traits, class Alloc > bool operator<(const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (9) | |
template<class CharT, class Traits, class Alloc > bool operator<=(const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (10) | |
template<class CharT, class Traits, class Alloc > bool operator<=(const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (10) | |
template<class CharT, class Traits, class Alloc > bool operator>(const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (11) | |
template<class CharT, class Traits, class Alloc > bool operator>(const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (11) | |
template<class CharT, class Traits, class Alloc > bool operator>=(const CharT* lhs, const basic_string<CharT,Traits,Alloc>& rhs ); | (12) | |
template<class CharT, class Traits, class Alloc > bool operator>=(const basic_string<CharT,Traits,Alloc>& lhs, const CharT* rhs ); | (12) | |
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
lhs
andrhs
are equal and each character inlhs
has equivalent character inrhs
at the same position.
- The ordering comparisons are done lexicographically -- the comparison is performed by a function equivalent to std::lexicographical_compare.
1-6) Compares two
basic_string
objects.7-12) Compares a
basic_string
object and a null-terminated array of CharT
.Contents |
[edit]Parameters
lhs, rhs | - | strings whose contents to compare |
[edit]Return value
true if the corresponding comparison holds, false otherwise.
[edit]Exceptions
1-6)
(none) | (until C++14) |
noexcept specification: noexcept | (since C++14) |
7-12) (none)
[edit]Complexity
Linear in the size of the strings.