c++ type trait 之 检验类型关系(Type Relation)
2017-05-17 22:29
507 查看
#include <iostream> using namespace std; int main() { cout << boolalpha; // is_same<T1,T2> T1和T2类型是否相同(包括const volatile修饰符) cout << is_same<const int&, int>::value << endl; // is_base_of<T,D> T是否是D的基类 cout << is_base_of<char, string>::value << endl; // is_convertible<T,D> T能否装换成D cout << is_convertible<double, int>::value << endl; // is_constructible<T,..Args> 能否用Args...初始化T cout << is_constructible<string, char, double>::value << endl; // is_trivially_constructible<T,...Args> 能用Args...平凡(隐式)初始化T cout << is_trivially_constructible<string, char, double>::value << endl; // is_nothrow_constructible<T,..Args> 能否用Args...初始化T且不抛出异常 cout << is_nothrow_constructible<string, char, double>::value << endl; // is_assignable<T,D> 类型T能否被类型D赋值 cout << is_assignable<double, int>::value << endl; // is_trivially_assignable<T,D> 类型T能被类型D平凡赋值 cout << is_trivially_assignable<double, int>::value << endl; // is_nothrow_assignable<T,D> 类型T能被类型D赋值且不抛出异常 cout << is_nothrow_assignable<double,int>::value; //uses_allocator<T,Alloc> Alloc可被转换T::allocator_type system("pause"); return 0; }
相关文章推荐
- c++ type trait 之 类型修饰符(Type Modifier)改动类型
- 常见数据类型Microsoft Access 和OleDbType对应关系
- C++数据类型与C#对应关系 c#调用WINDWOS API时,非常有用
- C++重载类型转换操作符(type cast operator
- C++模板中type_traits(类型特化)
- C++ 与 C#数据结构类型对应关系表 (转)
- C/C++中数组和指针类型的关系
- [Android] Jni中C++和Java的数据类型的对应关系
- C++ 与 C#数据结构类型对应关系表
- NHibernate VS .NET Type VS DbType 的类型映射关系
- 深入理解 C++ 指针(六)---指针和结构类型的关系
- C++与C#的数据类型对应关系表
- C++ 与 C#数据结构类型对应关系表
- EnableViewState and Button Type(DataGrid中按钮类型与EnableViewState的关系)
- c++ template笔记(3)非类型模板参数nontype template parameters
- SQL与C++的数据类型对应关系(网上资料搜集整理)
- c++模拟MFC中运行时类型识别(RTTI)(Run-Time Type Identification)
- C++类型转换运算符(Type Conversion Operators)
- C++数据类型与C#对应关系 c#调用WINDWOS API时,非常有用
- C++数据类型与C#对应关系 c#调用WINDWOS API时,非常有用(转)