17 Concepts library [concepts]

17.5 Comparison concepts [concepts.compare]

17.5.3 Concept EqualityComparable [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; requires Boolean<decltype(t == u)>; t != u; requires Boolean<decltype(t != u)>; u == t; requires Boolean<decltype(u == t)>; u != t; requires Boolean<decltype(u != t)>; };
Let t and u be lvalues of types const remove_­reference_­t<T> and const remove_­reference_­t<U> respectively.
weakly-equality-comparable-with<T, U> is satisfied 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).
template<class T> concept EqualityComparable = weakly-equality-comparable-with<T, T>;
Let a and b be objects of type T.
EqualityComparable<T> is satisfied only if bool(a == b) is true when a is equal to b ([concepts.equality]), and false otherwise.
[Note
:
The requirement that the expression a == b is equality-preserving implies that == is transitive and symmetric.
end note
]
template<class T, class U> concept EqualityComparableWith = EqualityComparable<T> && EqualityComparable<U> && CommonReference<const remove_reference_t<T>&, const remove_reference_t<U>&> && EqualityComparable< common_reference_t< const remove_reference_t<T>&, const remove_reference_t<U>&>> && weakly-equality-comparable-with<T, U>;
Let t be an lvalue of type const remove_­reference_­t<T>, u be an lvalue of type const remove_­reference_­t<U>, and C be:
common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>
EqualityComparableWith<T, U> is satisfied only if bool(t == u) == bool(C(t) == C(u)).