X Tutup
The Wayback Machine - https://web.archive.org/web/20180425102127/http://ja.cppreference.com:80/w/cpp/types/conditional
名前空間
変種
操作

std::conditional

提供: cppreference.com
< cpp‎ | types

 
 
 
型サポート
型プロトタイプ
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)(deprecated in C++17)
(C++11)(deprecated in C++20)
(C++11)
型特性定数
メタ関数
(C++17)
エンディアン
(C++20)
サポートされている操作
関係と性質の問い合わせ
(C++11)
(C++11)
(C++11)
(C++11)
型変更
(C++11)(C++11)(C++11)
型変換
(C++11)
(C++11)
(C++17)
conditional
(C++11)
(C++11)(deprecated in C++17)(C++17)
 
ヘッダ <type_traits> で定義
template< bool B, class T, class F >
struct conditional;
(C++11およびそれ以降)
typeとして定義されているメンバのtypedefTを提供する場合、Btrueコンパイル時、またはFですB場合falseようです.
Original:
Provides member typedef type, which is defined as T if B is true at compile time, or as F if B is false.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] メンバータイプ

メンバー·タイプ
Original:
Member type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Definition
type T if B == true, F if B == false

[編集] 可能な実装

template<bool B, class T, class F>
struct conditional { typedef T type; };
 
template<class T, class F>
struct conditional<false, T, F> { typedef F type; };

[編集]

#include <iostream>
#include <type_traits>
#include <typeinfo>
 
int main() 
{
    typedef std::conditional<true, int, double>::type Type1;
    typedef std::conditional<false, int, double>::type Type2;
    typedef std::conditional<sizeof(int) >= sizeof(double), int, double>::type Type3;
 
    std::cout << typeid(Type1).name() << '\n';
    std::cout << typeid(Type2).name() << '\n';
    std::cout << typeid(Type3).name() << '\n';
}

出力:

i
d
d

[編集] 参照

(C++11)
コンパイル時ブーリアンに基づいて関数オーバーロードまたはテンプレート特殊化を隠蔽します
(クラステンプレート) [edit]
X Tutup