美文网首页
seastar中std::enable_if使用

seastar中std::enable_if使用

作者: dnsir | 来源:发表于2019-06-15 10:53 被阅读0次

seastarshard.hh有这么一段代码。

    template <typename T>
    std::enable_if_t<std::is_base_of<peering_sharded_service<T>, T>::value>
    set_container(T& service) {
        service.set_container(this);
    }

    template <typename T>
    std::enable_if_t<!std::is_base_of<peering_sharded_service<T>, T>::value>
    set_container(T& service) {
    }

里面使用到C++11里的两个新特性:std::enable_ifstd::is_base_of

1 std::enable_if

查看c++的type_traits 源码,std::enable_if的实现如下:

// Primary template.
  /// Define a member typedef @c type only if a boolean constant is true.
  template<bool, typename _Tp = void>
    struct enable_if 
    { };

  // Partial specialization for true. 模板特化
  template<typename _Tp>
    struct enable_if<true, _Tp>
    { typedef _Tp type; };

相关文章

  • seastar中std::enable_if使用

    在seastar的shard.hh有这么一段代码。 里面使用到C++11里的两个新特性:std::enable_i...

  • C++模版笔记(2)

    本篇介绍 本篇继续C++的模版介绍 std::enable_if<> enable_if<> 的作用是满足条件后可...

  • c++ 11: enable_if

    最近在看ceph rgw的源码, 在其客户端数据处理部分遇到std::enable_if的概念,如下: enabl...

  • C++多线程std::thread

    std::thread 在 头文件中声明,因此使用 std::thread 时需要包含 头文件。 std:...

  • 转载--std::ref应用

    在std::promise范例中,使用了std::ref将future对象传递给引用参数类型的任务函数。 std:...

  • 再说智能指针

    一 STL的智能指针及使用 STL中智能指针有std::shared_ptr std::weak_ptr std:...

  • C++

    1.using namespace std; 告诉编译器使用 std 命名空间。 2.C++ 关键字 C++ 中的...

  • C++11为什么需要std::ref/reference_wra

    在std::promise范例中,使用了std::ref将future对象传递给引用参数类型的任务函数。 如果直接...

  • C++基础知识

    std是指名称空间,using namespace std; 是指使用名称空间std 位的取值为0,1 使用aut...

  • Windows常用的宏定义

    NOMINMAX Windows的头文件中包含了min和max的宏定义,所以在使用std::min和std::ma...

网友评论

      本文标题:seastar中std::enable_if使用

      本文链接:https://www.haomeiwen.com/subject/lvwgxqtx.html