std::three_...arable_with(3)
πΈ NAME πΈ
Okay bestie, this is the std::three_...arable_with(3) page from the C++ Standard Libary manual. The NAME line is literally std::three_way_comparable,std::three_way_comparable_with β comma smooshed, no space β then a dash, then it repeats std::three_way_comparable,std::three_way_comparable_with. Two concepts, one NAME line, absolutely iconic. π
β¨ Synopsis β¨
Defined in header <compare>.
First concept, first vibe β the page marks this one (1) and (since C++20):
template< class T, class Cat = std::partial_ordering >
concept three_way_comparable =
__WeaklyEqualityComparableWith<T, T> &&
__PartiallyOrderedWith<T, T> &&
requires(const std::remove_reference_t<T>& a,
const std::remove_reference_t<T>& b) {
{ a <=> b } -> __ComparesAs<Cat>;
};
Then the mixed-operand concept β the page marks this one (2) and (since C++20):
template< class T, class U, class Cat = std::partial_ordering >
concept three_way_comparable_with =
std::three_way_comparable<T, Cat> &&
std::three_way_comparable<U, Cat> &&
__ComparisonCommonTypeWith<T, U> &&
std::three_way_comparable<
std::common_reference_t<
const std::remove_reference_t<T>&,
const std::remove_reference_t<U>&>, Cat> &&
__WeaklyEqualityComparableWith<T, U> &&
__PartiallyOrderedWith<T, U> &&
requires(const std::remove_reference_t<T>& t,
const std::remove_reference_t<U>& u) {
{ t <=> u } -> __ComparesAs<Cat>;
{ u <=> t } -> __ComparesAs<Cat>;
};
And the helper concept β the page marks this one (3) and labels it (exposition only*):
template< class T, class Cat >
concept __ComparesAs =
std::same_as<std::common_comparison_category_t<T, Cat>, Cat>;
Here's the numbered lore, bestie:
- The concept
std::three_way_comparablespecifies that the three way comparison operator<=>onTyield results consistent with the comparison category implied byCat. - The concept
std::three_way_comparable_withspecifies that the three way comparison operator<=>on (possibly mixed)TandUoperands yield results consistent with the comparison category implied byCat. Comparing mixed operands yields results equivalent to comparing the operands converted to their common type.
Also: __WeaklyEqualityComparableWith, __PartiallyOrderedWith, and __ComparisonCommonTypeWith are exposition-only concepts. See descriptions of equality_comparable and totally_ordered.
π See also π
equality_comparableβ specifies thatoperator ==is an equivalence relation. The page also listsequality_comparable_with(concept)(C++20)right there in the same See also cluster.totally_orderedβ specifies that the comparison operators on the type yield a total order. The page also liststotally_ordered_with(concept)(C++20)right there in the same See also cluster.
Bye bestie π β this was std::three_...arable_with(3) from http://cppreference.com, dated 2024.06.10. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms