std::partial_ordering(3)
π std::partial_ordering(3) β a deep dive from your friendly neighborhood C++ bestie
okay so this page lives in the C++ Standard Library manual (yes, the (3) is giving "section 3, library functions" β iykyk) and it's literally all about std::partial_ordering. buckle up bestie, we're comparing things that maybe don't even compare. π¦
β¨ NAME β¨
std::partial_ordering β that's it, that's the name. iconic of it honestly. π
πΈ Synopsis πΈ
Defined in header <compare>
class partial_ordering; (since C++20)
So std::partial_ordering is the class type you get back as the result type of a three-way comparison that:
- Admits all six relational operators (
==,!=,<,<=,>,>=). - Does not imply substitutability: if
ais equivalent tob, thenf(a)may not be equivalent tof(b), wherefdenotes a function that reads only comparison-salient state that is accessible via the argument's public const members. In other words, equivalent values may be distinguishable. (yes bestie, "equivalent but not identical" is a whole vibe π) - Admits incomparable values:
a < b,a == b, anda > bmay all be false. the way that everything can just be no π
π Constants π
The type std::partial_ordering has four valid values, implemented as const static data members of its type:
less(inline constexpr) [static] β a valid value of the typestd::partial_orderingindicating less-than (ordered before) relationship (public static member constant)equivalent(inline constexpr) [static] β a valid value of the typestd::partial_orderingindicating equivalence (neither ordered before nor ordered after) (public static member constant)greater(inline constexpr) [static] β a valid value of the typestd::partial_orderingindicating greater-than (ordered after) relationship (public static member constant)unordered(inline constexpr) [static] β a valid value of the typestd::partial_orderingindicating relationship with an incomparable value (public static member constant)
four constants, zero skips. slay. β¨
π¦ Conversions π¦
std::partial_ordering cannot be implicitly converted to other comparison category types, while both std::strong_ordering and std::weak_ordering are implicitly-convertible to partial_ordering.
so likeβ¦ they can come to our party, but we're not going to theirs. boundaries. π
π₯ Comparisons π₯
Comparison operators are defined between values of this type and literal 0. This supports the expressions a <=> b == 0 or a <=> b < 0 that can be used to convert the result of a three-way comparison operator to a boolean relationship; see std::is_eq, std::is_lt, etc.
These functions are not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::partial_ordering is an associated class of the arguments.
β οΈ big warning bestie: the behavior of a program that attempts to compare apartial_orderingwith anything other than the integer literal0is undefined. not "returns something weird". undefined. periodt. π
The whole squad:
operator==operator<operator>operator<=β compares with zero or apartial_ordering(function)operator>=operator<=>
π operator== π
friend constexpr bool operator==( partial_ordering v, /*unspecified*/ u ) noexcept; (1)
friend constexpr bool operator==( partial_ordering v, partial_ordering w ) noexcept = default; (2)
Parameters
v,wβstd::partial_orderingvalues to checkuβ an unused parameter of any type that accepts literal zero argument
Return value
trueifvisequivalent,falseifvisless,greater, orunorderedtrueif both parameters hold the same value,falseotherwise
β operator< β
friend constexpr bool operator<( partial_ordering v, /*unspecified*/ u ) noexcept; (1)
friend constexpr bool operator<( /*unspecified*/ u, partial_ordering v ) noexcept; (2)
Parameters
vβ astd::partial_orderingvalue to checkuβ an unused parameter of any type that accepts literal zero argument
Return value
trueifvisless, andfalseifvisgreater,equivalent, orunorderedtrueifvisgreater, andfalseifvisless,equivalent, orunordered
π operator<= π
friend constexpr bool operator<=( partial_ordering v, /*unspecified*/ u ) noexcept; (1)
friend constexpr bool operator<=( /*unspecified*/ u, partial_ordering v ) noexcept; (2)
Parameters
vβ astd::partial_orderingvalue to checkuβ an unused parameter of any type that accepts literal zero argument
Return value
trueifvislessorequivalent, andfalseifvisgreaterorunorderedtrueifvisgreaterorequivalent, andfalseifvislessorunordered
π operator> π
friend constexpr bool operator>( partial_ordering v, /*unspecified*/ u ) noexcept; (1)
friend constexpr bool operator>( /*unspecified*/ u, partial_ordering v ) noexcept; (2)
Parameters
vβ astd::partial_orderingvalue to checkuβ an unused parameter of any type that accepts literal zero argument
Return value
trueifvisgreater, andfalseifvisless,equivalent, orunorderedtrueifvisless, andfalseifvisgreater,equivalent, orunordered
π§ operator>= π§
friend constexpr bool operator>=( partial_ordering v, /*unspecified*/ u ) noexcept; (1)
friend constexpr bool operator>=( /*unspecified*/ u, partial_ordering v ) noexcept; (2)
Parameters
vβ astd::partial_orderingvalue to checkuβ an unused parameter of any type that accepts literal zero argument
Return value
trueifvisgreaterorequivalent, andfalseifvislessorunorderedtrueifvislessorequivalent, andfalseifvisgreaterorunordered
π operator<=> π
friend constexpr partial_ordering operator<=>( partial_ordering v, /*unspecified*/ u ) noexcept; (1)
friend constexpr partial_ordering operator<=>( /*unspecified*/ u, partial_ordering v ) noexcept; (2)
Parameters
vβ astd::partial_orderingvalue to checkuβ an unused parameter of any type that accepts literal zero argument
Return value
v.greaterifvisless,lessifvisgreater, otherwisev.
(yeah, return value #1 is literally just "v." β nothing more, nothing less. she said "I am the answer" π
)
π Notes π
The built-in operator<=> between floating-point values uses this ordering: the positive zero and the negative zero compare equivalent, but can be distinguished, and NaN values compare unordered with any other value.
so 0.0 == -0.0 is true but they're not the same and NaN refuses to be compared at all. main character energy, honestly. π
πΈ Example πΈ
π§ This section is incomplete Reason: no example
(ngl, they really said "figure it out bestie" on this one π)
π«Ά See also π«Ά
strong_ordering(C++20) β the result type of 3-way comparison that supports all 6 operators and is substitutable (class)weak_ordering(C++20) β the result type of 3-way comparison that supports all 6 operators and is not substitutable (class)
π Category π
- Todo no example
(yeah, same todo, still no example. it's giving unfinished homework. π)
okay that's the whole page bestie!! β¨ this one came from cppreference.com, dated 2024.06.10 β go drink some water and go compare some floats responsibly π«Άππ
π¦ 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