std::strong_order(3)

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

✨ std::strong_order(3) ✨

okay so bestie, you're on the std::strong_order(3) page from the C++ Standard Libary manual β€” yes, that's the manual name right there, spelling and all πŸ’… β€” and we're about to make this 3-way comparison thing make sense. No cap. 🫢

πŸ’– NAME πŸ’–

std::strong_order β€” std::strong_order

Literally the name. Iconic of it. πŸ‘‘


🌸 Synopsis 🌸

Defined in header <compare>:

Defined in header <compare>
inline namespace /* unspecified */ {

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

}
Call signature
template< class T, class U >

    requires /* see below */

constexpr std::strong_ordering strong_order( T&& t, U&& u )
noexcept(/* see below */);

This thing compares two values using 3-way comparison and produces a result of type std::strong_ordering. Periodt. πŸ’œ

Let t and u be expressions, and let T and U denote decltype((t)) and decltype((u)) respectively. Then std::strong_order(t, u) is expression-equivalent to:

  • If std::is_same_v<std::decay_t<T>, std::decay_t<U>> is true:
    • std::strong_ordering(strong_order(t, u)), if it is a well-formed expression with overload resolution performed in a context that does not include a declaration of std::strong_order,
    • otherwise, if T is a floating-point type:
      • if std::numeric_limits<T>::is_iec559 is true, performs the ISO/IEC/IEEE 60559 totalOrder comparison of floating-point values and returns that result as a value of type std::strong_ordering (note: this comparison can distinguish between the positive and negative zero and between the NaNs with different representations),
      • otherwise, yields a value of type std::strong_ordering that is consistent with the ordering observed by T's comparison operators,
    • otherwise, std::strong_ordering(std::compare_three_way()(t, u)) if it is well-formed.
  • In all other cases, the expression is ill-formed, which can result in substitution failure when it appears in the immediate context of a template instantiation.
tiny warning bestie: that last bullet is the β€œnot valid here” case β€” it's ill-formed, and it can cause substitution failure in a template instantiation's immediate context. Not me being dramatic, that's just what the page says. πŸ’€

πŸ“ Example πŸ“

This section is incomplete.

Reason: no example.

we love a mysterious incomplete section, honestly. πŸŽ€


πŸ‘€ See also πŸ‘€

  • strong_ordering (C++20) β€” the result type of 3-way comparison that supports all 6 operators and is substitutable (class)
  • weak_order (C++20) β€” performs 3-way comparison and produces a result of type std::weak_ordering (customization point object)
  • partial_order (C++20) β€” performs 3-way comparison and produces a result of type std::partial_ordering (customization point object)
  • compare_strong_order_fallback (C++20) β€” performs 3-way comparison and produces a result of type std::strong_ordering, even if operator<=> is unavailable (customization point object)

πŸ—‚οΈ Category πŸ—‚οΈ

  • Todo no example

and that's the whole page, bestie! Source: http://cppreference.com, date/version: 2024.06.10, page: std::strong_order(3). Mwah πŸ’‹πŸ¦‹

πŸ“¦ where this page comes from