C++17 有带初始化器的选择语句
status_code foo() {
if (status_code c = bar(); c != SUCCESS) {
return c;
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
我想写一个while-loop 和一个范围仅限于循环的变量,并且在第一次迭代之前只初始化一次。
// fake example, doesn't compile, is doable in many ways
while (bool keep_trying = foo(); keep_trying) {
// do stuff
if (something)
keep_trying = false;
}
Run Code Online (Sandbox Code Playgroud)
在 C++17 或 C++2a 中有什么可以解决的吗?