There was an error while loading. Please reload this page.
Limit Variable Scope
1 parent c644a3b commit 187c033Copy full SHA for 187c033
08-Considering_Performance.md
@@ -273,6 +273,16 @@ for (int i = 0; i < 15; ++i)
273
// obj is still taking up memory for no reason
274
```
275
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
286
[This topic has an associated discussion thread](https://github.com/lefticus/cppbestpractices/issues/52).
287
288
### Prefer `double` to `float`, But Test First
0 commit comments