c++ type trait 之 类型判断工具
来源:互联网 发布:普鲁申科 亚古丁 知乎 编辑:程序博客网 时间:2024/06/06 03:15
//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;}
阅读全文
0 0
- c++ type trait 之 类型判断工具
- c++ type trait 之 检验类型关系(Type Relation)
- c++ type trait 之 class trait
- c++ type trait 之 useful trait
- c++ type trait 之 类型修饰符(Type Modifier)改动类型
- 九、 通用工具 ----Type Trait 和 Type Utility
- jquery源码之属性判断-$.type类型
- type trait用于平行类层次中的参数类型检查
- Trait和类型转换
- trait中的属性类型
- C++--类型转换(Type Casting)
- 关于用 type()判断字段类型
- jquery $.type来实现类型判断
- Python类型判断type与isinstance
- Python isinstance 和 type,类型判断
- 类型判断type与isinstance的区别
- Logstash type来标记事件类型,通过type判断
- php手册之Trait
- 进程、线程、服务和任务的区别
- libRTMP使用说明
- 腾讯云入门使用(一) CentOS购买、登录及域名绑定IP
- hessian入门,spring集成
- 指针数组和数组指针
- c++ type trait 之 类型判断工具
- 企业人事管理系统
- 数据结构——图的遍历和存储
- Jquery用法
- C++中的RTTI(runtime type information) 机制
- Matlab自适应滤波器设计Demo——LMS,RLS
- 04-树4 是否同一棵二叉搜索树 (25分)
- windows 下 Redis 主从 读写分离
- Entity Framework- Databinding with WinForms