Commit a907c318 authored by thakis's avatar thakis Committed by Commit bot

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}
parent fdfc765d
...@@ -65,18 +65,6 @@ typedef base::Callback<void(const history::URLRow*, ...@@ -65,18 +65,6 @@ typedef base::Callback<void(const history::URLRow*,
const history::URLRow*)> const history::URLRow*)>
SimulateNotificationCallback; SimulateNotificationCallback;
// Comparison functions as to make it easier to check results of
// GetFaviconBitmaps() and GetIconMappingsForPageURL().
bool IconMappingLessThan(const history::IconMapping& a,
const history::IconMapping& b) {
return a.icon_url < b.icon_url;
}
bool FaviconBitmapLessThan(const history::FaviconBitmap& a,
const history::FaviconBitmap& b) {
return a.pixel_size.GetArea() < b.pixel_size.GetArea();
}
class HistoryClientMock : public history::HistoryClientFakeBookmarks { class HistoryClientMock : public history::HistoryClientFakeBookmarks {
public: public:
MOCK_METHOD0(BlockUntilBookmarksLoaded, void()); MOCK_METHOD0(BlockUntilBookmarksLoaded, void());
...@@ -368,7 +356,9 @@ class HistoryBackendTest : public HistoryBackendTestBase { ...@@ -368,7 +356,9 @@ class HistoryBackendTest : public HistoryBackendTestBase {
return false; return false;
} }
std::sort(icon_mappings->begin(), icon_mappings->end(), std::sort(icon_mappings->begin(), icon_mappings->end(),
IconMappingLessThan); [](const history::IconMapping& a, const history::IconMapping& b) {
return a.icon_url < b.icon_url;
});
return true; return true;
} }
...@@ -378,8 +368,11 @@ class HistoryBackendTest : public HistoryBackendTestBase { ...@@ -378,8 +368,11 @@ class HistoryBackendTest : public HistoryBackendTestBase {
std::vector<FaviconBitmap>* favicon_bitmaps) { std::vector<FaviconBitmap>* favicon_bitmaps) {
if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, favicon_bitmaps)) if (!backend_->thumbnail_db_->GetFaviconBitmaps(icon_id, favicon_bitmaps))
return false; return false;
std::sort(favicon_bitmaps->begin(), favicon_bitmaps->end(), std::sort(
FaviconBitmapLessThan); favicon_bitmaps->begin(), favicon_bitmaps->end(),
[](const history::FaviconBitmap& a, const history::FaviconBitmap& b) {
return a.pixel_size.GetArea() < b.pixel_size.GetArea();
});
return true; return true;
} }
......
...@@ -115,6 +115,23 @@ enum classes and regular enums.</td> ...@@ -115,6 +115,23 @@ enum classes and regular enums.</td>
<td>Recommended for new code. Existing uses of the <code>FINAL</code> macro will be <a href="https://crbug.com/417463">replaced throughout the codebase</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td> <td>Recommended for new code. Existing uses of the <code>FINAL</code> macro will be <a href="https://crbug.com/417463">replaced throughout the codebase</a>. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/VTNZzizN0zo">Discussion thread</a></td>
</tr> </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> <tr>
<td>Local Types as Template Arguments</td> <td>Local Types as Template Arguments</td>
<td></td> <td></td>
...@@ -414,14 +431,6 @@ synthetic function such as a copy constructor</td> ...@@ -414,14 +431,6 @@ synthetic function such as a copy constructor</td>
<td>Unclear how it will work with components</td> <td>Unclear how it will work with components</td>
</tr> </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> <tr>
<td>Non-Static Class Member Initializers</td> <td>Non-Static Class Member Initializers</td>
<td> <td>
......
...@@ -28,10 +28,6 @@ namespace ui { ...@@ -28,10 +28,6 @@ namespace ui {
namespace { namespace {
bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){
return GetScaleForScaleFactor(lhs) < GetScaleForScaleFactor(rhs);
}
std::vector<ScaleFactor>* g_supported_scale_factors = NULL; std::vector<ScaleFactor>* g_supported_scale_factors = NULL;
const float kScaleFactorScales[] = {1.0f, 1.0f, 1.25f, 1.33f, 1.4f, 1.5f, 1.8f, const float kScaleFactorScales[] = {1.0f, 1.0f, 1.25f, 1.33f, 1.4f, 1.5f, 1.8f,
...@@ -49,7 +45,9 @@ void SetSupportedScaleFactors( ...@@ -49,7 +45,9 @@ void SetSupportedScaleFactors(
g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors); g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors);
std::sort(g_supported_scale_factors->begin(), std::sort(g_supported_scale_factors->begin(),
g_supported_scale_factors->end(), g_supported_scale_factors->end(),
ScaleFactorComparator); [](ScaleFactor lhs, ScaleFactor rhs) {
return GetScaleForScaleFactor(lhs) < GetScaleForScaleFactor(rhs);
});
// Set ImageSkia's supported scales. // Set ImageSkia's supported scales.
std::vector<float> scales; std::vector<float> scales;
......
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