在包扩展模式中调用函数模板

时间:2016-09-07 16:57:56

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

让我们保持简短。为什么以下代码编译成功...

#define RUN_FORALL(pattern) (int[]){0, ((pattern), void(), 0)...}
template <typename ...Attributes>
class Foo : public Attributes... {
  template <typename T>
  void bar(T o) { RUN_FORALL(Attributes::value = o.getValue()); }
};
int main() {}

...以下代码没有?

#define RUN_FORALL(pattern) (int[]){0, ((pattern), void(), 0)...}
template <typename ...Attributes>
class Foo : public Attributes... {
  template <typename T>
  void bar(T o) { RUN_FORALL(Attributes::value = o.getValue<Attributes>()); }
};
int main() {}

错误:

1:30: error: expected primary-expression before 'int'
5:19: note: in expansion of macro 'RUN_FORALL'

如何在包扩展模式中调用功能模板?

0 个答案:

没有答案