小编Fel*_*oni的帖子

为什么clang拒绝variadic模板的朋友功能

我有以下示例代码,简化为必需的,编译与gcc 6.1,gcc 7.0 head和Visual Studio 2015/2017RC,但没有任何clang版本.

#include <iostream>
#include <tuple>

using namespace std;

namespace outer {
  namespace test {

    template <typename A, typename B, typename...C>
    auto bar_(A&&, B&&, C&&... c) {
      return std::make_tuple(c._p...);
    }

  }

  template <typename A, typename B, typename...C>
  auto bar(A a, B b, C&&... c) {
    return test::bar_(std::move(a), std::move(b), std::forward<C>(c)...);
  }

  template<typename T>
  class foo
  {
    template <typename A, typename B, typename...C>
    friend auto test::bar_(A&&, B&&, C&&... c);

    int _p;
  public:
    foo(int f) : _p(f) {}
  }; …
Run Code Online (Sandbox Code Playgroud)

c++ templates variadic-templates clang++ c++14

12
推荐指数
1
解决办法
301
查看次数

如何在可变参数上下文中使用抽象类时实现抽象方法

如何在下面的代码中实现一般情况下的抽象基类.代码从我正在处理的库中简化.因此,int和double的显式实现不是一个选项.

template <typename T>
struct Foo
{
  virtual void send(T t) = 0;
};

template <typename...T>
struct Bar : Foo<T>...
{
  void send(T t) override { // does not compile because 
                            // abstract method not implemented
  }
};

int main() {
  // example usage
  Bar<int, double> b;

  b.send(1);
  b.send(2.3);
}
Run Code Online (Sandbox Code Playgroud)

提前谢谢了.

编辑:添加虚拟到抽象方法.

c++ templates pure-virtual variadic-templates c++11

11
推荐指数
1
解决办法
438
查看次数

如何迭代boost :: fusion关联结构并以通用方式访问键

这是我对这个伟大的知识交流的第一个问题,我希望我能找到一些帮助.

我尝试实现创建PrintTo函数的通用方法(稍后将在GoogleTest中使用).

所以下面的代码只完成了一半的工作.它只打印定义的结构的值Foo::Bar

#include <iostream>
#include <sstream>
#include <string>

#include <boost/fusion/container.hpp>
#include <boost/fusion/algorithm.hpp>
#include <boost/fusion/adapted/struct/define_assoc_struct.hpp>
#include <boost/fusion/include/define_assoc_struct.hpp>

namespace Foo
{
  namespace Keys
  {
    struct StringField;
    struct IntField;
  };
}

BOOST_FUSION_DEFINE_ASSOC_STRUCT(
  (Foo), Bar,
  (std::string, stringField, Foo::Keys::StringField)
  (int,         intField,    Foo::Keys::IntField))


struct fusion_printer_impl
{
  std::ostream& _os;

  fusion_printer_impl(std::ostream& os) 
    : _os(os) {}

  template <typename T>
  void operator() (T& v) const
  {
    _os << v << std::endl;
  }
};

void PrintTo(Foo::Bar const& v, std::ostream* os)
{
  boost::fusion::for_each(v, fusion_printer_impl(*os));
}

int main()
{
  Foo::Bar fb("Don't …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-fusion

8
推荐指数
1
解决办法
828
查看次数

Windows std :: thread是否在内部使用PPL?

是否在内部基于PPL的任务系统实现Visual Studio 2015的std :: thread?

我的问题的背景是,将std :: thread用于多个任务是否有意义,因为它们已经在公共线程池上执行了平衡,或者通过PPL任务执行任务更好?

根据(哪个std :: async实现使用线程池?)这似乎是,但由于问题相当陈旧,我想得到一个"官方"答案.

c++ multithreading c++11 ppl

4
推荐指数
2
解决办法
1010
查看次数