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
3 // found in the LICENSE file.
5 // A Tuple is a generic templatized container, similar in concept to std::pair.
6 // There are classes Tuple0 to Tuple6, cooresponding to the number of elements
7 // it contains. The convenient MakeTuple() function takes 0 to 6 arguments,
8 // and will construct and return the appropriate Tuple object. The functions
9 // DispatchToMethod and DispatchToFunction take a function pointer or instance
10 // and method pointer, and unpack a tuple into arguments to the call.
12 // Tuple elements are copied by value, and stored in the tuple. See the unit
13 // tests for more details of how/when the values are copied.
16 // // These two methods of creating a Tuple are identical.
17 // Tuple2<int, const char*> tuple_a(1, "wee");
18 // Tuple2<int, const char*> tuple_b = MakeTuple(1, "wee");
20 // void SomeFunc(int a, const char* b) { }
21 // DispatchToFunction(&SomeFunc, tuple_a); // SomeFunc(1, "wee")
22 // DispatchToFunction(
23 // &SomeFunc, MakeTuple(10, "foo")); // SomeFunc(10, "foo")
25 // struct { void SomeMeth(int a, int b, int c) { } } foo;
26 // DispatchToMethod(&foo, &Foo::SomeMeth, MakeTuple(1, 2, 3));
27 // // foo->SomeMeth(1, 2, 3);
29 #ifndef BASE_TUPLE_H__
30 #define BASE_TUPLE_H__
32 // Traits ----------------------------------------------------------------------
34 // A simple traits class for tuple arguments.
36 // ValueType: the bare, nonref version of a type (same as the type for nonrefs).
37 // RefType: the ref version of a type (same as the type for refs).
38 // ParamType: what type to pass to functions (refs should not be constified).
44 typedef const P
& ParamType
;
48 struct TupleTraits
<P
&> {
55 struct TupleTypes
{ };
57 // Tuple -----------------------------------------------------------------------
59 // This set of classes is useful for bundling 0 or more heterogeneous data types
60 // into a single variable. The advantage of this is that it greatly simplifies
61 // function objects that need to take an arbitrary number of parameters; see
62 // RunnableMethod and IPC::MessageWithTuple.
64 // Tuple0 is supplied to act as a 'void' type. It can be used, for example,
65 // when dispatching to a function that accepts no arguments (see the
66 // Dispatchers below).
67 // Tuple1<A> is rarely useful. One such use is when A is non-const ref that you
68 // want filled by the dispatchee, and the tuple is merely a container for that
69 // output (a "tier"). See MakeRefTuple and its usages.
72 typedef Tuple0 ValueTuple
;
73 typedef Tuple0 RefTuple
;
74 typedef Tuple0 ParamTuple
;
83 explicit Tuple1(typename TupleTraits
<A
>::ParamType a
) : a(a
) {}
88 template <class A
, class B
>
95 Tuple2(typename TupleTraits
<A
>::ParamType a
,
96 typename TupleTraits
<B
>::ParamType b
)
104 template <class A
, class B
, class C
>
112 Tuple3(typename TupleTraits
<A
>::ParamType a
,
113 typename TupleTraits
<B
>::ParamType b
,
114 typename TupleTraits
<C
>::ParamType c
)
123 template <class A
, class B
, class C
, class D
>
132 Tuple4(typename TupleTraits
<A
>::ParamType a
,
133 typename TupleTraits
<B
>::ParamType b
,
134 typename TupleTraits
<C
>::ParamType c
,
135 typename TupleTraits
<D
>::ParamType d
)
136 : a(a
), b(b
), c(c
), d(d
) {
145 template <class A
, class B
, class C
, class D
, class E
>
155 Tuple5(typename TupleTraits
<A
>::ParamType a
,
156 typename TupleTraits
<B
>::ParamType b
,
157 typename TupleTraits
<C
>::ParamType c
,
158 typename TupleTraits
<D
>::ParamType d
,
159 typename TupleTraits
<E
>::ParamType e
)
160 : a(a
), b(b
), c(c
), d(d
), e(e
) {
170 template <class A
, class B
, class C
, class D
, class E
, class F
>
181 Tuple6(typename TupleTraits
<A
>::ParamType a
,
182 typename TupleTraits
<B
>::ParamType b
,
183 typename TupleTraits
<C
>::ParamType c
,
184 typename TupleTraits
<D
>::ParamType d
,
185 typename TupleTraits
<E
>::ParamType e
,
186 typename TupleTraits
<F
>::ParamType f
)
187 : a(a
), b(b
), c(c
), d(d
), e(e
), f(f
) {
198 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
>
210 Tuple7(typename TupleTraits
<A
>::ParamType a
,
211 typename TupleTraits
<B
>::ParamType b
,
212 typename TupleTraits
<C
>::ParamType c
,
213 typename TupleTraits
<D
>::ParamType d
,
214 typename TupleTraits
<E
>::ParamType e
,
215 typename TupleTraits
<F
>::ParamType f
,
216 typename TupleTraits
<G
>::ParamType g
)
217 : a(a
), b(b
), c(c
), d(d
), e(e
), f(f
), g(g
) {
229 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
,
243 Tuple8(typename TupleTraits
<A
>::ParamType a
,
244 typename TupleTraits
<B
>::ParamType b
,
245 typename TupleTraits
<C
>::ParamType c
,
246 typename TupleTraits
<D
>::ParamType d
,
247 typename TupleTraits
<E
>::ParamType e
,
248 typename TupleTraits
<F
>::ParamType f
,
249 typename TupleTraits
<G
>::ParamType g
,
250 typename TupleTraits
<H
>::ParamType h
)
251 : a(a
), b(b
), c(c
), d(d
), e(e
), f(f
), g(g
), h(h
) {
264 // Tuple types ----------------------------------------------------------------
266 // Allows for selection of ValueTuple/RefTuple/ParamTuple without needing the
267 // definitions of class types the tuple takes as parameters.
270 struct TupleTypes
< Tuple0
> {
271 typedef Tuple0 ValueTuple
;
272 typedef Tuple0 RefTuple
;
273 typedef Tuple0 ParamTuple
;
277 struct TupleTypes
< Tuple1
<A
> > {
278 typedef Tuple1
<typename TupleTraits
<A
>::ValueType
> ValueTuple
;
279 typedef Tuple1
<typename TupleTraits
<A
>::RefType
> RefTuple
;
280 typedef Tuple1
<typename TupleTraits
<A
>::ParamType
> ParamTuple
;
283 template <class A
, class B
>
284 struct TupleTypes
< Tuple2
<A
, B
> > {
285 typedef Tuple2
<typename TupleTraits
<A
>::ValueType
,
286 typename TupleTraits
<B
>::ValueType
> ValueTuple
;
287 typedef Tuple2
<typename TupleTraits
<A
>::RefType
,
288 typename TupleTraits
<B
>::RefType
> RefTuple
;
289 typedef Tuple2
<typename TupleTraits
<A
>::ParamType
,
290 typename TupleTraits
<B
>::ParamType
> ParamTuple
;
293 template <class A
, class B
, class C
>
294 struct TupleTypes
< Tuple3
<A
, B
, C
> > {
295 typedef Tuple3
<typename TupleTraits
<A
>::ValueType
,
296 typename TupleTraits
<B
>::ValueType
,
297 typename TupleTraits
<C
>::ValueType
> ValueTuple
;
298 typedef Tuple3
<typename TupleTraits
<A
>::RefType
,
299 typename TupleTraits
<B
>::RefType
,
300 typename TupleTraits
<C
>::RefType
> RefTuple
;
301 typedef Tuple3
<typename TupleTraits
<A
>::ParamType
,
302 typename TupleTraits
<B
>::ParamType
,
303 typename TupleTraits
<C
>::ParamType
> ParamTuple
;
306 template <class A
, class B
, class C
, class D
>
307 struct TupleTypes
< Tuple4
<A
, B
, C
, D
> > {
308 typedef Tuple4
<typename TupleTraits
<A
>::ValueType
,
309 typename TupleTraits
<B
>::ValueType
,
310 typename TupleTraits
<C
>::ValueType
,
311 typename TupleTraits
<D
>::ValueType
> ValueTuple
;
312 typedef Tuple4
<typename TupleTraits
<A
>::RefType
,
313 typename TupleTraits
<B
>::RefType
,
314 typename TupleTraits
<C
>::RefType
,
315 typename TupleTraits
<D
>::RefType
> RefTuple
;
316 typedef Tuple4
<typename TupleTraits
<A
>::ParamType
,
317 typename TupleTraits
<B
>::ParamType
,
318 typename TupleTraits
<C
>::ParamType
,
319 typename TupleTraits
<D
>::ParamType
> ParamTuple
;
322 template <class A
, class B
, class C
, class D
, class E
>
323 struct TupleTypes
< Tuple5
<A
, B
, C
, D
, E
> > {
324 typedef Tuple5
<typename TupleTraits
<A
>::ValueType
,
325 typename TupleTraits
<B
>::ValueType
,
326 typename TupleTraits
<C
>::ValueType
,
327 typename TupleTraits
<D
>::ValueType
,
328 typename TupleTraits
<E
>::ValueType
> ValueTuple
;
329 typedef Tuple5
<typename TupleTraits
<A
>::RefType
,
330 typename TupleTraits
<B
>::RefType
,
331 typename TupleTraits
<C
>::RefType
,
332 typename TupleTraits
<D
>::RefType
,
333 typename TupleTraits
<E
>::RefType
> RefTuple
;
334 typedef Tuple5
<typename TupleTraits
<A
>::ParamType
,
335 typename TupleTraits
<B
>::ParamType
,
336 typename TupleTraits
<C
>::ParamType
,
337 typename TupleTraits
<D
>::ParamType
,
338 typename TupleTraits
<E
>::ParamType
> ParamTuple
;
341 template <class A
, class B
, class C
, class D
, class E
, class F
>
342 struct TupleTypes
< Tuple6
<A
, B
, C
, D
, E
, F
> > {
343 typedef Tuple6
<typename TupleTraits
<A
>::ValueType
,
344 typename TupleTraits
<B
>::ValueType
,
345 typename TupleTraits
<C
>::ValueType
,
346 typename TupleTraits
<D
>::ValueType
,
347 typename TupleTraits
<E
>::ValueType
,
348 typename TupleTraits
<F
>::ValueType
> ValueTuple
;
349 typedef Tuple6
<typename TupleTraits
<A
>::RefType
,
350 typename TupleTraits
<B
>::RefType
,
351 typename TupleTraits
<C
>::RefType
,
352 typename TupleTraits
<D
>::RefType
,
353 typename TupleTraits
<E
>::RefType
,
354 typename TupleTraits
<F
>::RefType
> RefTuple
;
355 typedef Tuple6
<typename TupleTraits
<A
>::ParamType
,
356 typename TupleTraits
<B
>::ParamType
,
357 typename TupleTraits
<C
>::ParamType
,
358 typename TupleTraits
<D
>::ParamType
,
359 typename TupleTraits
<E
>::ParamType
,
360 typename TupleTraits
<F
>::ParamType
> ParamTuple
;
363 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
>
364 struct TupleTypes
< Tuple7
<A
, B
, C
, D
, E
, F
, G
> > {
365 typedef Tuple7
<typename TupleTraits
<A
>::ValueType
,
366 typename TupleTraits
<B
>::ValueType
,
367 typename TupleTraits
<C
>::ValueType
,
368 typename TupleTraits
<D
>::ValueType
,
369 typename TupleTraits
<E
>::ValueType
,
370 typename TupleTraits
<F
>::ValueType
,
371 typename TupleTraits
<G
>::ValueType
> ValueTuple
;
372 typedef Tuple7
<typename TupleTraits
<A
>::RefType
,
373 typename TupleTraits
<B
>::RefType
,
374 typename TupleTraits
<C
>::RefType
,
375 typename TupleTraits
<D
>::RefType
,
376 typename TupleTraits
<E
>::RefType
,
377 typename TupleTraits
<F
>::RefType
,
378 typename TupleTraits
<G
>::RefType
> RefTuple
;
379 typedef Tuple7
<typename TupleTraits
<A
>::ParamType
,
380 typename TupleTraits
<B
>::ParamType
,
381 typename TupleTraits
<C
>::ParamType
,
382 typename TupleTraits
<D
>::ParamType
,
383 typename TupleTraits
<E
>::ParamType
,
384 typename TupleTraits
<F
>::ParamType
,
385 typename TupleTraits
<G
>::ParamType
> ParamTuple
;
388 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
,
390 struct TupleTypes
< Tuple8
<A
, B
, C
, D
, E
, F
, G
, H
> > {
391 typedef Tuple8
<typename TupleTraits
<A
>::ValueType
,
392 typename TupleTraits
<B
>::ValueType
,
393 typename TupleTraits
<C
>::ValueType
,
394 typename TupleTraits
<D
>::ValueType
,
395 typename TupleTraits
<E
>::ValueType
,
396 typename TupleTraits
<F
>::ValueType
,
397 typename TupleTraits
<G
>::ValueType
,
398 typename TupleTraits
<H
>::ValueType
> ValueTuple
;
399 typedef Tuple8
<typename TupleTraits
<A
>::RefType
,
400 typename TupleTraits
<B
>::RefType
,
401 typename TupleTraits
<C
>::RefType
,
402 typename TupleTraits
<D
>::RefType
,
403 typename TupleTraits
<E
>::RefType
,
404 typename TupleTraits
<F
>::RefType
,
405 typename TupleTraits
<G
>::RefType
,
406 typename TupleTraits
<H
>::RefType
> RefTuple
;
407 typedef Tuple8
<typename TupleTraits
<A
>::ParamType
,
408 typename TupleTraits
<B
>::ParamType
,
409 typename TupleTraits
<C
>::ParamType
,
410 typename TupleTraits
<D
>::ParamType
,
411 typename TupleTraits
<E
>::ParamType
,
412 typename TupleTraits
<F
>::ParamType
,
413 typename TupleTraits
<G
>::ParamType
,
414 typename TupleTraits
<H
>::ParamType
> ParamTuple
;
417 // Tuple creators -------------------------------------------------------------
419 // Helper functions for constructing tuples while inferring the template
422 inline Tuple0
MakeTuple() {
427 inline Tuple1
<A
> MakeTuple(const A
& a
) {
431 template <class A
, class B
>
432 inline Tuple2
<A
, B
> MakeTuple(const A
& a
, const B
& b
) {
433 return Tuple2
<A
, B
>(a
, b
);
436 template <class A
, class B
, class C
>
437 inline Tuple3
<A
, B
, C
> MakeTuple(const A
& a
, const B
& b
, const C
& c
) {
438 return Tuple3
<A
, B
, C
>(a
, b
, c
);
441 template <class A
, class B
, class C
, class D
>
442 inline Tuple4
<A
, B
, C
, D
> MakeTuple(const A
& a
, const B
& b
, const C
& c
,
444 return Tuple4
<A
, B
, C
, D
>(a
, b
, c
, d
);
447 template <class A
, class B
, class C
, class D
, class E
>
448 inline Tuple5
<A
, B
, C
, D
, E
> MakeTuple(const A
& a
, const B
& b
, const C
& c
,
449 const D
& d
, const E
& e
) {
450 return Tuple5
<A
, B
, C
, D
, E
>(a
, b
, c
, d
, e
);
453 template <class A
, class B
, class C
, class D
, class E
, class F
>
454 inline Tuple6
<A
, B
, C
, D
, E
, F
> MakeTuple(const A
& a
, const B
& b
, const C
& c
,
455 const D
& d
, const E
& e
, const F
& f
) {
456 return Tuple6
<A
, B
, C
, D
, E
, F
>(a
, b
, c
, d
, e
, f
);
459 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
>
460 inline Tuple7
<A
, B
, C
, D
, E
, F
, G
> MakeTuple(const A
& a
, const B
& b
, const C
& c
,
461 const D
& d
, const E
& e
, const F
& f
,
463 return Tuple7
<A
, B
, C
, D
, E
, F
, G
>(a
, b
, c
, d
, e
, f
, g
);
466 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
,
468 inline Tuple8
<A
, B
, C
, D
, E
, F
, G
, H
> MakeTuple(const A
& a
, const B
& b
,
469 const C
& c
, const D
& d
,
470 const E
& e
, const F
& f
,
471 const G
& g
, const H
& h
) {
472 return Tuple8
<A
, B
, C
, D
, E
, F
, G
, H
>(a
, b
, c
, d
, e
, f
, g
, h
);
475 // The following set of helpers make what Boost refers to as "Tiers" - a tuple
479 inline Tuple1
<A
&> MakeRefTuple(A
& a
) {
480 return Tuple1
<A
&>(a
);
483 template <class A
, class B
>
484 inline Tuple2
<A
&, B
&> MakeRefTuple(A
& a
, B
& b
) {
485 return Tuple2
<A
&, B
&>(a
, b
);
488 template <class A
, class B
, class C
>
489 inline Tuple3
<A
&, B
&, C
&> MakeRefTuple(A
& a
, B
& b
, C
& c
) {
490 return Tuple3
<A
&, B
&, C
&>(a
, b
, c
);
493 template <class A
, class B
, class C
, class D
>
494 inline Tuple4
<A
&, B
&, C
&, D
&> MakeRefTuple(A
& a
, B
& b
, C
& c
, D
& d
) {
495 return Tuple4
<A
&, B
&, C
&, D
&>(a
, b
, c
, d
);
498 template <class A
, class B
, class C
, class D
, class E
>
499 inline Tuple5
<A
&, B
&, C
&, D
&, E
&> MakeRefTuple(A
& a
, B
& b
, C
& c
, D
& d
, E
& e
) {
500 return Tuple5
<A
&, B
&, C
&, D
&, E
&>(a
, b
, c
, d
, e
);
503 template <class A
, class B
, class C
, class D
, class E
, class F
>
504 inline Tuple6
<A
&, B
&, C
&, D
&, E
&, F
&> MakeRefTuple(A
& a
, B
& b
, C
& c
, D
& d
, E
& e
,
506 return Tuple6
<A
&, B
&, C
&, D
&, E
&, F
&>(a
, b
, c
, d
, e
, f
);
509 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
>
510 inline Tuple7
<A
&, B
&, C
&, D
&, E
&, F
&, G
&> MakeRefTuple(A
& a
, B
& b
, C
& c
, D
& d
,
512 return Tuple7
<A
&, B
&, C
&, D
&, E
&, F
&, G
&>(a
, b
, c
, d
, e
, f
, g
);
515 template <class A
, class B
, class C
, class D
, class E
, class F
, class G
,
517 inline Tuple8
<A
&, B
&, C
&, D
&, E
&, F
&, G
&, H
&> MakeRefTuple(A
& a
, B
& b
, C
& c
,
520 return Tuple8
<A
&, B
&, C
&, D
&, E
&, F
&, G
&, H
&>(a
, b
, c
, d
, e
, f
, g
, h
);
523 // Dispatchers ----------------------------------------------------------------
525 // Helper functions that call the given method on an object, with the unpacked
526 // tuple arguments. Notice that they all have the same number of arguments,
527 // so you need only write:
528 // DispatchToMethod(object, &Object::method, args);
529 // This is very useful for templated dispatchers, since they don't need to know
530 // what type |args| is.
532 // Non-Static Dispatchers with no out params.
534 template <class ObjT
, class Method
>
535 inline void DispatchToMethod(ObjT
* obj
, Method method
, const Tuple0
& arg
) {
539 template <class ObjT
, class Method
, class A
>
540 inline void DispatchToMethod(ObjT
* obj
, Method method
, const A
& arg
) {
544 template <class ObjT
, class Method
, class A
>
545 inline void DispatchToMethod(ObjT
* obj
, Method method
, const Tuple1
<A
>& arg
) {
546 (obj
->*method
)(arg
.a
);
549 template<class ObjT
, class Method
, class A
, class B
>
550 inline void DispatchToMethod(ObjT
* obj
,
552 const Tuple2
<A
, B
>& arg
) {
553 (obj
->*method
)(arg
.a
, arg
.b
);
556 template<class ObjT
, class Method
, class A
, class B
, class C
>
557 inline void DispatchToMethod(ObjT
* obj
, Method method
,
558 const Tuple3
<A
, B
, C
>& arg
) {
559 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
);
562 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
>
563 inline void DispatchToMethod(ObjT
* obj
, Method method
,
564 const Tuple4
<A
, B
, C
, D
>& arg
) {
565 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
);
568 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
, class E
>
569 inline void DispatchToMethod(ObjT
* obj
, Method method
,
570 const Tuple5
<A
, B
, C
, D
, E
>& arg
) {
571 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
);
574 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
, class E
,
576 inline void DispatchToMethod(ObjT
* obj
, Method method
,
577 const Tuple6
<A
, B
, C
, D
, E
, F
>& arg
) {
578 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
, arg
.f
);
581 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
, class E
,
583 inline void DispatchToMethod(ObjT
* obj
, Method method
,
584 const Tuple7
<A
, B
, C
, D
, E
, F
, G
>& arg
) {
585 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
, arg
.f
, arg
.g
);
588 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
, class E
,
589 class F
, class G
, class H
>
590 inline void DispatchToMethod(ObjT
* obj
, Method method
,
591 const Tuple8
<A
, B
, C
, D
, E
, F
, G
, H
>& arg
) {
592 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
, arg
.f
, arg
.g
, arg
.h
);
595 // Static Dispatchers with no out params.
597 template <class Function
>
598 inline void DispatchToFunction(Function function
, const Tuple0
& arg
) {
602 template <class Function
, class A
>
603 inline void DispatchToFunction(Function function
, const A
& arg
) {
607 template <class Function
, class A
>
608 inline void DispatchToFunction(Function function
, const Tuple1
<A
>& arg
) {
612 template<class Function
, class A
, class B
>
613 inline void DispatchToFunction(Function function
, const Tuple2
<A
, B
>& arg
) {
614 (*function
)(arg
.a
, arg
.b
);
617 template<class Function
, class A
, class B
, class C
>
618 inline void DispatchToFunction(Function function
, const Tuple3
<A
, B
, C
>& arg
) {
619 (*function
)(arg
.a
, arg
.b
, arg
.c
);
622 template<class Function
, class A
, class B
, class C
, class D
>
623 inline void DispatchToFunction(Function function
,
624 const Tuple4
<A
, B
, C
, D
>& arg
) {
625 (*function
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
);
628 template<class Function
, class A
, class B
, class C
, class D
, class E
>
629 inline void DispatchToFunction(Function function
,
630 const Tuple5
<A
, B
, C
, D
, E
>& arg
) {
631 (*function
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
);
634 template<class Function
, class A
, class B
, class C
, class D
, class E
, class F
>
635 inline void DispatchToFunction(Function function
,
636 const Tuple6
<A
, B
, C
, D
, E
, F
>& arg
) {
637 (*function
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
, arg
.f
);
640 template<class Function
, class A
, class B
, class C
, class D
, class E
, class F
,
642 inline void DispatchToFunction(Function function
,
643 const Tuple7
<A
, B
, C
, D
, E
, F
, G
>& arg
) {
644 (*function
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
, arg
.f
, arg
.g
);
647 template<class Function
, class A
, class B
, class C
, class D
, class E
, class F
,
649 inline void DispatchToFunction(Function function
,
650 const Tuple8
<A
, B
, C
, D
, E
, F
, G
, H
>& arg
) {
651 (*function
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
, arg
.f
, arg
.g
, arg
.h
);
654 // Dispatchers with 0 out param (as a Tuple0).
656 template <class ObjT
, class Method
>
657 inline void DispatchToMethod(ObjT
* obj
,
659 const Tuple0
& arg
, Tuple0
*) {
663 template <class ObjT
, class Method
, class A
>
664 inline void DispatchToMethod(ObjT
* obj
, Method method
, const A
& arg
, Tuple0
*) {
668 template <class ObjT
, class Method
, class A
>
669 inline void DispatchToMethod(ObjT
* obj
,
671 const Tuple1
<A
>& arg
, Tuple0
*) {
672 (obj
->*method
)(arg
.a
);
675 template<class ObjT
, class Method
, class A
, class B
>
676 inline void DispatchToMethod(ObjT
* obj
,
678 const Tuple2
<A
, B
>& arg
, Tuple0
*) {
679 (obj
->*method
)(arg
.a
, arg
.b
);
682 template<class ObjT
, class Method
, class A
, class B
, class C
>
683 inline void DispatchToMethod(ObjT
* obj
, Method method
,
684 const Tuple3
<A
, B
, C
>& arg
, Tuple0
*) {
685 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
);
688 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
>
689 inline void DispatchToMethod(ObjT
* obj
, Method method
,
690 const Tuple4
<A
, B
, C
, D
>& arg
, Tuple0
*) {
691 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
);
694 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
, class E
>
695 inline void DispatchToMethod(ObjT
* obj
, Method method
,
696 const Tuple5
<A
, B
, C
, D
, E
>& arg
, Tuple0
*) {
697 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
);
700 template<class ObjT
, class Method
, class A
, class B
, class C
, class D
, class E
,
702 inline void DispatchToMethod(ObjT
* obj
, Method method
,
703 const Tuple6
<A
, B
, C
, D
, E
, F
>& arg
, Tuple0
*) {
704 (obj
->*method
)(arg
.a
, arg
.b
, arg
.c
, arg
.d
, arg
.e
, arg
.f
);
707 // Dispatchers with 1 out param.
709 template<class ObjT
, class Method
,
711 inline void DispatchToMethod(ObjT
* obj
, Method method
,
714 (obj
->*method
)(&out
->a
);
717 template<class ObjT
, class Method
, class InA
,
719 inline void DispatchToMethod(ObjT
* obj
, Method method
,
722 (obj
->*method
)(in
, &out
->a
);
725 template<class ObjT
, class Method
, class InA
,
727 inline void DispatchToMethod(ObjT
* obj
, Method method
,
728 const Tuple1
<InA
>& in
,
730 (obj
->*method
)(in
.a
, &out
->a
);
733 template<class ObjT
, class Method
, class InA
, class InB
,
735 inline void DispatchToMethod(ObjT
* obj
, Method method
,
736 const Tuple2
<InA
, InB
>& in
,
738 (obj
->*method
)(in
.a
, in
.b
, &out
->a
);
741 template<class ObjT
, class Method
, class InA
, class InB
, class InC
,
743 inline void DispatchToMethod(ObjT
* obj
, Method method
,
744 const Tuple3
<InA
, InB
, InC
>& in
,
746 (obj
->*method
)(in
.a
, in
.b
, in
.c
, &out
->a
);
749 template<class ObjT
, class Method
, class InA
, class InB
, class InC
, class InD
,
751 inline void DispatchToMethod(ObjT
* obj
, Method method
,
752 const Tuple4
<InA
, InB
, InC
, InD
>& in
,
754 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, &out
->a
);
757 template<class ObjT
, class Method
, class InA
, class InB
, class InC
, class InD
,
758 class InE
, class OutA
>
759 inline void DispatchToMethod(ObjT
* obj
, Method method
,
760 const Tuple5
<InA
, InB
, InC
, InD
, InE
>& in
,
762 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, &out
->a
);
765 template<class ObjT
, class Method
,
766 class InA
, class InB
, class InC
, class InD
, class InE
, class InF
,
768 inline void DispatchToMethod(ObjT
* obj
, Method method
,
769 const Tuple6
<InA
, InB
, InC
, InD
, InE
, InF
>& in
,
771 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, in
.f
, &out
->a
);
774 // Dispatchers with 2 out params.
776 template<class ObjT
, class Method
,
777 class OutA
, class OutB
>
778 inline void DispatchToMethod(ObjT
* obj
, Method method
,
780 Tuple2
<OutA
, OutB
>* out
) {
781 (obj
->*method
)(&out
->a
, &out
->b
);
784 template<class ObjT
, class Method
, class InA
,
785 class OutA
, class OutB
>
786 inline void DispatchToMethod(ObjT
* obj
, Method method
,
788 Tuple2
<OutA
, OutB
>* out
) {
789 (obj
->*method
)(in
, &out
->a
, &out
->b
);
792 template<class ObjT
, class Method
, class InA
,
793 class OutA
, class OutB
>
794 inline void DispatchToMethod(ObjT
* obj
, Method method
,
795 const Tuple1
<InA
>& in
,
796 Tuple2
<OutA
, OutB
>* out
) {
797 (obj
->*method
)(in
.a
, &out
->a
, &out
->b
);
800 template<class ObjT
, class Method
, class InA
, class InB
,
801 class OutA
, class OutB
>
802 inline void DispatchToMethod(ObjT
* obj
, Method method
,
803 const Tuple2
<InA
, InB
>& in
,
804 Tuple2
<OutA
, OutB
>* out
) {
805 (obj
->*method
)(in
.a
, in
.b
, &out
->a
, &out
->b
);
808 template<class ObjT
, class Method
, class InA
, class InB
, class InC
,
809 class OutA
, class OutB
>
810 inline void DispatchToMethod(ObjT
* obj
, Method method
,
811 const Tuple3
<InA
, InB
, InC
>& in
,
812 Tuple2
<OutA
, OutB
>* out
) {
813 (obj
->*method
)(in
.a
, in
.b
, in
.c
, &out
->a
, &out
->b
);
816 template<class ObjT
, class Method
, class InA
, class InB
, class InC
, class InD
,
817 class OutA
, class OutB
>
818 inline void DispatchToMethod(ObjT
* obj
, Method method
,
819 const Tuple4
<InA
, InB
, InC
, InD
>& in
,
820 Tuple2
<OutA
, OutB
>* out
) {
821 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, &out
->a
, &out
->b
);
824 template<class ObjT
, class Method
,
825 class InA
, class InB
, class InC
, class InD
, class InE
,
826 class OutA
, class OutB
>
827 inline void DispatchToMethod(ObjT
* obj
, Method method
,
828 const Tuple5
<InA
, InB
, InC
, InD
, InE
>& in
,
829 Tuple2
<OutA
, OutB
>* out
) {
830 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, &out
->a
, &out
->b
);
833 template<class ObjT
, class Method
,
834 class InA
, class InB
, class InC
, class InD
, class InE
, class InF
,
835 class OutA
, class OutB
>
836 inline void DispatchToMethod(ObjT
* obj
, Method method
,
837 const Tuple6
<InA
, InB
, InC
, InD
, InE
, InF
>& in
,
838 Tuple2
<OutA
, OutB
>* out
) {
839 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, in
.f
, &out
->a
, &out
->b
);
842 // Dispatchers with 3 out params.
844 template<class ObjT
, class Method
,
845 class OutA
, class OutB
, class OutC
>
846 inline void DispatchToMethod(ObjT
* obj
, Method method
,
848 Tuple3
<OutA
, OutB
, OutC
>* out
) {
849 (obj
->*method
)(&out
->a
, &out
->b
, &out
->c
);
852 template<class ObjT
, class Method
, class InA
,
853 class OutA
, class OutB
, class OutC
>
854 inline void DispatchToMethod(ObjT
* obj
, Method method
,
856 Tuple3
<OutA
, OutB
, OutC
>* out
) {
857 (obj
->*method
)(in
, &out
->a
, &out
->b
, &out
->c
);
860 template<class ObjT
, class Method
, class InA
,
861 class OutA
, class OutB
, class OutC
>
862 inline void DispatchToMethod(ObjT
* obj
, Method method
,
863 const Tuple1
<InA
>& in
,
864 Tuple3
<OutA
, OutB
, OutC
>* out
) {
865 (obj
->*method
)(in
.a
, &out
->a
, &out
->b
, &out
->c
);
868 template<class ObjT
, class Method
, class InA
, class InB
,
869 class OutA
, class OutB
, class OutC
>
870 inline void DispatchToMethod(ObjT
* obj
, Method method
,
871 const Tuple2
<InA
, InB
>& in
,
872 Tuple3
<OutA
, OutB
, OutC
>* out
) {
873 (obj
->*method
)(in
.a
, in
.b
, &out
->a
, &out
->b
, &out
->c
);
876 template<class ObjT
, class Method
, class InA
, class InB
, class InC
,
877 class OutA
, class OutB
, class OutC
>
878 inline void DispatchToMethod(ObjT
* obj
, Method method
,
879 const Tuple3
<InA
, InB
, InC
>& in
,
880 Tuple3
<OutA
, OutB
, OutC
>* out
) {
881 (obj
->*method
)(in
.a
, in
.b
, in
.c
, &out
->a
, &out
->b
, &out
->c
);
884 template<class ObjT
, class Method
, class InA
, class InB
, class InC
, class InD
,
885 class OutA
, class OutB
, class OutC
>
886 inline void DispatchToMethod(ObjT
* obj
, Method method
,
887 const Tuple4
<InA
, InB
, InC
, InD
>& in
,
888 Tuple3
<OutA
, OutB
, OutC
>* out
) {
889 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, &out
->a
, &out
->b
, &out
->c
);
892 template<class ObjT
, class Method
,
893 class InA
, class InB
, class InC
, class InD
, class InE
,
894 class OutA
, class OutB
, class OutC
>
895 inline void DispatchToMethod(ObjT
* obj
, Method method
,
896 const Tuple5
<InA
, InB
, InC
, InD
, InE
>& in
,
897 Tuple3
<OutA
, OutB
, OutC
>* out
) {
898 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, &out
->a
, &out
->b
, &out
->c
);
901 template<class ObjT
, class Method
,
902 class InA
, class InB
, class InC
, class InD
, class InE
, class InF
,
903 class OutA
, class OutB
, class OutC
>
904 inline void DispatchToMethod(ObjT
* obj
, Method method
,
905 const Tuple6
<InA
, InB
, InC
, InD
, InE
, InF
>& in
,
906 Tuple3
<OutA
, OutB
, OutC
>* out
) {
907 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, in
.f
, &out
->a
, &out
->b
, &out
->c
);
910 // Dispatchers with 4 out params.
912 template<class ObjT
, class Method
,
913 class OutA
, class OutB
, class OutC
, class OutD
>
914 inline void DispatchToMethod(ObjT
* obj
, Method method
,
916 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
917 (obj
->*method
)(&out
->a
, &out
->b
, &out
->c
, &out
->d
);
920 template<class ObjT
, class Method
, class InA
,
921 class OutA
, class OutB
, class OutC
, class OutD
>
922 inline void DispatchToMethod(ObjT
* obj
, Method method
,
924 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
925 (obj
->*method
)(in
, &out
->a
, &out
->b
, &out
->c
, &out
->d
);
928 template<class ObjT
, class Method
, class InA
,
929 class OutA
, class OutB
, class OutC
, class OutD
>
930 inline void DispatchToMethod(ObjT
* obj
, Method method
,
931 const Tuple1
<InA
>& in
,
932 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
933 (obj
->*method
)(in
.a
, &out
->a
, &out
->b
, &out
->c
, &out
->d
);
936 template<class ObjT
, class Method
, class InA
, class InB
,
937 class OutA
, class OutB
, class OutC
, class OutD
>
938 inline void DispatchToMethod(ObjT
* obj
, Method method
,
939 const Tuple2
<InA
, InB
>& in
,
940 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
941 (obj
->*method
)(in
.a
, in
.b
, &out
->a
, &out
->b
, &out
->c
, &out
->d
);
944 template<class ObjT
, class Method
, class InA
, class InB
, class InC
,
945 class OutA
, class OutB
, class OutC
, class OutD
>
946 inline void DispatchToMethod(ObjT
* obj
, Method method
,
947 const Tuple3
<InA
, InB
, InC
>& in
,
948 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
949 (obj
->*method
)(in
.a
, in
.b
, in
.c
, &out
->a
, &out
->b
, &out
->c
, &out
->d
);
952 template<class ObjT
, class Method
, class InA
, class InB
, class InC
, class InD
,
953 class OutA
, class OutB
, class OutC
, class OutD
>
954 inline void DispatchToMethod(ObjT
* obj
, Method method
,
955 const Tuple4
<InA
, InB
, InC
, InD
>& in
,
956 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
957 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, &out
->a
, &out
->b
, &out
->c
, &out
->d
);
960 template<class ObjT
, class Method
,
961 class InA
, class InB
, class InC
, class InD
, class InE
,
962 class OutA
, class OutB
, class OutC
, class OutD
>
963 inline void DispatchToMethod(ObjT
* obj
, Method method
,
964 const Tuple5
<InA
, InB
, InC
, InD
, InE
>& in
,
965 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
966 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
,
967 &out
->a
, &out
->b
, &out
->c
, &out
->d
);
970 template<class ObjT
, class Method
,
971 class InA
, class InB
, class InC
, class InD
, class InE
, class InF
,
972 class OutA
, class OutB
, class OutC
, class OutD
>
973 inline void DispatchToMethod(ObjT
* obj
, Method method
,
974 const Tuple6
<InA
, InB
, InC
, InD
, InE
, InF
>& in
,
975 Tuple4
<OutA
, OutB
, OutC
, OutD
>* out
) {
976 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, in
.f
,
977 &out
->a
, &out
->b
, &out
->c
, &out
->d
);
980 // Dispatchers with 5 out params.
982 template<class ObjT
, class Method
,
983 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
984 inline void DispatchToMethod(ObjT
* obj
, Method method
,
986 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
987 (obj
->*method
)(&out
->a
, &out
->b
, &out
->c
, &out
->d
, &out
->e
);
990 template<class ObjT
, class Method
, class InA
,
991 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
992 inline void DispatchToMethod(ObjT
* obj
, Method method
,
994 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
995 (obj
->*method
)(in
, &out
->a
, &out
->b
, &out
->c
, &out
->d
, &out
->e
);
998 template<class ObjT
, class Method
, class InA
,
999 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
1000 inline void DispatchToMethod(ObjT
* obj
, Method method
,
1001 const Tuple1
<InA
>& in
,
1002 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
1003 (obj
->*method
)(in
.a
, &out
->a
, &out
->b
, &out
->c
, &out
->d
, &out
->e
);
1006 template<class ObjT
, class Method
, class InA
, class InB
,
1007 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
1008 inline void DispatchToMethod(ObjT
* obj
, Method method
,
1009 const Tuple2
<InA
, InB
>& in
,
1010 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
1011 (obj
->*method
)(in
.a
, in
.b
, &out
->a
, &out
->b
, &out
->c
, &out
->d
, &out
->e
);
1014 template<class ObjT
, class Method
, class InA
, class InB
, class InC
,
1015 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
1016 inline void DispatchToMethod(ObjT
* obj
, Method method
,
1017 const Tuple3
<InA
, InB
, InC
>& in
,
1018 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
1019 (obj
->*method
)(in
.a
, in
.b
, in
.c
, &out
->a
, &out
->b
, &out
->c
, &out
->d
, &out
->e
);
1022 template<class ObjT
, class Method
, class InA
, class InB
, class InC
, class InD
,
1023 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
1024 inline void DispatchToMethod(ObjT
* obj
, Method method
,
1025 const Tuple4
<InA
, InB
, InC
, InD
>& in
,
1026 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
1027 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, &out
->a
, &out
->b
, &out
->c
, &out
->d
,
1031 template<class ObjT
, class Method
,
1032 class InA
, class InB
, class InC
, class InD
, class InE
,
1033 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
1034 inline void DispatchToMethod(ObjT
* obj
, Method method
,
1035 const Tuple5
<InA
, InB
, InC
, InD
, InE
>& in
,
1036 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
1037 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
,
1038 &out
->a
, &out
->b
, &out
->c
, &out
->d
, &out
->e
);
1041 template<class ObjT
, class Method
,
1042 class InA
, class InB
, class InC
, class InD
, class InE
, class InF
,
1043 class OutA
, class OutB
, class OutC
, class OutD
, class OutE
>
1044 inline void DispatchToMethod(ObjT
* obj
, Method method
,
1045 const Tuple6
<InA
, InB
, InC
, InD
, InE
, InF
>& in
,
1046 Tuple5
<OutA
, OutB
, OutC
, OutD
, OutE
>* out
) {
1047 (obj
->*method
)(in
.a
, in
.b
, in
.c
, in
.d
, in
.e
, in
.f
,
1048 &out
->a
, &out
->b
, &out
->c
, &out
->d
, &out
->e
);
1051 #endif // BASE_TUPLE_H__