相关疑难解决方法(0)

带有初始值设定项的 while 语句

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 中有什么可以解决的吗?

c++ scope initialization c++17

9
推荐指数
2
解决办法
3429
查看次数

标签 统计

c++ ×1

c++17 ×1

initialization ×1

scope ×1