c++11 常用判断类型的traits

template<class T>

struct is_void;   T是否为void类型

template<class T>

struct is_enum;   T是否为枚举类型

template<class T>

struct is_union;   T是否为union类型

template<class T>

struct is_class;   T是否为class/struct类型而不是union类型

template<class T>

struct is_function;   T是否为函数类型

template<class T>

struct is_reference;   T是否为引用类型

template<class T>

struct is_arithmetic;   T是否为整型、浮点类型

template<class T>

struct is_fundamental;   T是否为整型、浮点、void或nullptr_t类型

template<class T>

struct is_object;   T是否为一个对象类型(不是函数、不是引用、不是void)

template<class T>

struct is_scalar;   T是否为arithmetic、enumeration、pointer、pointer to member或nullptr_t类型

template<class T>

struct is_compound;   T是否非fundamental类型构造的

template<class T>

struct is_member_pointer;   T是否为成员函数指针类型

template<class T>

struct is_polymorphic;   T是否有虚函数

template<class T>

struct is_abstract;   T是否为抽象类

template<class T>

struct is_signed;   T是否是有符号类型

template<class T>

struct is_unsigned;   T是否是无符号类型

template<class T>

struct is_const;   T是否为const修饰的类型

使用如下:

    cout << is_const<const int*>::value << endl;            //0
    cout << is_const<int* const>::value << endl;            //1

 

template<class T, class U>

struct is_same;   判断两个类型是否相同

template<class Base, class Derived>

struct is_base_of;   判断Base类型是否为Derived类型的基类

template<class Form, class To>

struct is_convertible;   判断前面的模板参数类型能否转换为后面的模板参数类型

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值