From b97f67cd60125d1032a96f845a212017f25ef162 Mon Sep 17 00:00:00 2001 From: hsutter Date: Tue, 12 Jan 2016 12:02:59 -0800 Subject: [PATCH] Corrected F.54 example --- CppCoreGuidelines.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 0ae6a6a..b64d7d0 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -3071,6 +3071,8 @@ It's confusing. Writing `[=]` in a member function appears to capture by value, // ... auto lambda = [=]{ use(i,x); }; // BAD: "looks like" copy/value capture + // notes: [&] has identical semantics and copies the this pointer under the current rules + // [=,this] and [&,this] are identical in this case, and still confusing in general x = 42; lambda(); // calls use(42); x = 43; @@ -3078,13 +3080,7 @@ It's confusing. Writing `[=]` in a member function appears to capture by value, // ... - auto lambda2 = [=,this]{ use(i,x); }; // BAD: not much better, and confusing - auto lambda3 = [&,this]{ use(i,x); }; // BAD: not much better, and confusing - auto lambda4 = [&]{ use(i,x); }; // BAD: if lambda2 leaves the scope, it contains a dangling reference to the this parameter from this function's invocation - - // ... - - auto lambda5 = [i,this]{ use(i,x); }; // ok, most explicit and least confusing + auto lambda2 = [i,this]{ use(i,x); }; // ok, most explicit and least confusing // ... }