Merge pull request #100 from RostakaGmfun/cpp17-init-statements

Mention C++17's init-statement in the `Limit Variable Scope` section
This commit is contained in:
Jason Turner
2019-03-26 07:34:46 -07:00
committed by GitHub

View File

@@ -273,6 +273,16 @@ for (int i = 0; i < 15; ++i)
// obj is still taking up memory for no reason // 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). [This topic has an associated discussion thread](https://github.com/lefticus/cppbestpractices/issues/52).
### Prefer `double` to `float`, But Test First ### Prefer `double` to `float`, But Test First