Commit 78eea061 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[C++] Allow usage of Lambda capture expressions

This change moves Lambda capture expressions in the Allowed C++14
Features section and details their usage guidelines.

Bug: NONE
Change-Id: I2e1b117512ee3262f50d63c379b6d31506cfcd33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617506
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660839}
parent 18e72c11
...@@ -408,6 +408,22 @@ template &lt;typename T&gt;<br/>void Function(T&amp;&amp; t) { ... }</code></td> ...@@ -408,6 +408,22 @@ template &lt;typename T&gt;<br/>void Function(T&amp;&amp; t) { ... }</code></td>
<td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/LasGKwE3SFM/discussion">Discussion thread</a></td> <td><a href="https://groups.google.com/a/chromium.org/d/topic/cxx/LasGKwE3SFM/discussion">Discussion thread</a></td>
</tr> </tr>
<tr>
<td>Lambda capture expressions</td>
<td><code>auto widget = std::make_unique&lt;Widget&gt;();<br>auto lambda = [widget = std::move(widget)]() {<br>&nbsp;&nbsp;SetWidget(std::move(widget));<br>}</code></td>
<td>Allows lambda captures to be explicitly initialized with expressions.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/lambda#Lambda_capture">Lambda capture</a></td>
<td> Lambda capture expressions should only be used to capture existing names in
ways that C++11's direct capture doesn't allow, and should not be used as a
way to introduce new names. That is, capture expressions should always shadow
existing variables (or data members), and not substantially change their
meaning. Usage should be rare.
<a href="https://groups.google.com/a/chromium.org/d/msg/cxx/8BHoi4T6ZhA/pWHB6IYoAgAJ">
Discussion thread</a> with
<a href="https://groups.google.com/a/chromium.org/d/msg/cxx/8BHoi4T6ZhA/WwKXh2RgAgAJ">
examples</a></td>
</tr>
<tr> <tr>
<td>Number literal separators</td> <td>Number literal separators</td>
<td><code>float f = 1'000'000.000'1;</code></td> <td><code>float f = 1'000'000.000'1;</code></td>
...@@ -1025,14 +1041,6 @@ something, remove all callers and remove the function instead.</td> ...@@ -1025,14 +1041,6 @@ something, remove all callers and remove the function instead.</td>
<td>Often more surprising than <code>auto</code>. For instance, the <code>decltype</code> deduction rules do not remove references.</td> <td>Often more surprising than <code>auto</code>. For instance, the <code>decltype</code> deduction rules do not remove references.</td>
</tr> </tr>
<tr>
<td>Lambda capture expressions</td>
<td><code>auto widget = std::make_unique&lt;Widget&gt;();<br>auto lambda = [widget = std::move(widget)]() {<br>&nbsp;&nbsp;SetWidget(std::move(widget));<br>}</code></td>
<td>Allows lambda captures to be explicitly initialized with expressions.</td>
<td><a href="http://en.cppreference.com/w/cpp/language/lambda#Lambda_capture">Lambda capture</a></td>
<td>Particularly useful to capture move-only types in a lambda when a reference would go out of scope. Less useful without allowing lambdas to outlive the scope.</td>
</tr>
<tr> <tr>
<td>Variable templates</td> <td>Variable templates</td>
<td><code>template &lt;typename T&gt;<br>constexpr T tau = T(6.283185307179586476925286766559);</code></td> <td><code>template &lt;typename T&gt;<br>constexpr T tau = T(6.283185307179586476925286766559);</code></td>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment