std::compar...der_fallback(3)

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

okay so bestie, welcome to std::compare_partial_order_fallback, aka the std::compar...der_fallback(3) page from the C++ Standard Libary πŸ’…βœ¨. This is your fallback three-way comparison bestie: it performs three-way comparison on subexpressions t and u and produces a result of type std::partial_ordering, even if operator <=> is unavailable. no cap, that's the vibe.

πŸ’– NAME πŸ’–

std::compare_partial_order_fallback β€” std::compare_partial_order_fallback. like, yes, the name is the name, periodt.

πŸ¦‹ SYNOPSIS πŸ¦‹

Okay so here's the setup, bestie: this lives in the header <compare>, and it's giving since C++20 energy from the jump.

Defined in header <compare>

inline namespace /* unspecified */ {

    inline constexpr /* unspecified */
(since C++20)
        compare_partial_order_fallback = /* unspecified */;

}

Call signature
template< class T, class U >

    requires /* see below */
constexpr std::partial_ordering
(since C++20)

    compare_partial_order_fallback( T&& t, U&& u ) noexcept(/* see
below */);

So what does it actually do? It performs three-way comparison on subexpressions t and u and produces a result of type std::partial_ordering, even if the operator <=> is unavailable. slay.

If std::decay_t<T> and std::decay_t<U>> are the same type, std::compare_partial_order_fallback(t, u) is expression-equivalent to:

  • std::partial_order(t, u), if it is a well-formed expression;
  • otherwise,
t == u ? std::partial_ordering::equivalent :
t < u  ? std::partial_ordering::less :
u < t  ? std::partial_ordering::greater :
         std::partial_ordering::unordered

if the expressions t == u, t < u and u < t are all well-formed and each of decltype(t == u) and decltype(t < u) models boolean-testable, except that t and u are evaluated only once.

In all other cases, std::compare_partial_order_fallback(t, u) is ill-formed, which can result in substitution failure when it appears in the immediate context of a template instantiation. πŸ’€

🌸 EXAMPLE 🌸

This section is incomplete.

Reason: no example πŸ™ˆ

πŸ’€ DEFECT REPORTS πŸ’€

The following behavior-changing defect reports were applied retroactively to previously published C++ standards. yes bestie, they went back and fixed the lore.

  • LWG 2114 (P2167R3) β€” applied to C++20. Behavior as published: the fallback mechanism only required return types to be convertible to bool. Correct behavior: constraints strengthened.
  • LWG 3465 β€” applied to C++20. Behavior as published: the fallback mechanism did not require u < t to be well-formed. Correct behavior: required u < t to be well-formed.

πŸ‘€ SEE ALSO πŸ‘€

  • partial_order (C++20) β€” performs 3-way comparison and produces a result of type std::partial_ordering (customization point object).

πŸ“ CATEGORY: πŸ“

  • Todo no example

mwah πŸ’‹ β€” sourced from http://cppreference.com, version/date 2024.06.10, and this was the std::compar...der_fallback(3) page. bye bestie, go compare things safely 🫢✨

πŸ“¦ where this page comes from