Claw  1.7.3
type_list.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
30 #ifndef __CLAW_TYPE_LIST_HPP__
31 #define __CLAW_TYPE_LIST_HPP__
32 
34 #include <claw/meta/no_type.hpp>
35 #include <claw/meta/same_type.hpp>
36 
37 namespace claw
38 {
39  namespace meta
40  {
58  template<typename Head, typename Queue>
59  struct type_list
60  {
62  typedef Head head_type;
63 
65  typedef Queue queue_type;
66 
67  }; // struct type_list
68 
76  template<typename Delimiter, typename TypeList>
77  struct split_type_list_at;
78 
81  template<typename Delimiter>
82  struct split_type_list_at<Delimiter, no_type>
83  {
86 
89 
90  }; // struct split_type_list_at
91 
99  template<typename Delimiter, typename TypeList>
101  {
103  typedef typename if_then_else
105  no_type, /* delimiter is found, mark the end of the list. */
106  type_list /* otherwise, cut in the remaining types. */
107  < typename TypeList::head_type,
108  typename split_type_list_at
109  <Delimiter, typename TypeList::queue_type>::left_part_type > >::result
111 
113  typedef typename if_then_else
115  TypeList, /* delimiter is found, this is the right part. */
116  typename split_type_list_at
117  <Delimiter, typename TypeList::queue_type>::right_part_type >::result
119 
120  }; // struct split_type_list_at
121 
126  template<typename T1>
128  {
131  }; // struct type_list_maker_1
132 
137  template<typename T1, typename T2>
139  {
142  }; // struct type_list_maker_2
143 
148  template<typename T1, typename T2, typename T3>
150  {
152  typedef
154  }; // struct type_list_maker_3
155 
160  template<typename T1, typename T2, typename T3, typename T4>
162  {
164  typedef
166  }; // struct type_list_maker_4
167 
172  template<typename T1, typename T2, typename T3, typename T4, typename T5>
174  {
176  typedef type_list
177  < T1,
179  }; // struct type_list_maker_5
180 
185  template<typename T1, typename T2, typename T3, typename T4, typename T5,
186  typename T6>
188  {
190  typedef type_list
191  < T1,
193  }; // struct type_list_maker_6
194 
199  template<typename T1, typename T2, typename T3, typename T4, typename T5,
200  typename T6, typename T7>
202  {
204  typedef type_list
205  < T1,
207  }; // struct type_list_maker_7
208 
213  template<typename T1, typename T2, typename T3, typename T4, typename T5,
214  typename T6, typename T7, typename T8>
216  {
218  typedef type_list
219  < T1,
221  }; // struct type_list_maker_8
222 
227  template<typename T1, typename T2, typename T3, typename T4, typename T5,
228  typename T6, typename T7, typename T8, typename T9>
230  {
232  typedef type_list
233  < T1,
234  typename type_list_maker_8
235  <T2, T3, T4, T5, T6, T7, T8, T9>::result
237  }; // struct type_list_maker_9
238 
243  template<typename T1, typename T2, typename T3, typename T4, typename T5,
244  typename T6, typename T7, typename T8, typename T9, typename T10>
246  {
248  typedef type_list
249  < T1,
250  typename type_list_maker_9
251  <T2, T3, T4, T5, T6, T7, T8, T9, T10>::result
253  }; // struct type_list_maker_10
254 
259  template<typename T1, typename T2, typename T3, typename T4, typename T5,
260  typename T6, typename T7, typename T8, typename T9, typename T10,
261  typename T11>
263  {
265  typedef type_list
266  < T1,
267  typename type_list_maker_10
268  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::result
270  }; // struct type_list_maker_11
271 
276  template<typename T1, typename T2, typename T3, typename T4, typename T5,
277  typename T6, typename T7, typename T8, typename T9, typename T10,
278  typename T11, typename T12>
280  {
282  typedef type_list
283  < T1,
284  typename type_list_maker_11
285  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::result
287  }; // struct type_list_maker_12
288 
293  template<typename T1, typename T2, typename T3, typename T4, typename T5,
294  typename T6, typename T7, typename T8, typename T9, typename T10,
295  typename T11, typename T12, typename T13>
297  {
299  typedef type_list
300  < T1,
301  typename type_list_maker_12
302  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::result
304  }; // struct type_list_maker_13
305 
310  template<typename T1, typename T2, typename T3, typename T4, typename T5,
311  typename T6, typename T7, typename T8, typename T9, typename T10,
312  typename T11, typename T12, typename T13, typename T14>
314  {
316  typedef type_list
317  < T1,
318  typename type_list_maker_13
319  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::result
321  }; // struct type_list_maker_14
322 
327  template<typename T1, typename T2, typename T3, typename T4, typename T5,
328  typename T6, typename T7, typename T8, typename T9, typename T10,
329  typename T11, typename T12, typename T13, typename T14,
330  typename T15>
332  {
334  typedef type_list
335  < T1,
336  typename type_list_maker_14
337  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::result
339  }; // struct type_list_maker_15
340 
346  template< typename T1, typename T2 = no_type, typename T3 = no_type,
347  typename T4 = no_type, typename T5 = no_type,
348  typename T6 = no_type, typename T7 = no_type,
349  typename T8 = no_type, typename T9 = no_type,
350  typename T10 = no_type, typename T11 = no_type,
351  typename T12 = no_type, typename T13 = no_type,
352  typename T14 = no_type, typename T15 = no_type >
354  {
356  typedef typename split_type_list_at
357  < no_type,
358  typename type_list_maker_15
359  < T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
360  T15 >::result
361  >::left_part_type result;
362  }; // struct type_list_maker
363 
376  template<typename T, typename List>
378  {
379  enum
380  {
383  };
384  }; // struct type_list_find
385 
386  template<typename T>
388  {
389  enum
390  {
392  };
393  }; // struct type_list_find
394 
401  template<typename List>
403  {
404  enum
405  {
406  result = !type_list_find<typename List::head_type,
407  typename List::queue_type>::result
409  };
410  }; // struct type_list_is_a_set
411 
412  template<>
414  {
415  enum
416  {
417  result = true
418  };
419  }; // struct type_list_is_a_set [no_type]
420 
426  template<typename List>
428  {
429  enum
430  {
432  };
433  }; // struct type_list_length
434 
435  template<>
437  {
438  enum
439  {
440  result = 0
441  };
442  }; // struct type_list_length [no_type]
443 
451  template<typename T, typename List>
452  struct type_list_contains;
453 
454  template<typename T, typename Tail>
455  struct type_list_contains< T, type_list<T, Tail> >
456  {
457  enum
458  {
459  result = true
460  };
461  }; // struct type_list_contains
462 
463  template<typename T>
464  struct type_list_contains< T, no_type >
465  {
466  enum
467  {
468  result = false
469  };
470  }; // struct type_list_contains
471 
472  template<typename T, typename Head, typename Tail>
473  struct type_list_contains< T, type_list<Head, Tail> >
474  {
475  enum
476  {
477  result = type_list_contains<T, Tail>::result
478  };
479  }; // struct type_list_contains
480 
482  typedef type_list_maker
483  < signed char, unsigned char,
484  signed short, unsigned short,
485  signed int, unsigned int,
486  signed long, unsigned long,
487 #ifndef __STRICT_ANSI__
488  signed long long, unsigned long long,
489 #endif
490  float,
491  double,
492  long double,
493  bool >::result cpp_type_list;
494 
495  } // namespace meta
496 } // namespace claw
497 
498 #endif // __CLAW_TYPE_LIST_HPP__