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

Unified Diff: mojo/public/cpp/bindings/callback.h

Issue 1402523002: Allow implicitly converting a lambda to mojo::Callback using C++11 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/callback_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/callback.h
diff --git a/mojo/public/cpp/bindings/callback.h b/mojo/public/cpp/bindings/callback.h
index 0a06e76f36ac7a6d6dc1cbfbcd1d951e57d34bad..24a2f43713adc9b5c43dc719de6634c0236f25bf 100644
--- a/mojo/public/cpp/bindings/callback.h
+++ b/mojo/public/cpp/bindings/callback.h
@@ -5,6 +5,7 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
#define MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
+#include <functional>
#include <type_traits>
#include "mojo/public/cpp/bindings/lib/callback_internal.h"
@@ -38,13 +39,13 @@ class Callback<void(Args...)> {
// ownership of |runnable|.
explicit Callback(Runnable* runnable) : sink_(runnable) {}
- // As above, but can take an object that isn't derived from Runnable, so long
- // as it has a compatible operator() or Run() method. operator() will be
- // preferred if the type has both.
+ // Adapts any type that is copy-constructable and has a compatible Run method
+ // or is convertible to std::function<void(Args...)> (such as a lambda of the
+ // correct type).
template <typename Sink>
Callback(const Sink& sink) {
using sink_type = typename std::conditional<
- internal::HasCompatibleCallOperator<Sink, Args...>::value,
+ std::is_convertible<Sink, std::function<void(Args...)>>::value,
FunctorAdapter<Sink>, RunnableAdapter<Sink>>::type;
sink_ = internal::SharedPtr<Runnable>(new sink_type(sink));
}
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/lib/callback_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698