Arduino Libraries
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
meta_list.hpp
Go to the documentation of this file.
1 // Author: Mario S. Könz <mskoenz@gmx.net>
2 // Date: 21.07.2013 11:54:08 EDT
3 // File: meta_list.hpp
4 
5 /* This program is free software. It comes without any warranty, to
6  * the extent permitted by applicable law. You can redistribute it
7  * and/or modify it under the terms of the Do What The Fuck You Want
8  * To Public License, Version 2, as published by Sam Hocevar. See
9  * http://www.wtfpl.net/ or COPYING for more details. */
10 
11 #ifndef __META_LIST_HEADER
12 #define __META_LIST_HEADER
13 
14 namespace util {
15  //------------------- mtp list -------------------
16  template<typename stored_type, typename next_list_item>
17  struct list_item {
18  typedef stored_type type;
19  typedef next_list_item next;
20  };
21 
22  struct list_end {}; //is used to mark the end of a list
23 
24  //------------------- remove void -------------------
25  template<typename list>
26  struct remove_void {
27  typedef list type;
28  };
29 
30  template<
31  typename stored_type
32  , typename next_list_item
33  >
34  struct remove_void<list_item<stored_type, next_list_item> > {
36  };
37 
38  template<typename next_list_item>
39  struct remove_void<list_item<void, next_list_item> > {
41  };
42 
43  //------------------- make_list -------------------
44  template<
45  typename _0 = void
46  , typename _1 = void
47  , typename _2 = void
48  , typename _3 = void
49  , typename _4 = void
50  , typename _5 = void
51  , typename _6 = void
52  , typename _7 = void
53  , typename _8 = void
54  , typename _9 = void
55  , typename _10 = void
56  , typename _11 = void
57  , typename _12 = void
58  , typename _13 = void
59  , typename _14 = void
60  , typename _15 = void
61  , typename _16 = void
62  , typename _17 = void
63  , typename _18 = void
64  , typename _19 = void
65  , typename _20 = void
66  , typename _21 = void
67  >
68  struct make_list {
69  typedef typename remove_void<
70  list_item<_0,
71  list_item<_1,
72  list_item<_2,
73  list_item<_3,
74  list_item<_4,
75  list_item<_5,
76  list_item<_6,
77  list_item<_7,
78  list_item<_8,
79  list_item<_9,
80  list_item<_10,
81  list_item<_11,
82  list_item<_12,
83  list_item<_13,
84  list_item<_14,
85  list_item<_15,
86  list_item<_16,
87  list_item<_17,
88  list_item<_18,
89  list_item<_19,
90  list_item<_20,
91  list_item<_21,
92  list_end
93  > > > > > > > > > >
94  > > > > > > > > > >
95  > >
97  };
98  //------------------- concat two lists -------------------
99  template<typename list1, typename list2> struct concatinate_lists {
101  };
102 
103  template<typename list2> struct concatinate_lists<list_end, list2> {
104  typedef list2 type;
105  };
106 
107  //------------------- unique list walker -------------------
108  //walks through the list and eliminates target
109  template<typename target, typename list>
111  typedef list_item<
112  typename list::type
114  > type;
115  };
116 
117  template<typename target, typename list>
118  struct unique_list_walker<target, list_item<target, list> > {
120  };
121 
122  template<typename target>
123  struct unique_list_walker<target, list_end>{
124  typedef list_end type;
125  };
126  //------------------- unique list -------------------
127  template<typename list>
128  struct unique_list {
129  typedef list_item<
130  typename list::type
131  , typename unique_list<
132  typename unique_list_walker<
133  typename list::type
134  , typename list::next
135  >::type
136  >::type
137  > type;
138  };
139 
140  template<>
142  typedef list_end type;
143  };
144  //------------------- last_item -------------------
145  template<typename list>
146  struct last_item {
147  typedef
150  };
151  template<typename item>
152  struct last_item<list_item<item, list_end> > {
153  typedef item type;
154  };
155 
156 
157  //------------------- remove_last -------------------
158  template<typename list>
159  struct remove_last {
160  typedef
161  list_item<typename list::type
163  >
165  };
166  template<typename item>
167  struct remove_last<list_item<item, list_end> > {
168  typedef list_end type;
169  };
170 
171  //------------------- invert list -------------------
172  template<typename list>
173  struct invert_list {
174  typedef
177  >
179  };
180  template<typename item>
181  struct invert_list<list_item<item, list_end> > {
183  };
184 }//end namespace util
185 
186 #endif //__META_LIST_HEADER
list_end type
Definition: meta_list.hpp:124
item type
Definition: meta_list.hpp:153
Definition: meta_list.hpp:128
list2 type
Definition: meta_list.hpp:104
Definition: meta_list.hpp:159
last_item< typename list::next >::type type
Definition: meta_list.hpp:149
list_end type
Definition: meta_list.hpp:168
Definition: meta_list.hpp:26
list_item< typename list::type, typename unique_list_walker< target, typename list::next >::type > type
Definition: meta_list.hpp:114
list_item< typename list::type, typename remove_last< typename list::next >::type > type
Definition: meta_list.hpp:164
list_end type
Definition: meta_list.hpp:142
stored_type type
Definition: meta_list.hpp:18
list_item< stored_type, typename remove_void< next_list_item >::type > type
Definition: meta_list.hpp:35
Definition: meta_list.hpp:17
Definition: meta_list.hpp:68
Definition: meta_list.hpp:99
Definition: meta_list.hpp:146
list_item< item, list_end > type
Definition: meta_list.hpp:182
remove_void< list_item< _0, list_item< _1, list_item< _2, list_item< _3, list_item< _4, list_item< _5, list_item< _6, list_item< _7, list_item< _8, list_item< _9, list_item< _10, list_item< _11, list_item< _12, list_item< _13, list_item< _14, list_item< _15, list_item< _16, list_item< _17, list_item< _18, list_item< _19, list_item< _20, list_item< _21, list_end > > > > > > > > > > > > > > > > > > > > > > >::type type
Definition: meta_list.hpp:96
Definition: meta_list.hpp:173
Definition: meta_list.hpp:110
remove_void< next_list_item >::type type
Definition: meta_list.hpp:40
list type
Definition: meta_list.hpp:27
list_item< typename last_item< list >::type, typename invert_list< typename remove_last< list >::type >::type > type
Definition: meta_list.hpp:178
list_item< typename list1::type, typename concatinate_lists< typename list1::next, list2 >::type > type
Definition: meta_list.hpp:100
Definition: meta_list.hpp:22
next_list_item next
Definition: meta_list.hpp:19
list_item< typename list::type, typename unique_list< typename unique_list_walker< typename list::type, typename list::next >::type >::type > type
Definition: meta_list.hpp:137
unique_list_walker< target, list >::type type
Definition: meta_list.hpp:119