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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/callback.h.pump ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains utility functions and classes that help the 5 // This file contains utility functions and classes that help the
6 // implementation, and management of the Callback objects. 6 // implementation, and management of the Callback objects.
7 7
8 #ifndef BASE_CALLBACK_INTERNAL_H_ 8 #ifndef BASE_CALLBACK_INTERNAL_H_
9 #define BASE_CALLBACK_INTERNAL_H_ 9 #define BASE_CALLBACK_INTERNAL_H_
10 #pragma once 10 #pragma once
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 // Force the destructor to be instaniated inside this translation unit so 74 // Force the destructor to be instaniated inside this translation unit so
75 // that our subclasses will not get inlined versions. Avoids more template 75 // that our subclasses will not get inlined versions. Avoids more template
76 // bloat. 76 // bloat.
77 ~CallbackBase(); 77 ~CallbackBase();
78 78
79 scoped_refptr<InvokerStorageBase> invoker_storage_; 79 scoped_refptr<InvokerStorageBase> invoker_storage_;
80 InvokeFuncStorage polymorphic_invoke_; 80 InvokeFuncStorage polymorphic_invoke_;
81 }; 81 };
82 82
83 // 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
84 // extract a suitable type for storing, and forwarding arguments.
85 //
86 // In particular, it strips off references, and converts arrays to
87 // pointers for storage; and it avoids accidentally trying to create a
88 // "reference of a reference" if the argument is a reference type.
89 //
90 // This array type becomes an issue for storage because we are passing bound
91 // parameters by const reference. In this case, we end up passing an actual
92 // array type in the initializer list which C++ does not allow. This will
93 // break passing of C-string literals.
94 template <typename T>
95 struct ParamTraits {
96 typedef const T& ForwardType;
97 typedef T StorageType;
98 };
99
100 // The Storage should almost be impossible to trigger unless someone manually
101 // specifies type of the bind parameters. However, in case they do,
102 // this will guard against us accidentally storing a reference parameter.
103 //
104 // The ForwardType should only be used for unbound arguments.
105 template <typename T>
106 struct ParamTraits<T&> {
107 typedef T& ForwardType;
108 typedef T StorageType;
109 };
110
111 // Note that for array types, we implicitly add a const in the conversion. This
112 // means that it is not possible to bind array arguments to functions that take
113 // a non-const pointer. Trying to specialize the template based on a "const
114 // T[n]" does not seem to match correctly, so we are stuck with this
115 // restriction.
116 template <typename T, size_t n>
117 struct ParamTraits<T[n]> {
118 typedef const T* ForwardType;
119 typedef const T* StorageType;
120 };
121
122 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
123 struct ParamTraits<T[]> {
124 typedef const T* ForwardType;
125 typedef const T* StorageType;
126 };
127
83 } // namespace internal 128 } // namespace internal
84 } // namespace base 129 } // namespace base
85 130
86 #endif // BASE_CALLBACK_INTERNAL_H_ 131 #endif // BASE_CALLBACK_INTERNAL_H_
OLDNEW
« 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