Namespaces
Variants
Actions

Standard library header <compare> (C++20)

From cppreference.com
< cpp‎ | header
 
 
Standard library headers
 

This header is part of the language support library.

Contents

Concepts

specifies that operator <=> produces consistent result on given types
(concept) [edit]

Classes

the result type of 3-way comparison that supports all 6 operators, is not substitutable, and allows incomparable values
(class) [edit]
the result type of 3-way comparison that supports all 6 operators and is not substitutable
(class) [edit]
the result type of 3-way comparison that supports all 6 operators and is substitutable
(class) [edit]
the strongest comparison category to which all of the given types can be converted
(class template) [edit]
obtains the result type of the three-way comparison operator <=> on given types
(class template) [edit]
constrained function object implementing x <=> y
(class) [edit]

Customization point objects

performs 3-way comparison and produces a result of type std::strong_ordering
(customization point object)[edit]
performs 3-way comparison and produces a result of type std::weak_ordering
(customization point object)[edit]
performs 3-way comparison and produces a result of type std::partial_ordering
(customization point object)[edit]
performs 3-way comparison and produces a result of type std::strong_ordering, even if operator<=> is unavailable
(customization point object)[edit]
performs 3-way comparison and produces a result of type std::weak_ordering, even if operator<=> is unavailable
(customization point object)[edit]
performs 3-way comparison and produces a result of type std::partial_ordering, even if operator<=> is unavailable
(customization point object)[edit]

Functions

named comparison functions
(function) [edit]

[edit] Synopsis

namespace std {
  // comparison category types
  class partial_ordering;
  class weak_ordering;
  class strong_ordering;
 
  // named comparison functions
  constexpr bool is_eq  (partial_ordering cmp) noexcept { return cmp == 0; }
  constexpr bool is_neq (partial_ordering cmp) noexcept { return cmp != 0; }
  constexpr bool is_lt  (partial_ordering cmp) noexcept { return cmp < 0; }
  constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
  constexpr bool is_gt  (partial_ordering cmp) noexcept { return cmp > 0; }
  constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
 
  // common comparison category type
  template<class... Ts>
  struct common_comparison_category {
    using type = /* see description */;
  };
  template<class... Ts>
    using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
 
  // concept three_way_comparable
  template<class T, class Cat = partial_ordering>
    concept three_way_comparable = /* see description */;
  template<class T, class U, class Cat = partial_ordering>
    concept three_way_comparable_with = /* see description */;
 
  // result of three-way comparison
  template<class T, class U = T> struct compare_three_way_result;
 
  template<class T, class U = T>
    using compare_three_way_result_t = typename compare_three_way_result<T, U>::type;
 
  // class compare_three_way
  struct compare_three_way;
 
  // comparison algorithms
  inline namespace /* unspecified */ {
    inline constexpr /* unspecified */ strong_order = /* unspecified */;
    inline constexpr /* unspecified */ weak_order = /* unspecified */;
    inline constexpr /* unspecified */ partial_order = /* unspecified */;
    inline constexpr /* unspecified */ compare_strong_order_fallback = /* unspecified */;
    inline constexpr /* unspecified */ compare_weak_order_fallback = /* unspecified */;
    inline constexpr /* unspecified */ compare_partial_order_fallback = /* unspecified */;
  }
}

[edit] Concept three_way_comparable

namespace std {
  template<class T, class Cat>
    concept __ComparesAs =                // exposition only
      same_as<common_comparison_category_t<T, Cat>, Cat>;
 
  template<class T, class U>
    concept __PartiallyOrderedWith =      // exposition only
      requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) {
        { t <  u } -> boolean-testable;
        { t >  u } -> boolean-testable;
        { t <= u } -> boolean-testable;
        { t >= u } -> boolean-testable;
        { u <  t } -> boolean-testable;
        { u >  t } -> boolean-testable;
        { u <= t } -> boolean-testable;
        { u >= t } ->