C++11_Type Traits

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

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

template <typename T>
void type_traits_output(const T& x)
{
    cout << "
type traits for type : " << typeid(T).name() << endl;
    
    cout << "is_void	" << is_void<T>::value << endl;
    cout << "is_integral	" << is_integral<T>::value << endl;
    cout << "is_floating_point	" << is_floating_point<T>::value << endl;
    cout << "is_arithmetic	" << is_arithmetic<T>::value << endl;
    cout << "is_signed	" << is_signed<T>::value << endl;
    cout << "is_unsigned	" << is_unsigned<T>::value << endl;
    cout << "is_const	" << is_const<T>::value << endl;
    cout << "is_volatile	" << is_volatile<T>::value << endl;
    cout << "is_class	" << is_class<T>::value << endl;
    cout << "is_function	" << is_function<T>::value << endl;
    cout << "is_reference	" << 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>>

原文地址:https://www.cnblogs.com/LearningTheLoad/p/7266405.html