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

Unified Diff: base/mac/bind_objc_block.h

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/json/json_reader.cc ('k') | base/mac/bind_objc_block_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/bind_objc_block.h
diff --git a/base/mac/bind_objc_block.h b/base/mac/bind_objc_block.h
index 9deb2d22e75c5add2da220e47898060eca0f53b7..c31f26e5a31f6347fc2459848f0d261a8e4c4bf4 100644
--- a/base/mac/bind_objc_block.h
+++ b/base/mac/bind_objc_block.h
@@ -21,51 +21,32 @@
// BindBlock(^(const std::string& arg0, const std::string& arg1) {
// ...
// });
+//
+// These variadic templates will accommodate any number of arguments, however
+// the underlying templates in bind_internal.h and callback.h are limited to
+// seven total arguments, and the bound block itself is used as one of these
+// arguments, so functionally the templates are limited to binding blocks with
+// zero through six arguments.
namespace base {
namespace internal {
-// Helper functions to run the block contained in the parameter.
-template<typename R>
-R RunBlock(base::mac::ScopedBlock<R(^)()> block) {
- R(^extracted_block)() = block.get();
- return extracted_block();
-}
-
-template<typename R, typename A1>
-R RunBlock(base::mac::ScopedBlock<R(^)(A1)> block, A1 a) {
- R(^extracted_block)(A1) = block.get();
- return extracted_block(a);
-}
-
-template<typename R, typename A1, typename A2>
-R RunBlock(base::mac::ScopedBlock<R(^)(A1, A2)> block, A1 a, A2 b) {
- R(^extracted_block)(A1, A2) = block.get();
- return extracted_block(a, b);
+// Helper function to run the block contained in the parameter.
+template<typename R, typename... Args>
+R RunBlock(base::mac::ScopedBlock<R(^)(Args...)> block, Args... args) {
+ R(^extracted_block)(Args...) = block.get();
+ return extracted_block(args...);
}
} // namespace internal
-// Construct a callback with no argument from an objective-C block.
-template<typename R>
-base::Callback<R(void)> BindBlock(R(^block)()) {
- return base::Bind(&base::internal::RunBlock<R>,
- base::mac::ScopedBlock<R(^)()>(Block_copy(block)));
-}
-
-// Construct a callback with one argument from an objective-C block.
-template<typename R, typename A1>
-base::Callback<R(A1)> BindBlock(R(^block)(A1)) {
- return base::Bind(&base::internal::RunBlock<R, A1>,
- base::mac::ScopedBlock<R(^)(A1)>(Block_copy(block)));
-}
-
-// Construct a callback with two arguments from an objective-C block.
-template<typename R, typename A1, typename A2>
-base::Callback<R(A1, A2)> BindBlock(R(^block)(A1, A2)) {
- return base::Bind(&base::internal::RunBlock<R, A1, A2>,
- base::mac::ScopedBlock<R(^)(A1, A2)>(Block_copy(block)));
+// Construct a callback from an objective-C block with up to six arguments (see
+// note above).
+template<typename R, typename... Args>
+base::Callback<R(Args...)> BindBlock(R(^block)(Args...)) {
+ return base::Bind(&base::internal::RunBlock<R, Args...>,
+ base::mac::ScopedBlock<R(^)(Args...)>(Block_copy(block)));
}
} // namespace base
« no previous file with comments | « base/json/json_reader.cc ('k') | base/mac/bind_objc_block_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698