std::three_...arable_with(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 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:

  1. The concept std::three_way_comparable specifies that the three way comparison operator <=> on T yield results consistent with the comparison category implied by Cat.
  2. The concept std::three_way_comparable_with specifies that the three way comparison operator <=> on (possibly mixed) T and U operands yield results consistent with the comparison category implied by Cat. 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 that operator == is an equivalence relation. The page also lists equality_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 lists totally_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