Skip to content

Latest commit

 

History

History
45 lines (39 loc) · 1.5 KB

synth-three-way-result.md

File metadata and controls

45 lines (39 loc) · 1.5 KB

synth-three-way-result

  • exposition-only[meta header]
  • function[meta id-type]
  • cpp20[meta cpp]
constexpr auto synth-three-way =                           // (1) C++20
  []<class T, class U>(const T& t, const U& u)
    requires requires {
      { t < u } -> boolean-testable ;
      { u < t } -> boolean-testable ;
    }
  {
    if constexpr (three_way_comparable_with<T, U>) {
      return t <=> u;
    } else {
      if (t < u) return weak_ordering::less;
      if (u < t) return weak_ordering::greater;
      return weak_ordering::equivalent;
   }
};

template <class T, class U=T>
using synth-three-way-result =
  decltype(synth-three-way(declval<T&>(), declval<U&>())); // (2) C++20
  • synth-three-way-result[italic]
  • synth-three-way[italic]
  • boolean-testable[link /reference/concepts/boolean-testable.md]
  • three_way_comparable_with[link /reference/compare/three_way_comparable.md]
  • weak_ordering[link /reference/compare/weak_ordering.md]
  • declval[link /reference/utility/declval.md]

概要

  • (1) : 型Tと型Uが三方比較可能であればそれを行い、そうでなければweak_orderingとして三方比較を実装して関数オブジェクト
  • (2) : synth-three-way-resultでの比較結果の型

バージョン

言語

  • C++20

参照