c++ type trait 之 类型判断工具

//type trait 之类型判断工具
#include <iostream>
#include <array>
using namespace std;

enum class color
{
    red,green,blue
};

auto f = []()
{
    cout << "I'm lambda" << endl;
};

union A
{
    int a;
    float b;
    string c;
};
class B
{
public:
    int b;
    void f() {}
};
int main()
{
    //is void?
    cout << boolalpha << is_void<void>::value << endl;
    //整数类型包括(bool char int char16_t char32_t wchar_t)?
    cout << boolalpha << is_integral<int>::value << endl;
    //浮点数(float double long double)?
    cout << boolalpha << is_floating_point<int>::value << endl;
    //算术类型(包括整数和浮点数)?arithmetic
    cout << boolalpha << is_arithmetic<string>::value << endl;
    //带正负号的arithmetic type
    cout << boolalpha << is_signed<string>::value << endl;
    //不带正负号的arithmetic type
    cout << boolalpha << is_unsigned<int>::value << endl;
    //对象是否带有const限定符
    cout << boolalpha << is_const<const int*>::value << endl;
    //对象是否带有volatile限定符
    cout << boolalpha << is_volatile<volatile int * volatile>::value << endl;
    //row array ?
    cout << boolalpha << is_array<array<int,5>>::value << endl;
    // enum ?
    cout << boolalpha << is_enum<color>::value << endl;
    // union ?
    cout << boolalpha << is_union<A>::value << endl;
    // class(class or struct but nou union) ?
    cout << boolalpha << is_class<A>::value << endl;
    //function type?
    cout << boolalpha << is_function<decltype(f)()>::value << endl;
    // reference ?
    cout << boolalpha << is_reference<int&&>::value << endl;
    // left reference ?
    cout << boolalpha << is_lvalue_reference<int&&>::value << endl;
    // right reference ?
    cout << boolalpha << is_rvalue_reference<int&&>::value << endl;
    // row pointer ?
    cout << is_pointer<int*>::value << endl;
    //pointer to nonstatic 成员 ?
    cout << is_member_pointer<decltype(&B::f)>::value << endl;
    //pointer to nonstatic 数据成员
    cout << is_member_object_pointer<decltype(&B::f)>::value << endl;
    //pointer to nonstatic 成员函数
    cout << is_member_function_pointer<decltype(&B::f)>::value << endl;
    //包括(整型,void,浮点型,std::nullptr_t)
    cout << is_fundamental<string>::value << endl;
    //整型 浮点数 枚举(enumeration) pointer,member pointer,std::nullptr_t
    cout << is_scalar<int>::value << endl;
    //任何类型除void reference pointer function array enumeration union 
    //class 
    cout << is_object<string>::value << endl;
    system("pause");
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值