From 187c033b74e04ea11d3d09d0b0b193a4e9d999c1 Mon Sep 17 00:00:00 2001 From: Rostyslav Kurylo Date: Sun, 23 Dec 2018 21:53:30 +0200 Subject: [PATCH] Mention C++17's init-statement in the `Limit Variable Scope` section --- 08-Considering_Performance.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/08-Considering_Performance.md b/08-Considering_Performance.md index 6db41c3..89404c5 100644 --- a/08-Considering_Performance.md +++ b/08-Considering_Performance.md @@ -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