zoukankan      html  css  js  c++  java
  • c++11之类型萃取type_traits

    • 不知道怎么评价这个特性。。。
    • 代码
        1. #include<iostream>
        2. #include<type_traits>
        3. //继承integral_constant可以方便写静态变量
        4. structGetSize: std::integral_constant<int,1>
        5. {
        6. };
        7. template<class T,T v>
        8. struct integral_my
        9. {
        10. staticconst T value = v;
        11. typedef T value_type;
        12. typedef integral_my<T, v>type;
        13. operator value_type(){return value;};//重载类型转换符
        14. };
        15. class A {};
        16. class B :A {};
        17. class C {};
        18. int main()
        19. {
        20. int a =GetSize::value;
        21. typedefint(*func)();
        22. //类型判断
        23. std::cout << std::is_function<int>::value << std::endl;
        24. std::cout << std::is_function<func>::value << std::endl;
        25. std::cout << std::is_const<constint&>::value << std::endl;
        26. std::cout << std::is_const<constint>::value << std::endl;
        27. std::cout << std::endl;
        28. //类型是否相同
        29. std::cout << std::is_same<int,float>::value << std::endl;
        30. std::cout << std::is_same<int,signedint>::value << std::endl;
        31. std::cout << std::endl;
        32. //判断是否未基类
        33. std::cout << std::is_base_of<B, A>::value << std::endl;
        34. std::cout << std::is_base_of<A, B>::value << std::endl;
        35. std::cout << std::is_base_of<C, A>::value << std::endl;
        36. std::cout << std::endl;
        37. bool b = std::is_base_of<C, A>::value;
        38. std::cout << std::boolalpha;
        39. std::cout << b << std::endl;
        40. return0;
        41. }
         





  • 相关阅读:
    shell 环境变量
    websphere 进程
    shell 安装使用VIM
    shell seq 用法
    shell 变量自增
    WebService学习笔记系列(二)
    WebService学习笔记系列(一)
    类加载器及其委托机制的深入分析
    Java工具类:给程序增加版权信息
    QQ互联API接口失效,第三方网站的死穴
  • 原文地址:https://www.cnblogs.com/dongdongweiwu/p/4743658.html
Copyright © 2011-2022 走看看