summaryrefslogtreecommitdiffstats
path: root/styleguide/c++/c++11.html
diff options
context:
space:
mode:
authorthakis <thakis@chromium.org>2014-11-04 15:38:06 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-04 23:38:45 +0000
commita907c318b52d7b66d2a66837bdfa6faf9e1058a3 (patch)
treeb10e10ece17b206ad31f54929cbe356ffcb22a15 /styleguide/c++/c++11.html
parentfdfc765d2bd2a6d674bad2fa4f2b064f56701aaa (diff)
downloadchromium_src-a907c318b52d7b66d2a66837bdfa6faf9e1058a3.zip
chromium_src-a907c318b52d7b66d2a66837bdfa6faf9e1058a3.tar.gz
chromium_src-a907c318b52d7b66d2a66837bdfa6faf9e1058a3.tar.bz2
c++11: Allow lambdas, with some restrictions.
Thanks to David Michael <dmichael@chromium.org> for condensing the discussion thread to a recommendation! BUG=none Review URL: https://codereview.chromium.org/699283002 Cr-Commit-Position: refs/heads/master@{#302708}
Diffstat (limited to 'styleguide/c++/c++11.html')
-rw-r--r--styleguide/c++/c++11.html25
1 files changed, 17 insertions, 8 deletions
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.</td>
</tr>
<tr>
+<td>Lambda Expressions</td>
+<td><code>[<i>captures</i>](<i>params</i>) -&gt; <i>ret</i> { <i>body</i> }</code></td>
+<td>Anonymous functions</td>
+<td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions</a></td>
+<td>Do not bind or store lambdas; use <code>base::Bind</code> and
+<code>base::Callback</code> instead, because they offer protection against a
+large class of object lifetime mistakes. Don't use default captures
+(<code>[=]</code>, <code>[&amp;]</code> &ndash; <a
+ href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Lambda_expressions">Google Style Guide</a>).
+Lambdas are typically useful as a parameter to methods or
+functions that will use them immediately, such as those in
+<code>&lt;algorithm&gt;</code>. <a
+ href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/D9UnnxBnciQ">Discussion
+ thread</a></td>
+</tr>
+
+<tr>
<td>Local Types as Template Arguments</td>
<td></td>
<td>Allows local and unnamed types as template arguments</td>
@@ -415,14 +432,6 @@ synthetic function such as a copy constructor</td>
</tr>
<tr>
-<td>Lambda Expressions</td>
-<td><code>[<i>captures</i>](<i>params</i>) -&gt; <i>ret</i> { <i>body</i> }</code></td>
-<td>Anonymous functions</td>
-<td><a href="http://en.cppreference.com/w/cpp/language/lambda">Lambda functions</a></td>
-<td>No default captures (<a href="https://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Lambda_expressions">Google Style Guide</a>). <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/D9UnnxBnciQ">Discussion thread</a></td>
-</tr>
-
-<tr>
<td>Non-Static Class Member Initializers</td>
<td>
<code>