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>>

  • 相关阅读:
    素数回文 ---- 有点暴力.....
    Manacher算法 , 实例 详解 . NYOJ 最长回文
    大数处理 详解 模版
    River Crossing 简单的动态规划 .
    hdu
    产生冠军 map 的 应用 .
    MySQL的数据库备份与恢复。
    rsync的相关使用,参数设置。
    centos与mac安装python虚拟环境 virtualenvwrapper
    CentOS7安装Python3.7
  • 原文地址:https://www.cnblogs.com/LearningTheLoad/p/7266405.html
Copyright © 2011-2022 走看看