8000 Merge pull request #100 from RostakaGmfun/cpp17-init-statements · ankuPRK/cppbestpractices@eabdc04 · GitHub
[go: up one dir, main page]

Skip to content

Commit eabdc04

Browse files
authored
Merge pull request cpp-best-practices#100 from RostakaGmfun/cpp17-init-statements
Mention C++17's init-statement in the `Limit Variable Scope` section
2 parents d04a773 + 187c033 commit eabdc04

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