18 Concepts library [concepts]

18.5 Comparison concepts [concepts.compare]

18.5.5 Concept totally_­ordered [concept.totallyordered]

template<class T> concept totally_­ordered = equality_­comparable<T> && partially-ordered-with<T, T>;
Given a type T, let a, b, and c be lvalues of type const remove_­reference_­t<T>.
T models totally_­ordered only if
  • Exactly one of bool(a < b), bool(a > b), or bool(a == b) is true.
  • If bool(a < b) and bool(b < c), then bool(a < c).
  • bool(a <= b) == !bool(b < a).
  • bool(a >= b) == !bool(a < b).
template<class T, class U> concept totally_­ordered_­with = totally_­ordered<T> && totally_­ordered<U> && equality_­comparable_­with<T, U> && totally_­ordered< common_reference_t< const remove_reference_t<T>&, const remove_reference_t<U>&>> && partially-ordered-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 totally_­ordered_­with<T, U> only if
  • bool(t < u) == bool(CONVERT_­TO_­LVALUE<C>(t2) < CONVERT_­TO_­LVALUE<C>(u2)).
  • bool(t > u) == bool(CONVERT_­TO_­LVALUE<C>(t2) > CONVERT_­TO_­LVALUE<C>(u2)).
  • bool(t <= u) == bool(CONVERT_­TO_­LVALUE<C>(t2) <= CONVERT_­TO_­LVALUE<C>(u2)).
  • bool(t >= u) == bool(CONVERT_­TO_­LVALUE<C>(t2) >= CONVERT_­TO_­LVALUE<C>(u2)).
  • bool(u < t) == bool(CONVERT_­TO_­LVALUE<C>(u2) < CONVERT_­TO_­LVALUE<C>(t2)).
  • bool(u > t) == bool(CONVERT_­TO_­LVALUE<C>(u2) > CONVERT_­TO_­LVALUE<C>(t2)).
  • bool(u <= t) == bool(CONVERT_­TO_­LVALUE<C>(u2) <= CONVERT_­TO_­LVALUE<C>(t2)).
  • bool(u >= t) == bool(CONVERT_­TO_­LVALUE<C>(u2) >= CONVERT_­TO_­LVALUE<C>(t2)).