Files
2025-10-25 03:02:53 +03:00

7.3 KiB

[cmp.concept]

17 Language support library [support]

17.12 Comparisons [cmp]

17.12.4 Concept three_way_comparable [cmp.concept]

template<class T, class Cat>concept compares-as = // exposition onlysame_as<common_comparison_category_t<T, Cat>, Cat>;

template<class T, class U>concept partially-ordered-with = // exposition onlyrequires(const remove_reference_t& t, const remove_reference_t& u) {{ t < u } -> boolean-testable; { t > u } -> boolean-testable; { t <= u } -> boolean-testable; { t >= u } -> boolean-testable; { u < t } -> boolean-testable; { u > t } -> boolean-testable; { u <= t } -> boolean-testable; { u >= t } -> boolean-testable; };

1

#

Let t and u be lvalues of types const remove_reference_t andconst remove_reference_t, respectively.

T and U modelpartially-ordered-with<T, U> only if

t < u, t <= u, t > u, t >= u, u < t, u <= t, u > t, and u >= t have the same domain,

bool(t < u) == bool(u > t) is true,

bool(u < t) == bool(t > u) is true,

bool(t <= u) == bool(u >= t) is true, and

bool(u <= t) == bool(t >= u) is true.

template<class T, class Cat = partial_ordering>concept three_way_comparable =weakly-equality-comparable-with<T, T> &&partially-ordered-with<T, T> &&requires(const remove_reference_t& a, const remove_reference_t& b) {{ a <=> b } -> compares-as; };

2

#

Let a and b be lvalues of type const remove_reference_t.

T and Cat model three_way_comparable<T, Cat> only if

(a <=> b == 0) == bool(a == b) is true,

(a <=> b != 0) == bool(a != b) is true,

((a <=> b) <=> 0) and (0 <=> (b <=> a)) are equal,

(a <=> b < 0) == bool(a < b) is true,

(a <=> b > 0) == bool(a > b) is true,

(a <=> b <= 0) == bool(a <= b) is true,

(a <=> b >= 0) == bool(a >= b) is true, and

if Cat is convertible to strong_ordering, T models totally_ordered ([concept.totallyordered]).

template<class T, class U, class Cat = partial_ordering>concept three_way_comparable_with =three_way_comparable<T, Cat> &&three_way_comparable<U, Cat> &&comparison-common-type-with<T, U> &&three_way_comparable< common_reference_t<const remove_reference_t&, const remove_reference_t&>, Cat> &&weakly-equality-comparable-with<T, U> &&partially-ordered-with<T, U> &&requires(const remove_reference_t& t, const remove_reference_t& u) {{ t <=> u } -> compares-as; { u <=> t } -> compares-as; };

3

#

Let t and t2 be lvalues denoting distinct equal objects of types const remove_reference_t andremove_cvref_t, respectively, and let u and u2 be lvalues denoting distinct equal objects of types const remove_reference_t andremove_cvref_t, respectively.

Let C becommon_reference_t<const remove_reference_t&, const remove_reference_t&>.

Let CONVERT_TO_LVALUE(E) be defined as in [concepts.compare.general].

T, U, and Cat model three_way_comparable_with<T, U, Cat> only if

t <=> u and u <=> t have the same domain,

((t <=> u) <=> 0) and (0 <=> (u <=> t)) are equal,

(t <=> u == 0) == bool(t == u) is true,

(t <=> u != 0) == bool(t != u) is true,

Cat(t <=> u) == Cat(CONVERT_TO_LVALUE(t2) <=>CONVERT_TO_LVALUE(u2)) is true,

(t <=> u < 0) == bool(t < u) is true,

(t <=> u > 0) == bool(t > u) is true,

(t <=> u <= 0) == bool(t <= u) is true,

(t <=> u >= 0) == bool(t >= u) is true, and

if Cat is convertible to strong_ordering, T and U model totally_ordered_with<T, U> ([concept.totallyordered]).