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





  • 相关阅读:
    初学java-基础
    初学java-基础
    HYPER-V 实现管理器远程管理虚拟机
    zeromq rpc原型
    haproxy+keepalived
    [转]序列化悍将Protobuf-Net,入门动手实录
    RabbitMQ的几种应用场景
    redis数据类型及使用场景
    [转]DDD领域驱动设计基本理论知识总结
    Centos 下编译安装Redis
  • 原文地址:https://www.cnblogs.com/dongdongweiwu/p/4743658.html
Copyright © 2011-2022 走看看