mirror of
https://github.com/cpp-best-practices/cppbestpractices.git
synced 2025-12-17 11:14:35 +03:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user