8000 Mention C++17's init-statement in the `Limit Variable Scope` section · AthenaVision/cppbestpractices@187c033 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 187c033

Browse files
committed
Mention C++17's init-statement in the Limit Variable Scope section
1 parent c644a3b commit 187c033

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

08-Considering_Performance.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ for (int i = 0; i < 15; ++i)
273273
// obj is still taking up memory for no reason
274274
```
275275

276+
For C++17 and onwards, consider using init-statement in the `if` and `switch` statements:
277+
278+
```cpp
279+
if (MyObject obj(index); obj.good()) {
280+
// do something if obj is good
281+
} else {
282+
// do something if obj is not good
283+
}
284+
```
285+
276286
[This topic has an associated discussion thread](https://github.com/lefticus/cppbestpractices/issues/52).
277287
278288
### Prefer `double` to `float`, But Test First

0 commit comments

Comments
 (0)
0