Lumiera  0.pre.03
»edit your freedom«
argument-tuple-accept.hpp
Go to the documentation of this file.
1 /*
2  ARGUMENT-TUPLE-ACCEPT.hpp - helper template providing a bind(...) member function
3 
4  Copyright (C)
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
50 #ifndef CONTROL_ARGUMENT_TUPLE_ACCEPT_H
51 #define CONTROL_ARGUMENT_TUPLE_ACCEPT_H
52 
53 #include "lib/meta/typelist.hpp"
54 #include "lib/meta/function.hpp"
56 
57 #include <utility>
58 #include <tuple>
59 
60 
61 
62 namespace steam {
63 namespace control {
64 
65 
66  namespace bind_arg { // internals....
67 
68  using namespace lib::meta;
69  using std::make_tuple;
70 
71 
72  //
73  // _______________________________________________________________________________________________________________
75  template< class TAR, class BA, class RET
76  , typename TYPES
77  >
78  struct AcceptArgs ;
79 
80 
81  /* specialisations for 0...9 Arguments.... */
82 
83  template< class TAR, class BA, class RET
84  > //____________________________________
85  struct AcceptArgs<TAR,BA,RET, Types<> >
86  : BA
87  {
88  RET
89  operator() ()
90  {
91  return static_cast<TAR*> (this) -> bindArg (std::tuple<>() );
92  }
93  };
94 
95 
96  template< class TAR, class BA, class RET
97  , typename T1
98  > //_______________________________
99  struct AcceptArgs<TAR,BA,RET, Types<T1> >
100  : BA
101  {
102  RET
103  operator() (T1 a1)
104  {
105  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1));
106  }
107  };
108 
109 
110  template< class TAR, class BA, class RET
111  , typename T1
112  , typename T2
113  > //________________________________
114  struct AcceptArgs<TAR,BA,RET, Types<T1,T2> >
115  : BA
116  {
117  RET
118  operator() (T1 a1, T2 a2)
119  {
120  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2));
121  }
122  };
123 
124 
125  template< class TAR, class BA, class RET
126  , typename T1
127  , typename T2
128  , typename T3
129  > //________________________________
130  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3> >
131  : BA
132  {
133  RET
134  operator() (T1 a1, T2 a2, T3 a3)
135  {
136  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3));
137  }
138  };
139 
140 
141  template< class TAR, class BA, class RET
142  , typename T1
143  , typename T2
144  , typename T3
145  , typename T4
146  > //________________________________
147  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4> >
148  : BA
149  {
150  RET
151  operator() (T1 a1, T2 a2, T3 a3, T4 a4)
152  {
153  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4));
154  }
155  };
156 
157 
158  template< class TAR, class BA, class RET
159  , typename T1
160  , typename T2
161  , typename T3
162  , typename T4
163  , typename T5
164  > //________________________________
165  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5> >
166  : BA
167  {
168  RET
169  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
170  {
171  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5));
172  }
173  };
174 
175 
176  template< class TAR, class BA, class RET
177  , typename T1
178  , typename T2
179  , typename T3
180  , typename T4
181  , typename T5
182  , typename T6
183  > //________________________________
184  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6> >
185  : BA
186  {
187  RET
188  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
189  {
190  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6));
191  }
192  };
193 
194 
195  template< class TAR, class BA, class RET
196  , typename T1
197  , typename T2
198  , typename T3
199  , typename T4
200  , typename T5
201  , typename T6
202  , typename T7
203  > //________________________________
204  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7> >
205  : BA
206  {
207  RET
208  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
209  {
210  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7));
211  }
212  };
213 
214 
215  template< class TAR, class BA, class RET
216  , typename T1
217  , typename T2
218  , typename T3
219  , typename T4
220  , typename T5
221  , typename T6
222  , typename T7
223  , typename T8
224  > //________________________________
225  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8> >
226  : BA
227  {
228  RET
229  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8)
230  {
231  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8));
232  }
233  };
234 
235 
236  template< class TAR, class BA, class RET
237  , typename T1
238  , typename T2
239  , typename T3
240  , typename T4
241  , typename T5
242  , typename T6
243  , typename T7
244  , typename T8
245  , typename T9
246  > //________________________________
247  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8,T9> >
248  : BA
249  {
250  RET
251  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9)
252  {
253  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8,a9));
254  }
255  };
256 
257 
258 
259 
260 
261 
262  //
263  // _______________________________________________________________________________________________________________
266  template< class TAR, class BA, class RET
267  , typename TYPES
268  >
269  struct AcceptBind ;
270 
271 
272  /* specialisations for 0...9 Arguments.... */
273 
274  template< class TAR, class BA, class RET
275  > //____________________________________
276  struct AcceptBind<TAR,BA,RET, Types<> >
277  : BA
278  {
279  RET
280  bind ()
281  {
282  return static_cast<TAR*> (this) -> bindArg (std::tuple<>() );
283  }
284  };
285 
286 
287  template< class TAR, class BA, class RET
288  , typename T1
289  > //_______________________________
290  struct AcceptBind<TAR,BA,RET, Types<T1> >
291  : BA
292  {
293  RET
294  bind (T1 a1)
295  {
296  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1));
297  }
298  };
299 
300 
301  template< class TAR, class BA, class RET
302  , typename T1
303  , typename T2
304  > //________________________________
305  struct AcceptBind<TAR,BA,RET, Types<T1,T2> >
306  : BA
307  {
308  RET
309  bind (T1 a1, T2 a2)
310  {
311  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2));
312  }
313  };
314 
315 
316  template< class TAR, class BA, class RET
317  , typename T1
318  , typename T2
319  , typename T3
320  > //________________________________
321  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3> >
322  : BA
323  {
324  RET
325  bind (T1 a1, T2 a2, T3 a3)
326  {
327  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3));
328  }
329  };
330 
331 
332  template< class TAR, class BA, class RET
333  , typename T1
334  , typename T2
335  , typename T3
336  , typename T4
337  > //________________________________
338  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4> >
339  : BA
340  {
341  RET
342  bind (T1 a1, T2 a2, T3 a3, T4 a4)
343  {
344  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4));
345  }
346  };
347 
348 
349  template< class TAR, class BA, class RET
350  , typename T1
351  , typename T2
352  , typename T3
353  , typename T4
354  , typename T5
355  > //________________________________
356  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5> >
357  : BA
358  {
359  RET
360  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
361  {
362  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5));
363  }
364  };
365 
366 
367  template< class TAR, class BA, class RET
368  , typename T1
369  , typename T2
370  , typename T3
371  , typename T4
372  , typename T5
373  , typename T6
374  > //________________________________
375  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6> >
376  : BA
377  {
378  RET
379  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
380  {
381  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6));
382  }
383  };
384 
385 
386  template< class TAR, class BA, class RET
387  , typename T1
388  , typename T2
389  , typename T3
390  , typename T4
391  , typename T5
392  , typename T6
393  , typename T7
394  > //________________________________
395  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7> >
396  : BA
397  {
398  RET
399  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
400  {
401  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7));
402  }
403  };
404 
405 
406  template< class TAR, class BA, class RET
407  , typename T1
408  , typename T2
409  , typename T3
410  , typename T4
411  , typename T5
412  , typename T6
413  , typename T7
414  , typename T8
415  > //________________________________
416  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8> >
417  : BA
418  {
419  RET
420  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8)
421  {
422  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8));
423  }
424  };
425 
426 
427  template< class TAR, class BA, class RET
428  , typename T1
429  , typename T2
430  , typename T3
431  , typename T4
432  , typename T5
433  , typename T6
434  , typename T7
435  , typename T8
436  , typename T9
437  > //________________________________
438  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8,T9> >
439  : BA
440  {
441  RET
442  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9)
443  {
444  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8,a9));
445  }
446  };
447 
448 
449 
450 
451 
452 
453  //
454  // _______________________________________________________________________________________________________________
457  template< class TAR, class BA, class RET>
459  : BA
460  {
462  RET
463  bind ()
464  {
465  return static_cast<TAR*> (this) -> bindArg (std::tuple<>());
466  }
467 
472  template<typename...ARGS>
473  RET
474  bind (ARGS&& ...args)
475  {
476  return static_cast<TAR*> (this) -> bindArg (make_tuple (std::forward<ARGS> (args)...));
477  }
478  };
479 
480 
481 
482  using lib::meta::Tuple;
483  using lib::meta::_Fun;
484 
485 
486  template<typename SIG>
487  struct _Type
488  {
489  using Args = typename _Fun<SIG>::Args;
490  using Ret = typename _Fun<SIG>::Ret;
491  using Sig = SIG;
492  using ArgTuple = Tuple<Args>;
493  };
494 
495  template<typename...TYPES>
496  struct _Type<std::tuple<TYPES...> >
497  {
498  using Args = typename Types<TYPES...>::Seq;
499  using Ret = void;
500  using Sig = typename BuildFunType<void, Args>::Sig;
501  using ArgTuple = std::tuple<TYPES...>;
502  };
503 
504  struct Dummy {};
505 
506 
507  } // (END) impl details (bind_arg)
508 
509 
510 
511 
518  template<typename SIG, class TAR, class BASE =bind_arg::Dummy>
520  : public bind_arg::AcceptArgs<TAR,BASE, typename bind_arg::_Type<SIG>::Ret
521  , typename bind_arg::_Type<SIG>::Args>
522  { };
523 
524 
530  template<typename SIG, class TAR, class BASE =bind_arg::Dummy>
532  : public bind_arg::AcceptBind<TAR,BASE, typename bind_arg::_Type<SIG>::Ret
533  , typename bind_arg::_Type<SIG>::Args>
534  { };
535 
536 
540  template<typename RET, typename SIG, class TAR, class BASE =bind_arg::Dummy>
542  : public bind_arg::AcceptBind<TAR,BASE, RET
543  , typename bind_arg::_Type<SIG>::Args>
544  { };
545 
546 
552  template< class TAR
553  , class RET =TAR&
554  , class BASE =bind_arg::Dummy
555  >
557  : public bind_arg::AcceptAnyBind<TAR,BASE,RET>
558  { };
559 
560 
561 
562 
563 
564 
565 }} // namespace steam::control
566 #endif
Build function types from given Argument types.
Definition: function.hpp:341
Helper Template for Steam-Layer control::Command : mix in a bind(...) function.
A template metaprogramming technique for manipulating collections of types.
typename BuildTupleType< TYPES >::Type Tuple
Build a std::tuple from types given as type sequence.
Helper Template for building a Functor or function-like class: Mix in a function call operator...
STL namespace.
Helper for uniform access to function signature types.
Definition: function.hpp:99
Steam-Layer implementation namespace root.
Metaprogramming with tuples-of-types and the std::tuple record.
Helper Template for control::Command, mix-in complete set of bind(...) functions. ...
Metaprogramming tools for transforming functor types.
RET bind()
Accept dummy binding (0 Arg)
RET bind(ARGS &&...args)
mix in bind function to create binding of arbitrary arguments
Variation of AcceptArgumentBinding, allowing to control the return type of the generated bind(...