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

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

Issue 864123002: Declient calculator test mojom. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Remove extraneous typedef Created 5 years, 11 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/tests/interface_ptr_unittest.cc » ('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 d7bab1632fb87397c817123e4bdbe2e9a263a2de..1c30e401b9373dabead7f9177d2cc5688056159f 100644
--- a/mojo/public/cpp/bindings/callback.h
+++ b/mojo/public/cpp/bindings/callback.h
@@ -62,6 +62,32 @@ class Callback<void(Args...)> {
typedef Callback<void()> Closure;
+namespace {
jamesr 2015/01/22 22:45:24 anonymous namespace inside a header is almost neve
Aaron Boodman 2015/01/22 22:49:08 You're right, thanks.
+
+template <typename Method, typename Class>
+class RunnableImpl {
jamesr 2015/01/22 22:45:24 don't put this in public. If you want it in your t
Aaron Boodman 2015/01/22 22:49:08 done.
+ public:
+ RunnableImpl(Method method, Class instance)
+ : method_(method), instance_(instance) {}
+ template <typename... Args>
+ void Run(Args... args) const {
+ (instance_->*method_)(args...);
+ }
+
+ private:
+ Method method_;
+ Class instance_;
+};
+
+} // namespace
+
+// Convenience to create a create a runnable for any method.
+// |Class| can be any copyable type with an -> operator.
+template <typename Method, typename Class>
+RunnableImpl<Method, Class> MakeRunnable(Method method, Class object) {
+ return RunnableImpl<Method, Class>(method, object);
+}
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_CALLBACK_H_
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698