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_ |