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)
5  2009, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 */
13 
14 
46 #ifndef LIB_META_TYPESEQ_UTIL_H
47 #define LIB_META_TYPESEQ_UTIL_H
48 
49 #include "lib/meta/typelist.hpp"
51 #include "lib/meta/util.hpp"
52 
53 
54 
55 namespace lib {
56 namespace meta {
57 
58 
64  template<class X>
65  constexpr size_t
67  {
68  static_assert (not sizeof(X), "Type not found in type-sequence");
69  return 0;
70  }
71 
72  template<class X, class T, class... TYPES>
73  constexpr size_t
74  indexOfType()
75  {
76  if constexpr (std::is_same_v<X,T>)
77  return 0;
78  else
79  return 1 + indexOfType<X,TYPES...>();
80  }
81 
82 
88  template<class T, class TYPES>
89  struct Prepend;
90 
91  template< typename T01
92  , typename T02
93  , typename T03
94  , typename T04
95  , typename T05
96  , typename T06
97  , typename T07
98  , typename T08
99  , typename T09
100  , typename T10
101  , typename T11
102  , typename T12
103  , typename T13
104  , typename T14
105  , typename T15
106  , typename T16
107  , typename T17
108  , typename T18
109  , typename T19
110  , typename T20
111  , typename IGN
112  >
113  struct Prepend<T01, Types< T02,T03,T04,T05
114  , T06,T07,T08,T09,T10
115  , T11,T12,T13,T14,T15
116  , T16,T17,T18,T19,T20
117  , IGN
118  > >
119  {
120  typedef Types< T01,T02,T03,T04,T05
121  , T06,T07,T08,T09,T10
122  , T11,T12,T13,T14,T15
123  , T16,T17,T18,T19,T20 > Seq;
124 
125  typedef typename Seq::List List;
126  };
127 
128 
129 
134  template<class H, class T>
135  struct Types< Node<H,T> >
136  {
137  typedef Node<H,T> List;
138 
139  typedef typename Prepend< H
140  , typename Types<T>::Seq
141  >::Seq Seq;
142  };
143 
144 
145 
146 
147 
148 
150  template<class TYPES>
151  struct Split;
152 
153  template< typename T01
154  , typename T02
155  , typename T03
156  , typename T04
157  , typename T05
158  , typename T06
159  , typename T07
160  , typename T08
161  , typename T09
162  , typename T10
163  , typename T11
164  , typename T12
165  , typename T13
166  , typename T14
167  , typename T15
168  , typename T16
169  , typename T17
170  , typename T18
171  , typename T19
172  , typename T20
173  >
174  struct Split<Types< T01,T02,T03,T04,T05
175  , T06,T07,T08,T09,T10
176  , T11,T12,T13,T14,T15
177  , T16,T17,T18,T19,T20
178  > >
179  {
180  typedef typename
181  Types< T01,T02,T03,T04,T05
182  , T06,T07,T08,T09,T10
183  , T11,T12,T13,T14,T15
184  , T16,T17,T18,T19,T20
185  >::List List;
186 
187  typedef T01 Head;
188  typedef Types< T01 > First;
189  typedef Types< T02,T03,T04,T05
190  , T06,T07,T08,T09,T10
191  , T11,T12,T13,T14,T15
192  , T16,T17,T18,T19,T20 > Tail;
193 
194  // for finding the end we need the help of typelist-util.hpp
195 
196  typedef typename SplitLast<List>::List PrefixList;
197  typedef typename Tail::List TailList;
198 
199  typedef typename Types<PrefixList>::Seq Prefix;
200  typedef typename SplitLast<List>::Type End;
201  typedef Types<End> Last;
202  };
203 
204 
205 
206 
211  template<class TYPES, uint i=1>
212  class Shifted
213  {
214  typedef typename Split<TYPES>::Tail Tail;
215  public:
216  typedef typename Shifted<Tail,i-1>::Type Type;
217  typedef typename Split<Type>::Head Head;
218  };
219 
220  template<class TYPES>
221  struct Shifted<TYPES,0>
222  {
223  typedef TYPES Type;
224  typedef typename Split<Type>::Head Head;
225  };
226 
227 
228 
233  template<typename...TYPES, size_t i>
234  struct Pick<Types<TYPES...>, i>
235  {
236  using Type = typename lib::meta::Shifted<Types<TYPES...>, i>::Head;
237  };
238 
239 
240 
241 
242 
243 }} // namespace lib::meta
244 #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
constexpr size_t indexOfType()
Find the index of the first incidence of a type in a type-sequence.
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.