C++11_Type Traits

版权声明:本文为博主原创文章,未经博主允许不得转载。

识别变量的type id,返回true或false,举一个简单使用的例子

template <typename T>
void type_traits_output(const T& x)
{
    cout << "\ntype traits for type : " << typeid(T).name() << endl;
    
    cout << "is_void\t" << is_void<T>::value << endl;
    cout << "is_integral\t" << is_integral<T>::value << endl;
    cout << "is_floating_point\t" << is_floating_point<T>::value << endl;
    cout << "is_arithmetic\t" << is_arithmetic<T>::value << endl;
    cout << "is_signed\t" << is_signed<T>::value << endl;
    cout << "is_unsigned\t" << is_unsigned<T>::value << endl;
    cout << "is_const\t" << is_const<T>::value << endl;
    cout << "is_volatile\t" << is_volatile<T>::value << endl;
    cout << "is_class\t" << is_class<T>::value << endl;
    cout << "is_function\t" << is_function<T>::value << endl;
    cout << "is_reference\t" << is_reference<T>::value << endl;
}

int main(int argc, const char * argv[]) {

    int a = 5;
    type_traits_output<int>(a);
    return 0;
}

  输出结果

 


 

具体操作也不做太多解释了,很好理解.更多的Type Traits见

http://www.cplusplus.com/reference/type_traits/

以下是Type Traits的截图

 

 




 希望会对大家有所帮助

如有不正确的地方请指正

参照<<侯捷 C++新标准 C++11>>

 

posted @ 2017-08-01 00:24  WangZijian  阅读(374)  评论(0编辑  收藏  举报