[英]fold expression in assignment
I am trying to use a fold expression to simplify some code. 我正在尝试使用折叠表达式来简化一些代码。 In following code, I am trying to insert elements into an array, but the fold expression does not compile 在下面的代码中,我试图将元素插入到数组中,但是fold表达式无法编译
struct test {
std::string cmd[20];
test() {
int i = 0;
auto insert = [&](auto... c) {
assert(i < 20);
(cmd[i++] = c), ...;
};
insert("c");
insert("c", "c2");
}
};
compilers complains about missing ';' 编译器抱怨缺少';'
Fold expressions have to be parenthesized. 折叠表达式必须加括号。 Hence: 因此:
((cmd[i++] = c), ...);
The inner parentheses are necessary as well. 内括号也是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.