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

  • 相关阅读:
    键盘弹出与隐藏对TextView的影响
    iOS9 警告框
    计时器的写法
    iOS提交被拒
    新生活
    批量删除wps文档里的回车符的方法!WPS使用技巧分享!
    学习笔记计划
    监控服务器的注册及登陆并邮件通知的代码(go / python)
    Python调用C代码
    导入用户到Discuz论坛
  • 原文地址:https://www.cnblogs.com/LearningTheLoad/p/7266405.html
Copyright © 2011-2022 走看看