|
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The type must work with== operator and the result should have standard semantics.
Contents |
The typeT satisfiesEqualityComparable if given expressionsa,b andc of typeT or(since C++11)const T, the following expression is valid and has its specified effects:
| Expression | Type | Effects |
|---|---|---|
| a== b | meetsBooleanTestable (until C++20) | Establishes anequivalence relation, that is, it satisfies the following properties:
|
modelsboolean-testable(since C++20) |
To satisfy this requirement, types that do not have built-incomparison operators have to provide auser-definedoperator==.
For the types that are bothEqualityComparable andLessThanComparable, the C++ standard library makes a distinction between
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 283 | C++98 | even ifT isEqualityComparable, therequirements did not apply toconst T objects | they apply to const T instead of T |
| LWG 2114 (P2167R3) | C++98 | convertibility tobool was too weak to reflect the expectation of implementations | requirements strengthened |
| specifies that operator== is an equivalence relation (concept)[edit] |