From a907c318b52d7b66d2a66837bdfa6faf9e1058a3 Mon Sep 17 00:00:00 2001 From: thakis Date: Tue, 4 Nov 2014 15:38:06 -0800 Subject: c++11: Allow lambdas, with some restrictions. Thanks to David Michael for condensing the discussion thread to a recommendation! BUG=none Review URL: https://codereview.chromium.org/699283002 Cr-Commit-Position: refs/heads/master@{#302708} --- styleguide/c++/c++11.html | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'styleguide/c++/c++11.html') diff --git a/styleguide/c++/c++11.html b/styleguide/c++/c++11.html index 6d870fb..f99a8eb 100644 --- a/styleguide/c++/c++11.html +++ b/styleguide/c++/c++11.html @@ -116,6 +116,23 @@ enum classes and regular enums. +Lambda Expressions +[captures](params) -> ret { body } +Anonymous functions +Lambda functions +Do not bind or store lambdas; use base::Bind and +base::Callback instead, because they offer protection against a +large class of object lifetime mistakes. Don't use default captures +([=], [&]Google Style Guide). +Lambdas are typically useful as a parameter to methods or +functions that will use them immediately, such as those in +<algorithm>. Discussion + thread + + + Local Types as Template Arguments Allows local and unnamed types as template arguments @@ -415,14 +432,6 @@ synthetic function such as a copy constructor -Lambda Expressions -[captures](params) -> ret { body } -Anonymous functions -Lambda functions -No default captures (Google Style Guide). Discussion thread - - - Non-Static Class Member Initializers -- cgit v1.1