Created on 2019-12-18.00:00:00 last changed 45 months ago
Proposed resolution:
This wording is relative to N4842.
Modify [cmp.concept] as indicated:
template<class T, class U, class Cat = partial_ordering> concept three_way_comparable_with =weakly-equality-comparable-with<T, U> &&partially-ordered-with<T, U> &&three_way_comparable<T, Cat> && three_way_comparable<U, Cat> && common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&> && three_way_comparable< common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>, Cat> && weakly-equality-comparable-with<T, U> && partially-ordered-with<T, U> && requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t <=> u } -> compares-as<Cat>; { u <=> t } -> compares-as<Cat>; };
[ 2020-01 Status set to Tentatively Ready after five positive votes on the reflector. ]
The concept three_way_comparable_with is defined in [cmp.concept] as:
template<class T, class U, class Cat = partial_ordering> concept three_way_comparable_with = weakly-equality-comparable-with<T, U> && partially-ordered-with<T, U> && three_way_comparable<T, Cat> && three_way_comparable<U, Cat> && common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&> && three_way_comparable< common_reference_t<const remove_reference_t<T>&, const remove_reference_t<U>&>, Cat> && requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) { { t <=> u } -> compares-as<Cat>; { u <=> t } -> compares-as<Cat>; };
Which notably doesn't follow the requirement ordering:
same-type requirements on T
same-type requirements on U
common_reference_with requirement
same-type requirements on common_reference_t<T, U>
cross-type requirements on T and U
that the other cross-type comparison concepts ([concept.equalitycomparable], [concept.totallyordered]) use. There were some motivating reasons for that ordering:
The existence of a common reference type is effectively an opt-in to cross-type concepts. Avoiding checking cross-type expressions when no common reference type exists can enable the concepts to work even in the presence of poorly-constrained "accidental" cross-type operator templates which could otherwise produce compile errors instead of dissatisfied concepts.
Putting the simpler same-type requirements first can help produce simpler error messages when applying the wrong concept to a pair of types, or the right concept to the wrong pair of types. "Frobnozzle <=> Frobnozzle is not a valid expression" is more easily deciphered than is "std::common_reference<int, FrobNozzle> has no member named type".
three_way_comparable_with should be made consistent with equality_comparable_with and totally_ordered_with for the above reasons and to make it easier to reason about comparison concepts in general.
History | |||
---|---|---|---|
Date | User | Action | Args |
2021-02-25 10:48:01 | admin | set | status: wp -> c++20 |
2020-02-24 16:02:59 | admin | set | status: voting -> wp |
2020-01-17 04:54:50 | admin | set | status: ready -> voting |
2020-01-05 16:13:01 | admin | set | messages: + msg10910 |
2020-01-05 16:13:01 | admin | set | status: new -> ready |
2019-12-21 14:36:49 | admin | set | messages: + msg10899 |
2019-12-18 00:00:00 | admin | create |