7 Concepts library [concepts.lib]

7.4 Comparison concepts [concepts.lib.compare]

7.4.3 Concept EqualityComparable [concepts.lib.compare.equalitycomparable]

template <class T, class U> concept bool WeaklyEqualityComparableWith = requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t == u } -> Boolean&&; { t != u } -> Boolean&&; { u == t } -> Boolean&&; { u != t } -> Boolean&&; };

Let t and u be const lvalues of types remove_reference_t<T> and remove_reference_t<U> respectively. WeaklyEqualityComparableWith<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 bool EqualityComparable = WeaklyEqualityComparableWith<T, T>;

Let a and b be objects of type T. EqualityComparable<T> is satisfied only if:

  • bool(a == b) if and only if a is equal to b.

Note: The requirement that the expression a == b is equality preserving implies that == is reflexive, transitive, and symmetric. — end note ]

template <class T, class U> concept bool 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>&>> && WeaklyEqualityComparableWith<T, U>;

Let t be a const lvalue of type remove_reference_t<T>, u be a const lvalue of type 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)).