18 Concepts library [concepts]

18.5 Comparison concepts [concepts.compare]

18.5.4 Concept equality_­comparable [concept.equalitycomparable]

template<class T, class U> concept weakly-equality-comparable-with = // exposition only requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t == u } -> boolean-testable; { t != u } -> boolean-testable; { u == t } -> boolean-testable; { u != t } -> boolean-testable; };
Given types T and U, let t and u be lvalues of types const remove_­reference_­t<T> and const remove_­reference_­t<U> respectively.
T and U model weakly-equality-comparable-with<T, U> only if
  • t == u, u == t, t != u, and u != t have the same domain.
  • bool(u == t) == bool(t == u).
  • bool(t != u) == !bool(t == u).
  • bool(u != t) == bool(t != u).
Let a and b be objects of type T.
T models equality_­comparable only if bool(a == b) is true when a is equal to b ([concepts.equality]), and false otherwise.
[Note 1:
The requirement that the expression a == b is equality-preserving implies that == is transitive and symmetric.
— end note]
template<class T, class U> concept equality_­comparable_­with = equality_­comparable<T> && equality_­comparable<U> && comparison-common-type-with<T, U> && equality_­comparable< common_reference_t< const remove_reference_t<T>&, const remove_reference_t<U>&>> && weakly-equality-comparable-with<T, U>;
Given types T and U, let t and t2 be lvalues denoting distinct equal objects of types const remove_­reference_­t<T> and remove_­cvref_­t<T>, respectively, let u and u2 be lvalues denoting distinct equal objects of types const remove_­reference_­t<U> and remove_­cvref_­t<U>, respectively, and let C be: common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&> T and U model equality_­comparable_­with<T, U> only if bool(t == u) == bool(CONVERT_TO_LVALUE<C>(t2) == CONVERT_TO_LVALUE<C>(u2))