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

Unified Diff: base/callback.h

Issue 8728010: Increase Bind/Callback Arity from 6 -> 7. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated comments. Created 9 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
Index: base/callback.h
diff --git a/base/callback.h b/base/callback.h
index 6844cc54dcb34317e9e0645753a304f52cc8bfc5..16e3ee60c51971f87bb914e9e52bf5fd9ddd3091 100644
--- a/base/callback.h
+++ b/base/callback.h
@@ -3,7 +3,6 @@
// DO NOT EDIT BY HAND!!!
-
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -227,7 +226,7 @@ namespace base {
// compiler that the template only has 1 type parameter which is the function
// signature that the Callback is representing.
//
-// After this, create template specializations for 0-6 parameters. Note that
+// After this, create template specializations for 0-7 parameters. Note that
// even though the template typelist grows, the specialization still
// only has one type: the function signature.
template <typename Sig>
@@ -573,6 +572,67 @@ class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase {
};
+template <typename R, typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6, typename A7>
+class Callback<R(A1, A2, A3, A4, A5, A6, A7)> : public internal::CallbackBase {
+ public:
+ typedef R(RunType)(A1, A2, A3, A4, A5, A6, A7);
+
+ Callback() : CallbackBase(NULL, NULL) { }
+
+ // We pass BindStateHolder by const ref to avoid incurring an
+ // unnecessary AddRef/Unref pair even though we will modify the object.
+ // We cannot use a normal reference because the compiler will warn
+ // since this is often used on a return value, which is a temporary.
+ //
+ // Note that this constructor CANNOT be explicit, and that Bind() CANNOT
+ // return the exact Callback<> type. See base/bind.h for details.
+ template <typename T>
+ Callback(const internal::BindStateHolder<T>& bind_state_holder)
+ : CallbackBase(NULL, &bind_state_holder.bind_state_) {
+ // Force the assignment to a location variable of PolymorphicInvoke
+ // so the compiler will typecheck that the passed in Run() method has
+ // the correct type.
+ PolymorphicInvoke invoke_func = &T::InvokerType::Run;
+ polymorphic_invoke_ = reinterpret_cast<InvokeFuncStorage>(invoke_func);
+ }
+
+ bool Equals(const Callback& other) const {
+ return CallbackBase::Equals(other);
+ }
+
+ R Run(typename internal::CallbackParamTraits<A1>::ForwardType a1,
+ typename internal::CallbackParamTraits<A2>::ForwardType a2,
+ typename internal::CallbackParamTraits<A3>::ForwardType a3,
+ typename internal::CallbackParamTraits<A4>::ForwardType a4,
+ typename internal::CallbackParamTraits<A5>::ForwardType a5,
+ typename internal::CallbackParamTraits<A6>::ForwardType a6,
+ typename internal::CallbackParamTraits<A7>::ForwardType a7) const {
+ PolymorphicInvoke f =
+ reinterpret_cast<PolymorphicInvoke>(polymorphic_invoke_);
+
+ return f(bind_state_.get(), a1,
+ a2,
+ a3,
+ a4,
+ a5,
+ a6,
+ a7);
+ }
+
+ private:
+ typedef R(*PolymorphicInvoke)(
+ internal::BindStateBase*,
+ typename internal::CallbackParamTraits<A1>::ForwardType,
+ typename internal::CallbackParamTraits<A2>::ForwardType,
+ typename internal::CallbackParamTraits<A3>::ForwardType,
+ typename internal::CallbackParamTraits<A4>::ForwardType,
+ typename internal::CallbackParamTraits<A5>::ForwardType,
+ typename internal::CallbackParamTraits<A6>::ForwardType,
+ typename internal::CallbackParamTraits<A7>::ForwardType);
+
+};
+
// Syntactic sugar to make Callbacks<void(void)> easier to declare since it
// will be used in a lot of APIs with delayed execution.
« base/bind_internal.h ('K') | « base/bind_internal_win.h.pump ('k') | base/callback.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698