Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: base/bind_lambda.h

Issue 694453002: Added utility base::BindLambda to allow passing lambdas as base::Callback<> Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tried to work around msvc failure Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/bind_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_BIND_LAMBDA_H_
6 #define BASE_BIND_LAMBDA_H_
7
8 #include "base/bind.h"
9
10 namespace base {
11 namespace internal {
12
13 template <typename T>
14 struct RemoveObjectFromMemberFunction {};
15 template <typename R, typename Z, typename... Args>
16 struct RemoveObjectFromMemberFunction<R (Z::*)(Args...) const> {
17 typedef R(type)(Args...);
18 };
19 template <typename R, typename Z, typename... Args>
20 struct RemoveObjectFromMemberFunction<R (Z::*)(Args...)> {
21 typedef R(type)(Args...);
22 };
23
24 template <typename LambdaType>
25 struct LambdaTraits {
26 using LambdaSig = decltype(&LambdaType::operator());
27 using CallbackSig = typename RemoveObjectFromMemberFunction<LambdaSig>::type;
28 using CallbackType = Callback<CallbackSig>;
29 };
30
31 template <typename LambdaType>
32 using LambdaCallback = typename LambdaTraits<LambdaType>::CallbackType;
33
34 } // namespace internal
35
36 template <typename LambdaType>
37 internal::LambdaCallback<LambdaType> BindLambda(const LambdaType& lambda) {
38 return Bind(&LambdaType::operator(), Owned(new LambdaType(lambda)));
39 }
40
41 } // namespace base
42
43 #endif // BASE_BIND_LAMBDA_H_
OLDNEW
« no previous file with comments | « no previous file | base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698