C++: Do not use [=] or [=,this] to capture 'this'#543
C++: Do not use [=] or [=,this] to capture 'this'#543pdillinger wants to merge 1 commit intogoogle:gh-pagesfrom
Conversation
Summary: C++20 deprecates [=] capturing 'this' (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0806r2.html) but the recommended alternative [=,this] is not standards-legal prior to C++20 (though it is widely accepted *with warning*). For portability (and readability), style should forbid using [=] or [=,this] to capture 'this'. Any by-value captures must be explicitly listed if also capturing 'this', though 'this' can still be implicitly default-captured by reference, as in [&, some_var_to_copy]. Test Plan: documentation only
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
tituswinters
left a comment
There was a problem hiding this comment.
Thanks for your PR. Lemme run this past the other owners of the style guide and get back to you.
My guess is this may be more words than we want to devote on the topic in this document: supplemental material like the TotW series (abseil.io/tips) may be better for the more-in-depth guidance parts of this.
I'll get back to you in a couple days either way.
Summary: C++20 deprecates [=] capturing 'this'
(http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0806r2.html)
but the recommended alternative [=,this] is not standards-legal prior to
C++20 (though it is widely accepted with warning).
For portability (and readability), style should forbid using
[=] or [=,this] to capture 'this'. Any by-value captures must be
explicitly listed if also capturing 'this', though 'this' can still
be implicitly default-captured by reference, as in
[&, some_var_to_copy].
Test Plan: documentation only