首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::conditional

Defined in header <type_traits>

template< bool B, class T, class F > struct conditional;

(since C++11)

提供成员类型type,它被定义为T如果Btrue在编译时,或F如果Bfalse...

成员类型

Member type

Definition

type

T if B == true, F if B == false

帮助者类型

template< bool B, class T, class F > using conditional_t = typename conditional<B,T,F>::type;

(since C++14)

可能的实施

模板<bool B,类T,类F>结构条件{ty胡枝子T型;};模板<类T,类F>结构条件<false,T,F>{ty胡枝子F型;};

*。

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
i
d
d

二次

另见

enable_if (C++11)

hides a function overload or template specialization based on compile-time boolean (class template)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券