最終更新日時(UTC):
が更新

履歴 編集

concept
<exposition-only>

comparison-common-type-with(C++20)

namespace std {
  template<class T, class U, class C = common_reference_t<const T&, const U&>>
  concept comparison-common-type-with-impl =
    same_as<common_reference_t<const T&, const U&>,
            common_reference_t<const U&, const T&>> &&
    requires {
      requires convertible_to<const T&, const C&> ||
               convertible_to<T, const C&>;
      requires convertible_to<const U&, const C&> ||
               convertible_to<U, const C&>;
    };

  template<class T, class U>
  concept comparison-common-type-with =
    comparison-common-type-with-impl<remove_cvref_t<T>, remove_cvref_t<U>>;
}

概要

comparison-common-type-withは、2つの型TUがムーブオンリー型であっても共通の上位型(common supertype)を持つことを判定するための説明専用コンセプトである。

common_reference_withと似ているが、const T&からの変換だけでなくT(右辺値)からの変換も許可する点が異なる。これにより、コピーができずムーブのみ可能な型であっても、比較コンセプト(equality_comparable_with, totally_ordered_with, three_way_comparable_with)を満たすことが可能になる。

備考

  • このコンセプトはC++23で導入されたが、C++20への欠陥報告(DR)として扱われる

バージョン

言語

  • C++20(C++23で追加、C++20にDR適用)

参照