Tae*_*ahn 4 c++ gcc c++17 gcc7
以下代码段将在GCC 8+中进行编译,但无法在GCC 7中进行编译。
template <typename... THINGS>
struct A
{
explicit A(THINGS *... things)
{
(..., [thing = things](){}());
}
};
int main()
{
int thing;
const auto thingy = A{&thing};
}
Run Code Online (Sandbox Code Playgroud)
声明的失败是未扩展参数包:parameter packs not expanded with '...'。
检查GCC标准符合性页面,GCC 7中应支持折叠表达式。
我还需要别的标志std=c++17吗?(我没有看到)
标准是否尚未完全实施?(我什么都没有看到,
这表明我可以做这个工作,还是这只是我要解决的GCC 7错误?
这是GCC错误,最初是在8.01版中报告的,已在8.2版中修复。似乎在不使用折叠表达式时也会发生该错误(NathanOliver提到的C ++ 11年代的“扩展器技巧”也不起作用),因此您必须使用更长的解决方法需要扩展lambda捕获内的模板参数包。例如:
template <typename THING>
void do_it(THING* thing) {
[thing]{}();
}
explicit A(THINGS *... things)
{
(..., do_it(things));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |