名前空間
変種
操作

std::compare_three_way_result

提供: cppreference.com
< cpp‎ | utility
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ(C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
ヘッダ <compare> で定義
template<class T, class U = T>
struct compare_three_way_result;
(C++20以上)

tu がそれぞれ conststd::remove_reference_t<T>conststd::remove_reference_t<U> の左辺値を表すとき、式 t <=> u が well-formed であれば、 decltype(t <=> u) に等しいメンバ型 type を提供します。 そうでなければ、メンバ type は存在しません。

このテンプレートを特殊化する試みは未定義動作です。

目次

[編集]メンバ型

名前 定義
typeTU の const 修飾された左辺値に対する operator<=> の結果の型

[編集]ヘルパー型

template<class T, class U = T>
using compare_three_way_result_t =typename compare_three_way_result<T>::type;
(C++20以上)

[編集]実装例

template<class T, class U = T>struct compare_three_way_result {};   template<class T, class U> requires requires(conststd::remove_reference_t<T>& t, conststd::remove_reference_t<U>& u){ t <=> u;}struct compare_three_way_result<T, U>{using type = decltype(std::declval<conststd::remove_reference_t<T>&>()<=>std::declval<conststd::remove_reference_t<U>&>());};

[編集]

#include <compare>#include <type_traits>#include <iostream>   template<class Ord>void print_cmp_type(){ifconstexpr(std::is_same_v<Ord, std::strong_ordering>)std::cout<<"strong ordering\n";elseifconstexpr(std::is_same_v<Ord, std::weak_ordering>)std::cout<<"weak ordering\n";elseifconstexpr(std::is_same_v<Ord, std::partial_ordering>)std::cout<<"partial ordering\n";elseifconstexpr(std::is_same_v<Ord, std::strong_equality>)std::cout<<"strong equality\n";elseifconstexpr(std::is_same_v<Ord, std::weak_equality>)std::cout<<"weak equality\n";elsestd::cout<<"illegal comparison result type\n";}   int main(){ print_cmp_type<std::compare_three_way_result_t<int>>(); print_cmp_type<std::compare_three_way_result_t<double>>(); print_cmp_type<std::compare_three_way_result_t<int(*)()>>();}

出力:

strong ordering partial ordering strong equality

[編集]関連項目

等しい、等しくないのみサポートする代用可能でない三方比較の結果の型
(クラス)[edit]
等しい、等しくないのみサポートする代用可能な三方比較の結果の型
(クラス)[edit]
6種類の演算子をすべてサポートし、代用可能でなく、比較不可能な値を許容する、三方比較の結果の型
(クラス)[edit]
6種類の演算子をすべてサポートする代用可能でない三方比較の結果の型
(クラス)[edit]
6種類の演算子をすべてサポートする代用可能な三方比較の結果の型
(クラス)[edit]
close