【发布时间】:2016-11-22 22:10:44
【问题描述】:
考虑如下代码sn-p:
template <typename TF>
void post(TF){ }
template <typename... TFs>
struct funcs : TFs...
{
funcs(TFs... fs) : TFs{fs}... { }
void call()
{
(post([&]{ static_cast<TFs&>(*this)(); }), ...);
}
};
clang++ 3.8+ successfully compiles the code.
g++ 7.0 fails to compile 出现以下错误:
prog.cc: In lambda function:
prog.cc:10:43: error: parameter packs not expanded with '...':
(post([&]{ static_cast<TFs&>(*this)(); }), ...);
~~~~~~~~~~~~~~~~~~~~~~~~^~
prog.cc:10:43: note: 'TFs'
prog.cc: In member function 'void funcs<TFs>::call()':
prog.cc:10:13: error: operand of fold expression has no unexpanded parameter packs
(post([&]{ static_cast<TFs&>(*this)(); }), ...);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
删除 post 调用和 lambda makes g++ compile the fold expression。
lambda、折叠表达式和模板函数调用之间的这种交互是否被标准以某种方式禁止,或者这是一个 gcc 错误?
【问题讨论】:
-
GCC 有 long-standing issues 与打包扩展整个 lambda。不完全是新的。
-
我会选择 3 号门,Monty:尚未完全实施。
标签: c++ lambda language-lawyer c++17 fold-expression