Claw  1.7.0
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  {
61  typedef Head head_type;
62  typedef Queue queue_type;
63  }; // struct type_list
64 
72  template<typename Delimiter, typename TypeList>
73  struct split_type_list_at;
74 
77  template<typename Delimiter>
78  struct split_type_list_at<Delimiter, no_type>
79  {
80  typedef no_type left_part_type;
81  typedef no_type right_part_type;
82 
83  }; // struct split_type_list_at
84 
92  template<typename Delimiter, typename TypeList>
94  {
96  typedef typename if_then_else
98  no_type, /* delimiter is found, mark the end of the list. */
99  type_list /* otherwise, cut in the remaining types. */
100  < typename TypeList::head_type,
101  typename split_type_list_at
102  <Delimiter, typename TypeList::queue_type>::left_part_type > >::result
104 
106  typedef typename if_then_else
108  TypeList, /* delimiter is found, this is the right part. */
109  typename split_type_list_at
110  <Delimiter, typename TypeList::queue_type>::right_part_type >::result
112 
113  }; // struct split_type_list_at
114 
119  template<typename T1>
121  {
123  }; // struct type_list_maker_1
124 
129  template<typename T1, typename T2>
131  {
133  }; // struct type_list_maker_2
134 
139  template<typename T1, typename T2, typename T3>
141  {
142  typedef
144  }; // struct type_list_maker_3
145 
150  template<typename T1, typename T2, typename T3, typename T4>
152  {
153  typedef
155  }; // struct type_list_maker_4
156 
161  template<typename T1, typename T2, typename T3, typename T4, typename T5>
163  {
164  typedef type_list
165  < T1,
167  }; // struct type_list_maker_5
168 
173  template<typename T1, typename T2, typename T3, typename T4, typename T5,
174  typename T6>
176  {
177  typedef type_list
178  < T1,
180  }; // struct type_list_maker_6
181 
186  template<typename T1, typename T2, typename T3, typename T4, typename T5,
187  typename T6, typename T7>
189  {
190  typedef type_list
191  < T1,
193  }; // struct type_list_maker_7
194 
199  template<typename T1, typename T2, typename T3, typename T4, typename T5,
200  typename T6, typename T7, typename T8>
202  {
203  typedef type_list
204  < T1,
206  }; // struct type_list_maker_8
207 
212  template<typename T1, typename T2, typename T3, typename T4, typename T5,
213  typename T6, typename T7, typename T8, typename T9>
215  {
216  typedef type_list
217  < T1,
218  typename type_list_maker_8
219  <T2, T3, T4, T5, T6, T7, T8, T9>::result
220  > result;
221  }; // struct type_list_maker_9
222 
227  template<typename T1, typename T2, typename T3, typename T4, typename T5,
228  typename T6, typename T7, typename T8, typename T9, typename T10>
230  {
231  typedef type_list
232  < T1,
233  typename type_list_maker_9
234  <T2, T3, T4, T5, T6, T7, T8, T9, T10>::result
235  > result;
236  }; // struct type_list_maker_10
237 
242  template<typename T1, typename T2, typename T3, typename T4, typename T5,
243  typename T6, typename T7, typename T8, typename T9, typename T10,
244  typename T11>
246  {
247  typedef type_list
248  < T1,
249  typename type_list_maker_10
250  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>::result
251  > result;
252  }; // struct type_list_maker_11
253 
258  template<typename T1, typename T2, typename T3, typename T4, typename T5,
259  typename T6, typename T7, typename T8, typename T9, typename T10,
260  typename T11, typename T12>
262  {
263  typedef type_list
264  < T1,
265  typename type_list_maker_11
266  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>::result
267  > result;
268  }; // struct type_list_maker_12
269 
274  template<typename T1, typename T2, typename T3, typename T4, typename T5,
275  typename T6, typename T7, typename T8, typename T9, typename T10,
276  typename T11, typename T12, typename T13>
278  {
279  typedef type_list
280  < T1,
281  typename type_list_maker_12
282  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>::result
283  > result;
284  }; // struct type_list_maker_13
285 
290  template<typename T1, typename T2, typename T3, typename T4, typename T5,
291  typename T6, typename T7, typename T8, typename T9, typename T10,
292  typename T11, typename T12, typename T13, typename T14>
294  {
295  typedef type_list
296  < T1,
297  typename type_list_maker_13
298  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>::result
299  > result;
300  }; // struct type_list_maker_14
301 
306  template<typename T1, typename T2, typename T3, typename T4, typename T5,
307  typename T6, typename T7, typename T8, typename T9, typename T10,
308  typename T11, typename T12, typename T13, typename T14,
309  typename T15>
311  {
312  typedef type_list
313  < T1,
314  typename type_list_maker_14
315  <T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::result
316  > result;
317  }; // struct type_list_maker_15
318 
324  template< typename T1, typename T2 = no_type, typename T3 = no_type,
325  typename T4 = no_type, typename T5 = no_type,
326  typename T6 = no_type, typename T7 = no_type,
327  typename T8 = no_type, typename T9 = no_type,
328  typename T10 = no_type, typename T11 = no_type,
329  typename T12 = no_type, typename T13 = no_type,
330  typename T14 = no_type, typename T15 = no_type >
332  {
333  typedef typename split_type_list_at
334  < no_type,
335  typename type_list_maker_15
336  < T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
337  T15 >::result
338  >::left_part_type result;
339  }; // struct type_list_maker
340 
353  template<typename T, typename List>
355  {
356  enum
357  {
360  };
361  }; // struct type_list_find
362 
363  template<typename T>
365  {
366  enum
367  {
369  };
370  }; // struct type_list_find
371 
378  template<typename List>
380  {
381  enum
382  {
383  result = !type_list_find<typename List::head_type,
384  typename List::queue_type>::result
386  };
387  }; // struct type_list_is_a_set
388 
389  template<>
391  {
392  enum
393  {
394  result = true
395  };
396  }; // struct type_list_is_a_set [no_type]
397 
403  template<typename List>
405  {
406  enum
407  {
409  };
410  }; // struct type_list_length
411 
412  template<>
414  {
415  enum
416  {
417  result = 0
418  };
419  }; // struct type_list_length [no_type]
420 
428  template<typename T, typename List>
429  struct type_list_contains;
430 
431  template<typename T, typename Tail>
432  struct type_list_contains< T, type_list<T, Tail> >
433  {
434  enum
435  {
436  result = true
437  };
438  }; // struct type_list_contains
439 
440  template<typename T>
441  struct type_list_contains< T, no_type >
442  {
443  enum
444  {
445  result = false
446  };
447  }; // struct type_list_contains
448 
449  template<typename T, typename Head, typename Tail>
450  struct type_list_contains< T, type_list<Head, Tail> >
451  {
452  enum
453  {
454  result = type_list_contains<T, Tail>::result
455  };
456  }; // struct type_list_contains
457 
459  typedef type_list_maker
460  < signed char, unsigned char,
461  signed short, unsigned short,
462  signed int, unsigned int,
463  signed long, unsigned long,
464  signed long long, unsigned long long,
465  float,
466  double,
467  long double,
468  bool >::result cpp_type_list;
469 
470  } // namespace meta
471 } // namespace claw
472 
473 #endif // __CLAW_TYPE_LIST_HPP__