Variadic嵌套模板类型作为参数

时间:2016-03-10 21:47:25

标签: c++ c++11 parameters variadic-templates

我想要一个可变参数模板类的模板类型的函数参数。以下代码如何格式良好?

template <typename T>
struct Foo {
  typedef T Base;
};

template <typename... Targs>
struct Bar {
  void get(Targs::Base... args) {} /// Type of the typedef Base of Foo!
};

int main() {
  Bar<Foo<int>, Foo<double>> bar;

  int i = 0;
  double j = 0.0;
  bar.get(i, j);
}

使用GCC 4.9 C ++ 11或5.3。

1 个答案:

答案 0 :(得分:2)

易。观看我的typename

template <typename... Targs>
struct Bar {
  void get(typename Targs::Base... args) {} /// Type of the typedef Base of Foo!
};
相关问题