【发布时间】:2020-02-21 05:58:41
【问题描述】:
以下 sn-p 将在 GCC 8+ 中编译,但在 GCC 7 中编译失败。
template <typename... THINGS>
struct A
{
explicit A(THINGS *... things)
{
(..., [thing = things](){}());
}
};
int main()
{
int thing;
const auto thingy = A{&thing};
}
声明的失败是参数包没有被扩展:parameter packs not expanded with '...'。
检查GCC standards compliance page,GCC 7 应该支持折叠表达式。
除了std=c++17,我还需要另一个标志吗? (我没看到)
标准还没有完全执行吗? (我没有看到任何迹象)
我可以完成这项工作吗,或者这只是我必须解决的 GCC 7 错误?
【问题讨论】:
-
FWIW 你应该可以使用数组技巧:
int discard[] = {([thing = things](){}(), 0)...}; -
@NathanOliver 但是由于相同的 GCC 错误,这给出了相同的错误?
-
@uneven_mark 哦。我认为问题在于折叠表达式本身,而不是 lambda 捕获破坏了表达式。现在我已经实际阅读了这个错误,我发现它确实不起作用。