c++ type trait 之 检验类型关系(Type Relation)

来源:互联网 发布:java里面微积分怎么用 编辑:程序博客网 时间:2024/06/05 08:34
#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;}
原创粉丝点击