[concept.equalitycomparable]

# 18 Concepts library [[concepts]](./#concepts)

## 18.5 Comparison concepts [[concepts.compare]](concepts.compare#concept.equalitycomparable)

### 18.5.4 Concept equality_comparable [concept.equalitycomparable]

[ð](#concept:weakly-equality-comparable-with)

`template<class T, class U>
  concept [weakly-equality-comparable-with](#concept:weakly-equality-comparable-with "18.5.4 Concept equality_­comparable [concept.equalitycomparable]") = // exposition only
    requires(const remove_reference_t<T>& t,
             const remove_reference_t<U>& u) {
      { t == u } -> [boolean-testable](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]");
      { t != u } -> [boolean-testable](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]");
      { u == t } -> [boolean-testable](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]");
      { u != t } -> [boolean-testable](concept.booleantestable#concept:boolean-testable "18.5.2 Boolean testability [concept.booleantestable]");
    };
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1041)

Given types T and U,
let t and u be lvalues of typesconst remove_reference_t<T> andconst remove_reference_t<U> respectively[.](#1.sentence-1)

T and U model[*weakly-equality-comparable-with*](#concept:weakly-equality-comparable-with "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<T, U> only if

- [(1.1)](#1.1)

  t == u, u == t, t != u, and u != t have the same domain[.](#1.1.sentence-1)

- [(1.2)](#1.2)

  bool(u == t) == bool(t == u)[.](#1.2.sentence-1)

- [(1.3)](#1.3)

  bool(t != u) == !bool(t == u)[.](#1.3.sentence-1)

- [(1.4)](#1.4)

  bool(u != t) == bool(t != u)[.](#1.4.sentence-1)

[ð](#concept:equality_comparable)

`template<class T>
  concept [equality_comparable](#concept:equality_comparable "18.5.4 Concept equality_­comparable [concept.equalitycomparable]") = [weakly-equality-comparable-with](#concept:weakly-equality-comparable-with "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<T, T>;
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1063)

Let a and b be objects of type T[.](#2.sentence-1)

T models [equality_comparable](#concept:equality_comparable "18.5.4 Concept equality_­comparable [concept.equalitycomparable]") only ifbool(a == b) is true when a is equal tob ([[concepts.equality]](concepts.equality "18.2 Equality preservation")), and false otherwise[.](#2.sentence-2)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1069)

[*Note [1](#note-1)*:

The requirement that the expression a == b is equality-preserving
implies that == is transitive and symmetric[.](#3.sentence-1)

â *end note*]

[ð](#concept:equality_comparable_with)

`template<class T, class U>
  concept [equality_comparable_with](#concept:equality_comparable_with "18.5.4 Concept equality_­comparable [concept.equalitycomparable]") =
    [equality_comparable](#concept:equality_comparable "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<T> && [equality_comparable](#concept:equality_comparable "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<U> &&
    [comparison-common-type-with](concept.comparisoncommontype#concept:comparison-common-type-with "18.5.3 Comparison common types [concept.comparisoncommontype]")<T, U> &&
    [equality_comparable](#concept:equality_comparable "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<
      common_reference_t<
        const remove_reference_t<T>&,
        const remove_reference_t<U>&>> &&
    [weakly-equality-comparable-with](#concept:weakly-equality-comparable-with "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<T, U>;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/concepts.tex#L1089)

Given types T and U,
let t and t2 be lvalues
denoting distinct equal objects of types const remove_reference_t<T> andremove_cvref_t<T>, respectively,
let u and u2 be lvalues
denoting distinct equal objects of types const remove_reference_t<U> andremove_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](#concept:equality_comparable_with "18.5.4 Concept equality_­comparable [concept.equalitycomparable]")<T, U> only ifbool(t == u) == bool(*CONVERT_TO_LVALUE*<C>(t2) == *CONVERT_TO_LVALUE*<C>(u2))
