zoukankan      html  css  js  c++  java
  • 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>>

  • 相关阅读:
    [转]CentOS 修改yum源为国内源
    著名的镜像网站
    [译]LRTHW练习五——更多的变量及输出打印
    CentOS足迹一
    LRTHW笔记二
    线程的创建和运行(未完待续)
    比较当前时间和给定时间大小
    单独管理image
    Java 修改页面排序条件
    Java 如何使用radio button保存值
  • 原文地址:https://www.cnblogs.com/LearningTheLoad/p/7266405.html
Copyright © 2011-2022 走看看