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

Side by Side Diff: base/bind.h

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « base/base.gypi ('k') | base/bind.h.pump » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // This file was GENERATED by command:
2 // pump.py bind.h.pump
3 // DO NOT EDIT BY HAND!!!
4
5
6 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
7 // 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
8 // found in the LICENSE file. 3 // found in the LICENSE file.
9 4
10 #ifndef BASE_BIND_H_ 5 #ifndef BASE_BIND_H_
11 #define BASE_BIND_H_ 6 #define BASE_BIND_H_
12 7
13 #include "base/bind_internal.h" 8 #include "base/bind_internal.h"
14 #include "base/callback_internal.h" 9 #include "base/callback_internal.h"
15 10
(...skipping 23 matching lines...) Expand all
39 // 34 //
40 // Each unique combination of (arity, function_type, num_prebound) where 35 // Each unique combination of (arity, function_type, num_prebound) where
41 // function_type is one of {function, method, const_method} would require 36 // function_type is one of {function, method, const_method} would require
42 // one specialization. We eventually have to do a similar number of 37 // one specialization. We eventually have to do a similar number of
43 // specializations anyways in the implementation (see the Invoker<>, 38 // specializations anyways in the implementation (see the Invoker<>,
44 // classes). However, it is avoidable in Bind if we return the result 39 // classes). However, it is avoidable in Bind if we return the result
45 // via an indirection like we do below. 40 // via an indirection like we do below.
46 // 41 //
47 // TODO(ajwong): We might be able to avoid this now, but need to test. 42 // TODO(ajwong): We might be able to avoid this now, but need to test.
48 // 43 //
49 // It is possible to move most of the COMPILE_ASSERT asserts into BindState<>, 44 // It is possible to move most of the static_assert into BindState<>, but it
50 // but it feels a little nicer to have the asserts here so people do not 45 // feels a little nicer to have the asserts here so people do not need to crack
51 // need to crack open bind_internal.h. On the other hand, it makes Bind() 46 // open bind_internal.h. On the other hand, it makes Bind() harder to read.
52 // harder to read.
53 47
54 namespace base { 48 namespace base {
55 49
56 template <typename Functor> 50 template <typename Functor>
57 base::Callback< 51 base::Callback<
58 typename internal::BindState< 52 typename internal::BindState<
59 typename internal::FunctorTraits<Functor>::RunnableType, 53 typename internal::FunctorTraits<Functor>::RunnableType,
60 typename internal::FunctorTraits<Functor>::RunType, 54 typename internal::FunctorTraits<Functor>::RunType,
61 void()> 55 void()>::UnboundRunType>
62 ::UnboundRunType>
63 Bind(Functor functor) { 56 Bind(Functor functor) {
64 // Typedefs for how to store and run the functor. 57 // Typedefs for how to store and run the functor.
65 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; 58 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
66 typedef typename internal::FunctorTraits<Functor>::RunType RunType; 59 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
67 60
68 typedef internal::BindState<RunnableType, RunType, void()> BindState; 61 typedef internal::BindState<RunnableType, RunType, void()> BindState;
69 62
70
71 return Callback<typename BindState::UnboundRunType>( 63 return Callback<typename BindState::UnboundRunType>(
72 new BindState(internal::MakeRunnable(functor))); 64 new BindState(internal::MakeRunnable(functor)));
73 } 65 }
74 66
75 template <typename Functor, typename P1> 67 template <typename Functor, typename... Args>
76 base::Callback< 68 base::Callback<
77 typename internal::BindState< 69 typename internal::BindState<
78 typename internal::FunctorTraits<Functor>::RunnableType, 70 typename internal::FunctorTraits<Functor>::RunnableType,
79 typename internal::FunctorTraits<Functor>::RunType, 71 typename internal::FunctorTraits<Functor>::RunType,
80 void(typename internal::CallbackParamTraits<P1>::StorageType)> 72 void(typename internal::CallbackParamTraits<Args>::StorageType...)>
81 ::UnboundRunType> 73 ::UnboundRunType>
82 Bind(Functor functor, const P1& p1) { 74 Bind(Functor functor, const Args&... args) {
83 // Typedefs for how to store and run the functor. 75 // Typedefs for how to store and run the functor.
84 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType; 76 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
85 typedef typename internal::FunctorTraits<Functor>::RunType RunType; 77 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
86 78
87 // Use RunnableType::RunType instead of RunType above because our 79 // Use RunnableType::RunType instead of RunType above because our
88 // checks should below for bound references need to know what the actual 80 // checks should below for bound references need to know what the actual
89 // functor is going to interpret the argument as. 81 // functor is going to interpret the argument as.
90 typedef internal::FunctionTraits<typename RunnableType::RunType> 82 typedef typename RunnableType::RunType BoundRunType;
91 BoundFunctorTraits;
92 83
93 // Do not allow binding a non-const reference parameter. Non-const reference 84 // Do not allow binding a non-const reference parameter. Non-const reference
94 // parameters are disallowed by the Google style guide. Also, binding a 85 // parameters are disallowed by the Google style guide. Also, binding a
95 // non-const reference parameter can make for subtle bugs because the 86 // non-const reference parameter can make for subtle bugs because the
96 // invoked function will receive a reference to the stored copy of the 87 // invoked function will receive a reference to the stored copy of the
97 // argument and not the original. 88 // argument and not the original.
98 COMPILE_ASSERT( 89 static_assert(!internal::HasNonConstReferenceParam<BoundRunType>::value,
99 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ), 90 "do_not_bind_functions_with_nonconst_ref");
100 do_not_bind_functions_with_nonconst_ref); 91
92 const bool is_method = internal::HasIsMethodTag<RunnableType>::value;
101 93
102 // For methods, we need to be careful for parameter 1. We do not require 94 // For methods, we need to be careful for parameter 1. We do not require
103 // a scoped_refptr because BindState<> itself takes care of AddRef() for 95 // a scoped_refptr because BindState<> itself takes care of AddRef() for
104 // methods. We also disallow binding of an array as the method's target 96 // methods. We also disallow binding of an array as the method's target
105 // object. 97 // object.
106 COMPILE_ASSERT( 98 static_assert(!internal::BindsArrayToFirstArg<is_method, Args...>::value,
107 internal::HasIsMethodTag<RunnableType>::value || 99 "first_bound_argument_to_method_cannot_be_array");
108 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value, 100 static_assert(
109 p1_is_refcounted_type_and_needs_scoped_refptr); 101 !internal::HasRefCountedParamAsRawPtr<is_method, Args...>::value,
110 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value || 102 "a_parameter_is_refcounted_type_and_needs_scoped_refptr");
111 !is_array<P1>::value, 103
112 first_bound_argument_to_method_cannot_be_array);
113 typedef internal::BindState<RunnableType, RunType, 104 typedef internal::BindState<RunnableType, RunType,
114 void(typename internal::CallbackParamTraits<P1>::StorageType)> BindState; 105 void(typename internal::CallbackParamTraits<Args>::StorageType...)>
115 106 BindState;
116 107
117 return Callback<typename BindState::UnboundRunType>( 108 return Callback<typename BindState::UnboundRunType>(
118 new BindState(internal::MakeRunnable(functor), p1)); 109 new BindState(internal::MakeRunnable(functor), args...));
119 }
120
121 template <typename Functor, typename P1, typename P2>
122 base::Callback<
123 typename internal::BindState<
124 typename internal::FunctorTraits<Functor>::RunnableType,
125 typename internal::FunctorTraits<Functor>::RunType,
126 void(typename internal::CallbackParamTraits<P1>::StorageType,
127 typename internal::CallbackParamTraits<P2>::StorageType)>
128 ::UnboundRunType>
129 Bind(Functor functor, const P1& p1, const P2& p2) {
130 // Typedefs for how to store and run the functor.
131 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
132 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
133
134 // Use RunnableType::RunType instead of RunType above because our
135 // checks should below for bound references need to know what the actual
136 // functor is going to interpret the argument as.
137 typedef internal::FunctionTraits<typename RunnableType::RunType>
138 BoundFunctorTraits;
139
140 // Do not allow binding a non-const reference parameter. Non-const reference
141 // parameters are disallowed by the Google style guide. Also, binding a
142 // non-const reference parameter can make for subtle bugs because the
143 // invoked function will receive a reference to the stored copy of the
144 // argument and not the original.
145 COMPILE_ASSERT(
146 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
147 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ),
148 do_not_bind_functions_with_nonconst_ref);
149
150 // For methods, we need to be careful for parameter 1. We do not require
151 // a scoped_refptr because BindState<> itself takes care of AddRef() for
152 // methods. We also disallow binding of an array as the method's target
153 // object.
154 COMPILE_ASSERT(
155 internal::HasIsMethodTag<RunnableType>::value ||
156 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
157 p1_is_refcounted_type_and_needs_scoped_refptr);
158 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
159 !is_array<P1>::value,
160 first_bound_argument_to_method_cannot_be_array);
161 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
162 p2_is_refcounted_type_and_needs_scoped_refptr);
163 typedef internal::BindState<RunnableType, RunType,
164 void(typename internal::CallbackParamTraits<P1>::StorageType,
165 typename internal::CallbackParamTraits<P2>::StorageType)> BindState;
166
167
168 return Callback<typename BindState::UnboundRunType>(
169 new BindState(internal::MakeRunnable(functor), p1, p2));
170 }
171
172 template <typename Functor, typename P1, typename P2, typename P3>
173 base::Callback<
174 typename internal::BindState<
175 typename internal::FunctorTraits<Functor>::RunnableType,
176 typename internal::FunctorTraits<Functor>::RunType,
177 void(typename internal::CallbackParamTraits<P1>::StorageType,
178 typename internal::CallbackParamTraits<P2>::StorageType,
179 typename internal::CallbackParamTraits<P3>::StorageType)>
180 ::UnboundRunType>
181 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3) {
182 // Typedefs for how to store and run the functor.
183 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
184 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
185
186 // Use RunnableType::RunType instead of RunType above because our
187 // checks should below for bound references need to know what the actual
188 // functor is going to interpret the argument as.
189 typedef internal::FunctionTraits<typename RunnableType::RunType>
190 BoundFunctorTraits;
191
192 // Do not allow binding a non-const reference parameter. Non-const reference
193 // parameters are disallowed by the Google style guide. Also, binding a
194 // non-const reference parameter can make for subtle bugs because the
195 // invoked function will receive a reference to the stored copy of the
196 // argument and not the original.
197 COMPILE_ASSERT(
198 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
199 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
200 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ),
201 do_not_bind_functions_with_nonconst_ref);
202
203 // For methods, we need to be careful for parameter 1. We do not require
204 // a scoped_refptr because BindState<> itself takes care of AddRef() for
205 // methods. We also disallow binding of an array as the method's target
206 // object.
207 COMPILE_ASSERT(
208 internal::HasIsMethodTag<RunnableType>::value ||
209 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
210 p1_is_refcounted_type_and_needs_scoped_refptr);
211 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
212 !is_array<P1>::value,
213 first_bound_argument_to_method_cannot_be_array);
214 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
215 p2_is_refcounted_type_and_needs_scoped_refptr);
216 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
217 p3_is_refcounted_type_and_needs_scoped_refptr);
218 typedef internal::BindState<RunnableType, RunType,
219 void(typename internal::CallbackParamTraits<P1>::StorageType,
220 typename internal::CallbackParamTraits<P2>::StorageType,
221 typename internal::CallbackParamTraits<P3>::StorageType)> BindState;
222
223
224 return Callback<typename BindState::UnboundRunType>(
225 new BindState(internal::MakeRunnable(functor), p1, p2, p3));
226 }
227
228 template <typename Functor, typename P1, typename P2, typename P3, typename P4>
229 base::Callback<
230 typename internal::BindState<
231 typename internal::FunctorTraits<Functor>::RunnableType,
232 typename internal::FunctorTraits<Functor>::RunType,
233 void(typename internal::CallbackParamTraits<P1>::StorageType,
234 typename internal::CallbackParamTraits<P2>::StorageType,
235 typename internal::CallbackParamTraits<P3>::StorageType,
236 typename internal::CallbackParamTraits<P4>::StorageType)>
237 ::UnboundRunType>
238 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4) {
239 // Typedefs for how to store and run the functor.
240 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
241 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
242
243 // Use RunnableType::RunType instead of RunType above because our
244 // checks should below for bound references need to know what the actual
245 // functor is going to interpret the argument as.
246 typedef internal::FunctionTraits<typename RunnableType::RunType>
247 BoundFunctorTraits;
248
249 // Do not allow binding a non-const reference parameter. Non-const reference
250 // parameters are disallowed by the Google style guide. Also, binding a
251 // non-const reference parameter can make for subtle bugs because the
252 // invoked function will receive a reference to the stored copy of the
253 // argument and not the original.
254 COMPILE_ASSERT(
255 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
256 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
257 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
258 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ),
259 do_not_bind_functions_with_nonconst_ref);
260
261 // For methods, we need to be careful for parameter 1. We do not require
262 // a scoped_refptr because BindState<> itself takes care of AddRef() for
263 // methods. We also disallow binding of an array as the method's target
264 // object.
265 COMPILE_ASSERT(
266 internal::HasIsMethodTag<RunnableType>::value ||
267 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
268 p1_is_refcounted_type_and_needs_scoped_refptr);
269 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
270 !is_array<P1>::value,
271 first_bound_argument_to_method_cannot_be_array);
272 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
273 p2_is_refcounted_type_and_needs_scoped_refptr);
274 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
275 p3_is_refcounted_type_and_needs_scoped_refptr);
276 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
277 p4_is_refcounted_type_and_needs_scoped_refptr);
278 typedef internal::BindState<RunnableType, RunType,
279 void(typename internal::CallbackParamTraits<P1>::StorageType,
280 typename internal::CallbackParamTraits<P2>::StorageType,
281 typename internal::CallbackParamTraits<P3>::StorageType,
282 typename internal::CallbackParamTraits<P4>::StorageType)> BindState;
283
284
285 return Callback<typename BindState::UnboundRunType>(
286 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4));
287 }
288
289 template <typename Functor, typename P1, typename P2, typename P3, typename P4,
290 typename P5>
291 base::Callback<
292 typename internal::BindState<
293 typename internal::FunctorTraits<Functor>::RunnableType,
294 typename internal::FunctorTraits<Functor>::RunType,
295 void(typename internal::CallbackParamTraits<P1>::StorageType,
296 typename internal::CallbackParamTraits<P2>::StorageType,
297 typename internal::CallbackParamTraits<P3>::StorageType,
298 typename internal::CallbackParamTraits<P4>::StorageType,
299 typename internal::CallbackParamTraits<P5>::StorageType)>
300 ::UnboundRunType>
301 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
302 const P5& p5) {
303 // Typedefs for how to store and run the functor.
304 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
305 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
306
307 // Use RunnableType::RunType instead of RunType above because our
308 // checks should below for bound references need to know what the actual
309 // functor is going to interpret the argument as.
310 typedef internal::FunctionTraits<typename RunnableType::RunType>
311 BoundFunctorTraits;
312
313 // Do not allow binding a non-const reference parameter. Non-const reference
314 // parameters are disallowed by the Google style guide. Also, binding a
315 // non-const reference parameter can make for subtle bugs because the
316 // invoked function will receive a reference to the stored copy of the
317 // argument and not the original.
318 COMPILE_ASSERT(
319 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
320 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
321 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
322 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ||
323 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value ),
324 do_not_bind_functions_with_nonconst_ref);
325
326 // For methods, we need to be careful for parameter 1. We do not require
327 // a scoped_refptr because BindState<> itself takes care of AddRef() for
328 // methods. We also disallow binding of an array as the method's target
329 // object.
330 COMPILE_ASSERT(
331 internal::HasIsMethodTag<RunnableType>::value ||
332 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
333 p1_is_refcounted_type_and_needs_scoped_refptr);
334 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
335 !is_array<P1>::value,
336 first_bound_argument_to_method_cannot_be_array);
337 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
338 p2_is_refcounted_type_and_needs_scoped_refptr);
339 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
340 p3_is_refcounted_type_and_needs_scoped_refptr);
341 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
342 p4_is_refcounted_type_and_needs_scoped_refptr);
343 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
344 p5_is_refcounted_type_and_needs_scoped_refptr);
345 typedef internal::BindState<RunnableType, RunType,
346 void(typename internal::CallbackParamTraits<P1>::StorageType,
347 typename internal::CallbackParamTraits<P2>::StorageType,
348 typename internal::CallbackParamTraits<P3>::StorageType,
349 typename internal::CallbackParamTraits<P4>::StorageType,
350 typename internal::CallbackParamTraits<P5>::StorageType)> BindState;
351
352
353 return Callback<typename BindState::UnboundRunType>(
354 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5));
355 }
356
357 template <typename Functor, typename P1, typename P2, typename P3, typename P4,
358 typename P5, typename P6>
359 base::Callback<
360 typename internal::BindState<
361 typename internal::FunctorTraits<Functor>::RunnableType,
362 typename internal::FunctorTraits<Functor>::RunType,
363 void(typename internal::CallbackParamTraits<P1>::StorageType,
364 typename internal::CallbackParamTraits<P2>::StorageType,
365 typename internal::CallbackParamTraits<P3>::StorageType,
366 typename internal::CallbackParamTraits<P4>::StorageType,
367 typename internal::CallbackParamTraits<P5>::StorageType,
368 typename internal::CallbackParamTraits<P6>::StorageType)>
369 ::UnboundRunType>
370 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
371 const P5& p5, const P6& p6) {
372 // Typedefs for how to store and run the functor.
373 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
374 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
375
376 // Use RunnableType::RunType instead of RunType above because our
377 // checks should below for bound references need to know what the actual
378 // functor is going to interpret the argument as.
379 typedef internal::FunctionTraits<typename RunnableType::RunType>
380 BoundFunctorTraits;
381
382 // Do not allow binding a non-const reference parameter. Non-const reference
383 // parameters are disallowed by the Google style guide. Also, binding a
384 // non-const reference parameter can make for subtle bugs because the
385 // invoked function will receive a reference to the stored copy of the
386 // argument and not the original.
387 COMPILE_ASSERT(
388 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
389 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
390 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
391 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ||
392 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value ||
393 is_non_const_reference<typename BoundFunctorTraits::A6Type>::value ),
394 do_not_bind_functions_with_nonconst_ref);
395
396 // For methods, we need to be careful for parameter 1. We do not require
397 // a scoped_refptr because BindState<> itself takes care of AddRef() for
398 // methods. We also disallow binding of an array as the method's target
399 // object.
400 COMPILE_ASSERT(
401 internal::HasIsMethodTag<RunnableType>::value ||
402 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
403 p1_is_refcounted_type_and_needs_scoped_refptr);
404 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
405 !is_array<P1>::value,
406 first_bound_argument_to_method_cannot_be_array);
407 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
408 p2_is_refcounted_type_and_needs_scoped_refptr);
409 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
410 p3_is_refcounted_type_and_needs_scoped_refptr);
411 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
412 p4_is_refcounted_type_and_needs_scoped_refptr);
413 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
414 p5_is_refcounted_type_and_needs_scoped_refptr);
415 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P6>::value,
416 p6_is_refcounted_type_and_needs_scoped_refptr);
417 typedef internal::BindState<RunnableType, RunType,
418 void(typename internal::CallbackParamTraits<P1>::StorageType,
419 typename internal::CallbackParamTraits<P2>::StorageType,
420 typename internal::CallbackParamTraits<P3>::StorageType,
421 typename internal::CallbackParamTraits<P4>::StorageType,
422 typename internal::CallbackParamTraits<P5>::StorageType,
423 typename internal::CallbackParamTraits<P6>::StorageType)> BindState;
424
425
426 return Callback<typename BindState::UnboundRunType>(
427 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6));
428 }
429
430 template <typename Functor, typename P1, typename P2, typename P3, typename P4,
431 typename P5, typename P6, typename P7>
432 base::Callback<
433 typename internal::BindState<
434 typename internal::FunctorTraits<Functor>::RunnableType,
435 typename internal::FunctorTraits<Functor>::RunType,
436 void(typename internal::CallbackParamTraits<P1>::StorageType,
437 typename internal::CallbackParamTraits<P2>::StorageType,
438 typename internal::CallbackParamTraits<P3>::StorageType,
439 typename internal::CallbackParamTraits<P4>::StorageType,
440 typename internal::CallbackParamTraits<P5>::StorageType,
441 typename internal::CallbackParamTraits<P6>::StorageType,
442 typename internal::CallbackParamTraits<P7>::StorageType)>
443 ::UnboundRunType>
444 Bind(Functor functor, const P1& p1, const P2& p2, const P3& p3, const P4& p4,
445 const P5& p5, const P6& p6, const P7& p7) {
446 // Typedefs for how to store and run the functor.
447 typedef typename internal::FunctorTraits<Functor>::RunnableType RunnableType;
448 typedef typename internal::FunctorTraits<Functor>::RunType RunType;
449
450 // Use RunnableType::RunType instead of RunType above because our
451 // checks should below for bound references need to know what the actual
452 // functor is going to interpret the argument as.
453 typedef internal::FunctionTraits<typename RunnableType::RunType>
454 BoundFunctorTraits;
455
456 // Do not allow binding a non-const reference parameter. Non-const reference
457 // parameters are disallowed by the Google style guide. Also, binding a
458 // non-const reference parameter can make for subtle bugs because the
459 // invoked function will receive a reference to the stored copy of the
460 // argument and not the original.
461 COMPILE_ASSERT(
462 !(is_non_const_reference<typename BoundFunctorTraits::A1Type>::value ||
463 is_non_const_reference<typename BoundFunctorTraits::A2Type>::value ||
464 is_non_const_reference<typename BoundFunctorTraits::A3Type>::value ||
465 is_non_const_reference<typename BoundFunctorTraits::A4Type>::value ||
466 is_non_const_reference<typename BoundFunctorTraits::A5Type>::value ||
467 is_non_const_reference<typename BoundFunctorTraits::A6Type>::value ||
468 is_non_const_reference<typename BoundFunctorTraits::A7Type>::value ),
469 do_not_bind_functions_with_nonconst_ref);
470
471 // For methods, we need to be careful for parameter 1. We do not require
472 // a scoped_refptr because BindState<> itself takes care of AddRef() for
473 // methods. We also disallow binding of an array as the method's target
474 // object.
475 COMPILE_ASSERT(
476 internal::HasIsMethodTag<RunnableType>::value ||
477 !internal::NeedsScopedRefptrButGetsRawPtr<P1>::value,
478 p1_is_refcounted_type_and_needs_scoped_refptr);
479 COMPILE_ASSERT(!internal::HasIsMethodTag<RunnableType>::value ||
480 !is_array<P1>::value,
481 first_bound_argument_to_method_cannot_be_array);
482 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P2>::value,
483 p2_is_refcounted_type_and_needs_scoped_refptr);
484 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P3>::value,
485 p3_is_refcounted_type_and_needs_scoped_refptr);
486 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P4>::value,
487 p4_is_refcounted_type_and_needs_scoped_refptr);
488 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P5>::value,
489 p5_is_refcounted_type_and_needs_scoped_refptr);
490 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P6>::value,
491 p6_is_refcounted_type_and_needs_scoped_refptr);
492 COMPILE_ASSERT(!internal::NeedsScopedRefptrButGetsRawPtr<P7>::value,
493 p7_is_refcounted_type_and_needs_scoped_refptr);
494 typedef internal::BindState<RunnableType, RunType,
495 void(typename internal::CallbackParamTraits<P1>::StorageType,
496 typename internal::CallbackParamTraits<P2>::StorageType,
497 typename internal::CallbackParamTraits<P3>::StorageType,
498 typename internal::CallbackParamTraits<P4>::StorageType,
499 typename internal::CallbackParamTraits<P5>::StorageType,
500 typename internal::CallbackParamTraits<P6>::StorageType,
501 typename internal::CallbackParamTraits<P7>::StorageType)> BindState;
502
503
504 return Callback<typename BindState::UnboundRunType>(
505 new BindState(internal::MakeRunnable(functor), p1, p2, p3, p4, p5, p6,
506 p7));
507 } 110 }
508 111
509 } // namespace base 112 } // namespace base
510 113
511 #endif // BASE_BIND_H_ 114 #endif // BASE_BIND_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/bind.h.pump » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698