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

Unified Diff: base/callback_internal.h

Issue 6718021: Callback support for unbound reference and array arguments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up. Created 9 years, 9 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 | « base/callback.h.pump ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback_internal.h
diff --git a/base/callback_internal.h b/base/callback_internal.h
index 4f1d3c346bfbd7ddd5695ed1f6f5d06482050ce5..fa4be920382857cf7d7585c787104f6bec981ad9 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -80,6 +80,51 @@ class CallbackBase {
InvokeFuncStorage polymorphic_invoke_;
};
+// This is a typetraits object that's used to take an argumen types, and
akalin 2011/03/24 00:40:19 an argumen -> argument storing, and forwarding ->
awong 2011/03/24 01:37:17 Done
+// extract a suitable type for storing, and forwarding arguments.
+//
+// In particular, it strips off references, and converts arrays to
+// pointers for storage; and it avoids accidentally trying to create a
+// "reference of a reference" if the argument is a reference type.
+//
+// This array type becomes an issue for storage because we are passing bound
+// parameters by const reference. In this case, we end up passing an actual
+// array type in the initializer list which C++ does not allow. This will
+// break passing of C-string literals.
+template <typename T>
+struct ParamTraits {
+ typedef const T& ForwardType;
+ typedef T StorageType;
+};
+
+// The Storage should almost be impossible to trigger unless someone manually
+// specifies type of the bind parameters. However, in case they do,
+// this will guard against us accidentally storing a reference parameter.
+//
+// The ForwardType should only be used for unbound arguments.
+template <typename T>
+struct ParamTraits<T&> {
+ typedef T& ForwardType;
+ typedef T StorageType;
+};
+
+// Note that for array types, we implicitly add a const in the conversion. This
+// means that it is not possible to bind array arguments to functions that take
+// a non-const pointer. Trying to specialize the template based on a "const
+// T[n]" does not seem to match correctly, so we are stuck with this
+// restriction.
+template <typename T, size_t n>
+struct ParamTraits<T[n]> {
+ typedef const T* ForwardType;
+ typedef const T* StorageType;
+};
+
+template <typename T>
akalin 2011/03/24 00:40:19 in this context, and in arguments, T[] means T*, r
awong 2011/03/24 01:37:17 Yes. As far as I know. See the comment above for
akalin 2011/03/24 01:49:18 It might be less confusing to have the template ty
awong 2011/03/24 01:58:56 Unforutnately, during the actual pattern match for
+struct ParamTraits<T[]> {
+ typedef const T* ForwardType;
+ typedef const T* StorageType;
+};
+
} // namespace internal
} // namespace base
« no previous file with comments | « base/callback.h.pump ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698