您的位置:首页 > 编程语言 > C语言/C++

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  type-trait c++