16 Language support library [language.support]

16.11 Comparisons [cmp]

16.11.2 Comparison category types [cmp.categories]

16.11.2.4 Class partial_­ordering [cmp.partialord]

The partial_­ordering type is typically used as the result type of a three-way comparison operator that (a) admits all of the six two-way comparison operators ([expr.rel], [expr.eq]), (b) does not imply substitutability, and (c) permits two values to be incomparable.220
namespace std {
  class partial_ordering {
    int value;          // exposition only
    bool is_ordered;    // exposition only

    // exposition-only constructors
    explicit constexpr
      partial_ordering(eq v) noexcept : value(int(v)), is_ordered(true) {}      // exposition only
    explicit constexpr
      partial_ordering(ord v) noexcept : value(int(v)), is_ordered(true) {}     // exposition only
    explicit constexpr
      partial_ordering(ncmp v) noexcept : value(int(v)), is_ordered(false) {}   // exposition only

  public:
    // valid values
    static const partial_ordering less;
    static const partial_ordering equivalent;
    static const partial_ordering greater;
    static const partial_ordering unordered;

    // conversion
    constexpr operator weak_equality() const noexcept;

    // comparisons
    friend constexpr bool operator==(partial_ordering v, unspecified) noexcept;
    friend constexpr bool operator!=(partial_ordering v, unspecified) noexcept;
    friend constexpr bool operator< (partial_ordering v, unspecified) noexcept;
    friend constexpr bool operator> (partial_ordering v, unspecified) noexcept;
    friend constexpr bool operator<=(partial_ordering v, unspecified) noexcept;
    friend constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
    friend constexpr bool operator==(unspecified, partial_ordering v) noexcept;
    friend constexpr bool operator!=(unspecified, partial_ordering v) noexcept;
    friend constexpr bool operator< (unspecified, partial_ordering v) noexcept;
    friend constexpr bool operator> (unspecified, partial_ordering v) noexcept;
    friend constexpr bool operator<=(unspecified, partial_ordering v) noexcept;
    friend constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
    friend constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
    friend constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
  };

  // valid values' definitions
  inline constexpr partial_ordering partial_ordering::less(ord::less);
  inline constexpr partial_ordering partial_ordering::equivalent(eq::equivalent);
  inline constexpr partial_ordering partial_ordering::greater(ord::greater);
  inline constexpr partial_ordering partial_ordering::unordered(ncmp::unordered);
}
constexpr operator weak_equality() const noexcept;
Returns: value == 0 ? weak_­equality::equivalent : weak_­equality::nonequivalent.
[Note
:
The result is independent of the is_­ordered member.
end note
]
constexpr bool operator==(partial_ordering v, unspecified) noexcept; constexpr bool operator< (partial_ordering v, unspecified) noexcept; constexpr bool operator> (partial_ordering v, unspecified) noexcept; constexpr bool operator<=(partial_ordering v, unspecified) noexcept; constexpr bool operator>=(partial_ordering v, unspecified) noexcept;
Returns: For operator@, v.is_­ordered && v.value @ 0.
constexpr bool operator==(unspecified, partial_ordering v) noexcept; constexpr bool operator< (unspecified, partial_ordering v) noexcept; constexpr bool operator> (unspecified, partial_ordering v) noexcept; constexpr bool operator<=(unspecified, partial_ordering v) noexcept; constexpr bool operator>=(unspecified, partial_ordering v) noexcept;
Returns: For operator@, v.is_­ordered && 0 @ v.value.
constexpr bool operator!=(partial_ordering v, unspecified) noexcept; constexpr bool operator!=(unspecified, partial_ordering v) noexcept;
Returns: For operator@, !v.is_­ordered || v.value != 0.
constexpr partial_ordering operator<=>(partial_ordering v, unspecified) noexcept;
Returns: v.
constexpr partial_ordering operator<=>(unspecified, partial_ordering v) noexcept;
Returns: v < 0 ? partial_­ordering::greater : v > 0 ? partial_­ordering::less : v.
That is, a < b, a == b, and a > b might all be false.