Lumiera  0.pre.03
»edit your freedom«
typeseq-util.hpp
Go to the documentation of this file.
1 /*
2  TYPESEQ-UTIL.hpp - basic metaprogramming utilities for type sequences
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 
55 #ifndef LIB_META_TYPESEQ_UTIL_H
56 #define LIB_META_TYPESEQ_UTIL_H
57 
58 #include "lib/meta/typelist.hpp"
60 #include "lib/meta/util.hpp"
61 
62 
63 
64 namespace lib {
65 namespace meta {
66 
67 
68 
74  template<class T, class TYPES>
75  struct Prepend;
76 
77  template< typename T01
78  , typename T02
79  , typename T03
80  , typename T04
81  , typename T05
82  , typename T06
83  , typename T07
84  , typename T08
85  , typename T09
86  , typename T10
87  , typename T11
88  , typename T12
89  , typename T13
90  , typename T14
91  , typename T15
92  , typename T16
93  , typename T17
94  , typename T18
95  , typename T19
96  , typename T20
97  , typename IGN
98  >
99  struct Prepend<T01, Types< T02,T03,T04,T05
100  , T06,T07,T08,T09,T10
101  , T11,T12,T13,T14,T15
102  , T16,T17,T18,T19,T20
103  , IGN
104  > >
105  {
106  typedef Types< T01,T02,T03,T04,T05
107  , T06,T07,T08,T09,T10
108  , T11,T12,T13,T14,T15
109  , T16,T17,T18,T19,T20 > Seq;
110 
111  typedef typename Seq::List List;
112  };
113 
114 
115 
120  template<class H, class T>
121  struct Types< Node<H,T> >
122  {
123  typedef Node<H,T> List;
124 
125  typedef typename Prepend< H
126  , typename Types<T>::Seq
127  >::Seq Seq;
128  };
129 
130 
131 
132 
133 
134 
136  template<class TYPES>
137  struct Split;
138 
139  template< typename T01
140  , typename T02
141  , typename T03
142  , typename T04
143  , typename T05
144  , typename T06
145  , typename T07
146  , typename T08
147  , typename T09
148  , typename T10
149  , typename T11
150  , typename T12
151  , typename T13
152  , typename T14
153  , typename T15
154  , typename T16
155  , typename T17
156  , typename T18
157  , typename T19
158  , typename T20
159  >
160  struct Split<Types< T01,T02,T03,T04,T05
161  , T06,T07,T08,T09,T10
162  , T11,T12,T13,T14,T15
163  , T16,T17,T18,T19,T20
164  > >
165  {
166  typedef typename
167  Types< T01,T02,T03,T04,T05
168  , T06,T07,T08,T09,T10
169  , T11,T12,T13,T14,T15
170  , T16,T17,T18,T19,T20
171  >::List List;
172 
173  typedef T01 Head;
174  typedef Types< T01 > First;
175  typedef Types< T02,T03,T04,T05
176  , T06,T07,T08,T09,T10
177  , T11,T12,T13,T14,T15
178  , T16,T17,T18,T19,T20 > Tail;
179 
180  // for finding the end we need the help of typelist-util.hpp
181 
182  typedef typename SplitLast<List>::List PrefixList;
183  typedef typename Tail::List TailList;
184 
185  typedef typename Types<PrefixList>::Seq Prefix;
186  typedef typename SplitLast<List>::Type End;
187  typedef Types<End> Last;
188  };
189 
190 
191 
192 
197  template<class TYPES, uint i=1>
198  class Shifted
199  {
200  typedef typename Split<TYPES>::Tail Tail;
201  public:
202  typedef typename Shifted<Tail,i-1>::Type Type;
203  typedef typename Split<Type>::Head Head;
204  };
205 
206  template<class TYPES>
207  struct Shifted<TYPES,0>
208  {
209  typedef TYPES Type;
210  typedef typename Split<Type>::Head Head;
211  };
212 
213 
214 
219  template<typename...TYPES, size_t i>
220  struct Pick<Types<TYPES...>, i>
221  {
222  using Type = typename lib::meta::Shifted<Types<TYPES...>, i>::Head;
223  };
224 
225 
226 
227 
228 
229 }} // namespace lib::meta
230 #endif
A template metaprogramming technique for manipulating collections of types.
Simple and lightweight helpers for metaprogramming and type detection.
Helper: prepend a type to an existing type sequence, thus shifting all elements within the sequence t...
Implementation namespace for support and library code.
Helper: separate parts of a type sequence.
pick the n-th element from a typelist
access the last list element
Helper: generate a type sequence left shifted by i steps, filling in NullType at the end...
Metaprogramming: Helpers for manipulating lists-of-types.