Namespaces
Variants

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

From cppreference.net
Standard library headers

Cet en-tête fait partie de la bibliothèque de support du langage .

Table des matières

Concepts

spécifie que l'opérateur <=> produit un résultat cohérent sur les types donnés
(concept)

Classes

le type de résultat de la comparaison à trois voies qui prend en charge les 6 opérateurs, n'est pas substituable et autorise les valeurs incomparables
(classe)
le type de résultat de la comparaison à trois voies qui prend en charge les 6 opérateurs et n'est pas substituable
(classe)
le type de résultat de la comparaison à trois voies qui prend en charge les 6 opérateurs et est substituable
(classe)
la catégorie de comparaison la plus forte à laquelle tous les types donnés peuvent être convertis
(modèle de classe)
obtient le type de résultat de l'opérateur de comparaison à trois voies <=> sur les types donnés
(modèle de classe)
objet fonction contraint implémentant x <=> y
(classe)

Objets de point de personnalisation

effectue une comparaison à trois voies et produit un résultat de type std::strong_ordering
(objet point de personnalisation)
(C++20)
effectue une comparaison à trois voies et produit un résultat de type std::weak_ordering
(objet de point de personnalisation)
effectue une comparaison à trois voies et produit un résultat de type std::partial_ordering
(objet point de personnalisation)
effectue une comparaison à trois voies et produit un résultat de type std::strong_ordering , même si operator <=> n'est pas disponible
(objet de point de personnalisation)
effectue une comparaison à trois voies et produit un résultat de type std::weak_ordering , même si operator <=> n'est pas disponible
(objet de point de personnalisation)
effectue une comparaison à trois voies et produit un résultat de type std::partial_ordering , même si operator <=> n'est pas disponible
(objet de point de personnalisation)

Fonctions

fonctions de comparaison nommées
(fonction)

Synopsis

namespace std {
  // types de catégorie de comparaison
  class partial_ordering;
  class weak_ordering;
  class strong_ordering;
  // fonctions de comparaison nommées
  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; }
  // type de catégorie de comparaison commun
  template<class... Ts>
  struct common_comparison_category {
    using type = /* voir 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 = /* voir description */;
  template<class T, class U, class Cat = partial_ordering>
    concept three_way_comparable_with = /* voir description */;
  // résultat de la comparaison à trois voies
  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;
  // classe compare_three_way
  struct compare_three_way;
  // algorithmes de comparaison
  inline namespace /* non spécifié */ {
    inline constexpr /* non spécifié */ strong_order = /* non spécifié */;
    inline constexpr /* non spécifié */ weak_order = /* non spécifié */;
    inline constexpr /* non spécifié */ partial_order = /* non spécifié */;
    inline constexpr /* non spécifié */ compare_strong_order_fallback = /* non spécifié */;
    inline constexpr /* non spécifié */ compare_weak_order_fallback = /* non spécifié */;
    inline constexpr /* non spécifié */ compare_partial_order_fallback = /* non spécifié */;
  }
}

Concept three_way_comparable

namespace std {
  template<class T, class Cat>
    concept __ComparesAs =                // exposition uniquement
      same_as<common_comparison_category_t<T, Cat>, Cat>;
  template<class T, class U>
    concept __PartiallyOrderedWith =      // exposition uniquement
      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 } -> boolean-testable;
      };
  template<class T, class Cat = partial_ordering>
    concept three_way_comparable =
      __WeaklyEqualityComparableWith<T, T> &&
      __PartiallyOrderedWith<T, T> &&
      requires(const remove_reference_t<T>& a, const remove_reference_t<T>& b) {
        { a <=> b } -> __ComparesAs<Cat>;
      };
}

Concept three_way_comparable_with

namespace std {
  template<class T, class U, class Cat = partial_ordering>
    concept three_way_comparable_with =
      __WeaklyEqualityComparableWith<T, U> &&
      __PartiallyOrderedWith<T, U> &&
      three_way_comparable<T, Cat> &&
      three_way_comparable<U, Cat> &&
      common_reference_with<const remove_reference_t<T>&, const remove_reference_t<U>&> &&
      three_way_comparable<
        common_reference_t<
          const remove_reference_t<T>&, const remove_reference_t<U>&>, Cat> &&
      requires(const remove_reference_t<T>& t, const remove_reference_t<U>& u) {
        { t <=> u } -> __ComparesAs<Cat>;
        { u <=> t } -> __ComparesAs<Cat>;
      };
}

Classe std:: partial_ordering

namespace std {
  class partial_ordering {
    int value;          // exposition uniquement
    bool is_ordered;    // exposition uniquement
    // constructeurs d'exposition uniquement
    constexpr explicit
      partial_ordering(eq v) noexcept :
        value(int(v)), is_ordered(true) {}      // exposition uniquement
    constexpr explicit
      partial_ordering(ord v) noexcept :
        value(int(v)), is_ordered(true) {}     // exposition uniquement
    constexpr explicit
      partial_ordering(ncmp v) noexcept :
        value(int(v)), is_ordered(false) {}   // exposition uniquement
  public:
    // valeurs valides
    static const partial_ordering less;
    static const partial_ordering equivalent;
    static const partial_ordering greater;
    static const partial_ordering unordered;
    // comparaisons
    friend constexpr bool operator==(partial_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool
      operator==(partial_ordering v, partial_ordering w) noexcept = default;
    friend constexpr bool operator< (partial_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator> (partial_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator<=(partial_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator>=(partial_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator< (/* non spécifié */, partial_ordering v) noexcept;
    friend constexpr bool operator> (/* non spécifié */, partial_ordering v) noexcept;
    friend constexpr bool operator<=(/* non spécifié */, partial_ordering v) noexcept;
    friend constexpr bool operator>=(/* non spécifié */, partial_ordering v) noexcept;
    friend constexpr partial_ordering
      operator<=>(partial_ordering v, /* non spécifié */) noexcept;
    friend constexpr partial_ordering
      operator<=>(/* non spécifié */, partial_ordering v) noexcept;
  };
  // définitions des valeurs valides
  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);
}

Classe std:: weak_ordering

namespace std {
  class weak_ordering {
    int value;  // exposition uniquement
    // constructeurs d'exposition uniquement
    constexpr explicit weak_ordering(eq v) noexcept : value(int(v)) {}  // exposition uniquement
    constexpr explicit weak_ordering(ord v) noexcept : value(int(v)) {} // exposition uniquement
  public:
    // valeurs valides
    static const weak_ordering less;
    static const weak_ordering equivalent;
    static const weak_ordering greater;
    // conversions
    constexpr operator partial_ordering() const noexcept;
    // comparaisons
    friend constexpr bool operator==(weak_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator==(weak_ordering v, weak_ordering w) noexcept = default;
    friend constexpr bool operator< (weak_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator> (weak_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator<=(weak_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator>=(weak_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator< (/* non spécifié */, weak_ordering v) noexcept;
    friend constexpr bool operator> (/* non spécifié */, weak_ordering v) noexcept;
    friend constexpr bool operator<=(/* non spécifié */, weak_ordering v) noexcept;
    friend constexpr bool operator>=(/* non spécifié */, weak_ordering v) noexcept;
    friend constexpr weak_ordering
      operator<=>(weak_ordering v, /* non spécifié */) noexcept;
    friend constexpr weak_ordering
      operator<=>(/* non spécifié */, weak_ordering v) noexcept;
  };
  // définitions des valeurs valides
  inline constexpr weak_ordering weak_ordering::less(ord::less);
  inline constexpr weak_ordering weak_ordering::equivalent(eq::equivalent);
  inline constexpr weak_ordering weak_ordering::greater(ord::greater);
}

Classe std:: strong_ordering

namespace std {
  class strong_ordering {
    int value;  // exposition uniquement
    // constructeurs d'exposition uniquement
    constexpr explicit strong_ordering(eq v) noexcept :
      value(int(v)) {}    // exposition uniquement
    constexpr explicit strong_ordering(ord v) noexcept :
      value(int(v)) {}   // exposition uniquement
  public:
    // valeurs valides
    static const strong_ordering less;
    static const strong_ordering equal;
    static const strong_ordering equivalent;
    static const strong_ordering greater;
    // conversions
    constexpr operator partial_ordering() const noexcept;
    constexpr operator weak_ordering() const noexcept;
    // comparaisons
    friend constexpr bool operator==(strong_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool
      operator==(strong_ordering v, strong_ordering w) noexcept = default;
    friend constexpr bool operator< (strong_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator> (strong_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator<=(strong_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator>=(strong_ordering v, /* non spécifié */) noexcept;
    friend constexpr bool operator< (/* non spécifié */, strong_ordering v) noexcept;
    friend constexpr bool operator> (/* non spécifié */, strong_ordering v) noexcept;
    friend constexpr bool operator<=(/* non spécifié */, strong_ordering v) noexcept;
    friend constexpr bool operator>=(/* non spécifié */, strong_ordering v) noexcept;
    friend constexpr strong_ordering
      operator<=>(strong_ordering v, /* non spécifié */) noexcept;
    friend constexpr strong_ordering
    operator<=>(/* non spécifié */, strong_ordering v) noexcept;
  };
  // définitions des valeurs valides
  inline constexpr strong_ordering strong_ordering::less(ord::less);
  inline constexpr strong_ordering strong_ordering::equal(eq::equal);
  inline constexpr strong_ordering strong_ordering::equivalent(eq::equivalent);
  inline constexpr strong_ordering strong_ordering::greater(ord::greater);
}

Classe std:: compare_three_way

namespace std {
  struct compare_three_way {
    template<class T, class U>
    constexpr auto operator()(T&& t, U&& u) const;
    using is_transparent = /* non spécifié */;
  };
}

Voir aussi

opérateur de comparaison à trois voies expression lhs <=> rhs (C++20)