Mention C++17's init-statement in the Limit Variable Scope section

This commit is contained in:
Rostyslav Kurylo
2018-12-23 21:53:30 +02:00
parent c644a3bf52
commit 187c033b74

View File

@@ -273,6 +273,16 @@ for (int i = 0; i < 15; ++i)
// obj is still taking up memory for no reason
```
For C++17 and onwards, consider using init-statement in the `if` and `switch` statements:
```cpp
if (MyObject obj(index); obj.good()) {
// do something if obj is good
} else {
// do something if obj is not good
}
```
[This topic has an associated discussion thread](https://github.com/lefticus/cppbestpractices/issues/52).
### Prefer `double` to `float`, But Test First