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) Lumiera.org
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
23 
59 #ifndef CONTROL_ARGUMENT_TUPLE_ACCEPT_H
60 #define CONTROL_ARGUMENT_TUPLE_ACCEPT_H
61 
62 #include "lib/meta/typelist.hpp"
63 #include "lib/meta/function.hpp"
65 
66 #include <utility>
67 #include <tuple>
68 
69 
70 
71 namespace steam {
72 namespace control {
73 
74 
75  namespace bind_arg { // internals....
76 
77  using namespace lib::meta;
78  using std::make_tuple;
79 
80 
81  //
82  // _______________________________________________________________________________________________________________
84  template< class TAR, class BA, class RET
85  , typename TYPES
86  >
87  struct AcceptArgs ;
88 
89 
90  /* specialisations for 0...9 Arguments.... */
91 
92  template< class TAR, class BA, class RET
93  > //____________________________________
94  struct AcceptArgs<TAR,BA,RET, Types<> >
95  : BA
96  {
97  RET
98  operator() ()
99  {
100  return static_cast<TAR*> (this) -> bindArg (std::tuple<>() );
101  }
102  };
103 
104 
105  template< class TAR, class BA, class RET
106  , typename T1
107  > //_______________________________
108  struct AcceptArgs<TAR,BA,RET, Types<T1> >
109  : BA
110  {
111  RET
112  operator() (T1 a1)
113  {
114  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1));
115  }
116  };
117 
118 
119  template< class TAR, class BA, class RET
120  , typename T1
121  , typename T2
122  > //________________________________
123  struct AcceptArgs<TAR,BA,RET, Types<T1,T2> >
124  : BA
125  {
126  RET
127  operator() (T1 a1, T2 a2)
128  {
129  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2));
130  }
131  };
132 
133 
134  template< class TAR, class BA, class RET
135  , typename T1
136  , typename T2
137  , typename T3
138  > //________________________________
139  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3> >
140  : BA
141  {
142  RET
143  operator() (T1 a1, T2 a2, T3 a3)
144  {
145  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3));
146  }
147  };
148 
149 
150  template< class TAR, class BA, class RET
151  , typename T1
152  , typename T2
153  , typename T3
154  , typename T4
155  > //________________________________
156  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4> >
157  : BA
158  {
159  RET
160  operator() (T1 a1, T2 a2, T3 a3, T4 a4)
161  {
162  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4));
163  }
164  };
165 
166 
167  template< class TAR, class BA, class RET
168  , typename T1
169  , typename T2
170  , typename T3
171  , typename T4
172  , typename T5
173  > //________________________________
174  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5> >
175  : BA
176  {
177  RET
178  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
179  {
180  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5));
181  }
182  };
183 
184 
185  template< class TAR, class BA, class RET
186  , typename T1
187  , typename T2
188  , typename T3
189  , typename T4
190  , typename T5
191  , typename T6
192  > //________________________________
193  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6> >
194  : BA
195  {
196  RET
197  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
198  {
199  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6));
200  }
201  };
202 
203 
204  template< class TAR, class BA, class RET
205  , typename T1
206  , typename T2
207  , typename T3
208  , typename T4
209  , typename T5
210  , typename T6
211  , typename T7
212  > //________________________________
213  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7> >
214  : BA
215  {
216  RET
217  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
218  {
219  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7));
220  }
221  };
222 
223 
224  template< class TAR, class BA, class RET
225  , typename T1
226  , typename T2
227  , typename T3
228  , typename T4
229  , typename T5
230  , typename T6
231  , typename T7
232  , typename T8
233  > //________________________________
234  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8> >
235  : BA
236  {
237  RET
238  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8)
239  {
240  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8));
241  }
242  };
243 
244 
245  template< class TAR, class BA, class RET
246  , typename T1
247  , typename T2
248  , typename T3
249  , typename T4
250  , typename T5
251  , typename T6
252  , typename T7
253  , typename T8
254  , typename T9
255  > //________________________________
256  struct AcceptArgs<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8,T9> >
257  : BA
258  {
259  RET
260  operator() (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9)
261  {
262  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8,a9));
263  }
264  };
265 
266 
267 
268 
269 
270 
271  //
272  // _______________________________________________________________________________________________________________
275  template< class TAR, class BA, class RET
276  , typename TYPES
277  >
278  struct AcceptBind ;
279 
280 
281  /* specialisations for 0...9 Arguments.... */
282 
283  template< class TAR, class BA, class RET
284  > //____________________________________
285  struct AcceptBind<TAR,BA,RET, Types<> >
286  : BA
287  {
288  RET
289  bind ()
290  {
291  return static_cast<TAR*> (this) -> bindArg (std::tuple<>() );
292  }
293  };
294 
295 
296  template< class TAR, class BA, class RET
297  , typename T1
298  > //_______________________________
299  struct AcceptBind<TAR,BA,RET, Types<T1> >
300  : BA
301  {
302  RET
303  bind (T1 a1)
304  {
305  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1));
306  }
307  };
308 
309 
310  template< class TAR, class BA, class RET
311  , typename T1
312  , typename T2
313  > //________________________________
314  struct AcceptBind<TAR,BA,RET, Types<T1,T2> >
315  : BA
316  {
317  RET
318  bind (T1 a1, T2 a2)
319  {
320  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2));
321  }
322  };
323 
324 
325  template< class TAR, class BA, class RET
326  , typename T1
327  , typename T2
328  , typename T3
329  > //________________________________
330  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3> >
331  : BA
332  {
333  RET
334  bind (T1 a1, T2 a2, T3 a3)
335  {
336  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3));
337  }
338  };
339 
340 
341  template< class TAR, class BA, class RET
342  , typename T1
343  , typename T2
344  , typename T3
345  , typename T4
346  > //________________________________
347  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4> >
348  : BA
349  {
350  RET
351  bind (T1 a1, T2 a2, T3 a3, T4 a4)
352  {
353  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4));
354  }
355  };
356 
357 
358  template< class TAR, class BA, class RET
359  , typename T1
360  , typename T2
361  , typename T3
362  , typename T4
363  , typename T5
364  > //________________________________
365  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5> >
366  : BA
367  {
368  RET
369  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)
370  {
371  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5));
372  }
373  };
374 
375 
376  template< class TAR, class BA, class RET
377  , typename T1
378  , typename T2
379  , typename T3
380  , typename T4
381  , typename T5
382  , typename T6
383  > //________________________________
384  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6> >
385  : BA
386  {
387  RET
388  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)
389  {
390  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6));
391  }
392  };
393 
394 
395  template< class TAR, class BA, class RET
396  , typename T1
397  , typename T2
398  , typename T3
399  , typename T4
400  , typename T5
401  , typename T6
402  , typename T7
403  > //________________________________
404  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7> >
405  : BA
406  {
407  RET
408  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7)
409  {
410  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7));
411  }
412  };
413 
414 
415  template< class TAR, class BA, class RET
416  , typename T1
417  , typename T2
418  , typename T3
419  , typename T4
420  , typename T5
421  , typename T6
422  , typename T7
423  , typename T8
424  > //________________________________
425  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8> >
426  : BA
427  {
428  RET
429  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8)
430  {
431  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8));
432  }
433  };
434 
435 
436  template< class TAR, class BA, class RET
437  , typename T1
438  , typename T2
439  , typename T3
440  , typename T4
441  , typename T5
442  , typename T6
443  , typename T7
444  , typename T8
445  , typename T9
446  > //________________________________
447  struct AcceptBind<TAR,BA,RET, Types<T1,T2,T3,T4,T5,T6,T7,T8,T9> >
448  : BA
449  {
450  RET
451  bind (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8, T9 a9)
452  {
453  return static_cast<TAR*> (this) -> bindArg (make_tuple (a1,a2,a3,a4,a5,a6,a7,a8,a9));
454  }
455  };
456 
457 
458 
459 
460 
461 
462  //
463  // _______________________________________________________________________________________________________________
466  template< class TAR, class BA, class RET>
468  : BA
469  {
471  RET
472  bind ()
473  {
474  return static_cast<TAR*> (this) -> bindArg (std::tuple<>());
475  }
476 
481  template<typename...ARGS>
482  RET
483  bind (ARGS&& ...args)
484  {
485  return static_cast<TAR*> (this) -> bindArg (make_tuple (std::forward<ARGS> (args)...));
486  }
487  };
488 
489 
490 
491  using lib::meta::Tuple;
492  using lib::meta::_Fun;
493 
494 
495  template<typename SIG>
496  struct _Type
497  {
498  using Args = typename _Fun<SIG>::Args;
499  using Ret = typename _Fun<SIG>::Ret;
500  using Sig = SIG;
501  using ArgTuple = Tuple<Args>;
502  };
503 
504  template<typename...TYPES>
505  struct _Type<std::tuple<TYPES...> >
506  {
507  using Args = typename Types<TYPES...>::Seq;
508  using Ret = void;
509  using Sig = typename BuildFunType<void, Args>::Sig;
510  using ArgTuple = std::tuple<TYPES...>;
511  };
512 
513  struct Dummy {};
514 
515 
516  } // (END) impl details (bind_arg)
517 
518 
519 
520 
527  template<typename SIG, class TAR, class BASE =bind_arg::Dummy>
529  : public bind_arg::AcceptArgs<TAR,BASE, typename bind_arg::_Type<SIG>::Ret
530  , typename bind_arg::_Type<SIG>::Args>
531  { };
532 
533 
539  template<typename SIG, class TAR, class BASE =bind_arg::Dummy>
541  : public bind_arg::AcceptBind<TAR,BASE, typename bind_arg::_Type<SIG>::Ret
542  , typename bind_arg::_Type<SIG>::Args>
543  { };
544 
545 
549  template<typename RET, typename SIG, class TAR, class BASE =bind_arg::Dummy>
551  : public bind_arg::AcceptBind<TAR,BASE, RET
552  , typename bind_arg::_Type<SIG>::Args>
553  { };
554 
555 
561  template< class TAR
562  , class RET =TAR&
563  , class BASE =bind_arg::Dummy
564  >
566  : public bind_arg::AcceptAnyBind<TAR,BASE,RET>
567  { };
568 
569 
570 
571 
572 
573 
574 }} // namespace steam::control
575 #endif
Build function types from given Argument types.
Definition: function.hpp:350
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:108
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(...