operator==,!=,<,<=,>,>=,<=>(std::sub_match) - cppreference.com
| Defined in header |
||
| Direct comparison |
||
|
|
(1) | (since C++11) |
|
|
(2) | (since C++11) (until C++20) |
|
|
(3) | (since C++11) (until C++20) |
|
|
(4) | (since C++11) (until C++20) |
|
|
(5) | (since C++11) (until C++20) |
|
|
(6) | (since C++11) (until C++20) |
|
|
(7) | (since C++20) |
| Comparing with a std::basic_string |
||
|
|
(8) | (since C++11) |
|
|
(9) | (since C++11) (until C++20) |
|
|
(10) | (since C++11) (until C++20) |
|
|
(11) | (since C++11) (until C++20) |
|
|
(12) | (since C++11) (until C++20) |
|
|
(13) | (since C++11) (until C++20) |
|
|
(14) | (since C++20) |
|
|
(15) | (since C++11) (until C++20) |
|
|
(16) | (since C++11) (until C++20) |
|
|
(17) | (since C++11) (until C++20) |
|
|
(18) | (since C++11) (until C++20) |
|
|
(19) | (since C++11) (until C++20) |
|
|
(20) | (since C++11) (until C++20) |
| Comparing with a C-style string |
||
|
|
(21) | (since C++11) |
|
|
(22) | (since C++11) (until C++20) |
|
|
(23) | (since C++11) (until C++20) |
|
|
(24) | (since C++11) (until C++20) |
|
|
(25) | (since C++11) (until C++20) |
|
|
(26) | (since C++11) (until C++20) |
|
|
(27) | (since C++20) |
|
|
(28) | (since C++11) (until C++20) |
|
|
(29) | (since C++11) (until C++20) |
|
|
(30) | (since C++11) (until C++20) |
|
|
(31) | (since C++11) (until C++20) |
|
|
(32) | (since C++11) (until C++20) |
|
|
(33) | (since C++11) (until C++20) |
| Comparing with a single character |
||
|
|
(34) | (since C++11) |
|
|
(35) | (since C++11) (until C++20) |
|
|
(36) | (since C++11) (until C++20) |
|
|
(37) | (since C++11) (until C++20) |
|
|
(38) | (since C++11) (until C++20) |
|
|
(39) | (since C++11) (until C++20) |
|
|
(40) | (since C++20) |
|
|
(41) | (since C++11) (until C++20) |
|
|
(42) | (since C++11) (until C++20) |
|
|
(43) | (since C++11) (until C++20) |
|
|
(44) | (since C++11) (until C++20) |
|
|
(45) | (since C++11) (until C++20) |
|
|
(46) | (since C++11) (until C++20) |
| Helper type aliases |
||
|
(47) | (exposition only*) |
|
(48) | (since C++20) (exposition only*) |
Compares a sub_match to another sub_match, a std::string, a C-style string or a single character.
1-7) Compares two sub_match directly.
8-20) Compares a sub_match with a std::basic_string.
21-33) Compares a sub_match with a C-style string.
34-46) Compares a sub_match with a single character.
|
The |
(since C++20) |
47) value-type-of <BidirIt> is the value type of BidirIt.
48) cat-type-of <BidirIt> is the result type of three-way comparison of std::sub_match<BidirIt>.
Parameters
| lhs, rhs | - | a sub_match to compare
|
| str | - | a std::basic_string to compare |
| s | - | a pointer to a C-style string to compare |
| ch | - | a character to compare |
Return value
Let target be the following values:
1-7) rhs
8-20) typename std::sub_match<BidirIt>::string_type(str.data(), str.size())
21-33) s
34-46) typename std::sub_match<BidirIt>::string_type(1, ch)
The return values are defined as follows:
| Operator | Return value | |
|---|---|---|
| Overloads (1-14,21-27,34-40) (overloads with parameter lhs)
|
Overloads (15-20,28-33,41-46) (overloads without parameter lhs)
| |
==
|
lhs.compare(target) == 0
|
rhs.compare(target) == 0
|
!=
|
lhs.compare(target) != 0
|
rhs.compare(target) != 0
|
<
|
lhs.compare(target) < 0
|
rhs.compare(target) > 0
|
<=
|
lhs.compare(target) <= 0
|
rhs.compare(target) >= 0
|
>
|
lhs.compare(target) > 0
|
rhs.compare(target) < 0
|
>=
|
lhs.compare(target) >= 0
|
rhs.compare(target) <= 0
|
<=>
|
static_cast<cat-type-of <BidirIt>> (lhs.compare(target) <=> 0)
|
N/A |
Notes
The return type of operator<=> is guaranteed to be a comparison category type. If value-type-of <BidirIt> is char, wchar_t, char8_t, char16_t, or char32_t, the return type of operator<=> is std::strong_ordering.
Example
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2217 | C++11 | for comparisons with std::string, the argument of compare() was str.c_str()
|
the argument isstring_type(str.data(), str.size()))
|
See also
| compares matched subsequence (if any) (public member function) [edit] |