Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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
35#ifndef LIB_META_TYPESEQ_UTIL_H
36#define LIB_META_TYPESEQ_UTIL_H
37
38#include "lib/meta/typelist.hpp"
40#include "lib/meta/util.hpp"
41
42
43
44namespace lib {
45namespace meta {
46
47
53 template<class X>
54 constexpr size_t
56 {
57 static_assert (not sizeof(X), "Type not found in type-sequence");
58 return 0;
59 }
60
61 template<class X, class T, class... TYPES>
62 constexpr size_t
64 {
65 if constexpr (std::is_same_v<X,T>)
66 return 0;
67 else
68 return 1 + indexOfType<X,TYPES...>();
69 }
70
75 template<class... TYPES>
76 struct count
77 : SizConst<sizeof...(TYPES)>
78 { };
79 template<class... TYPES>
80 struct count<Types<TYPES...>>
81 : SizConst<sizeof...(TYPES)>
82 { };
83
84
90 template<class T, class TYPES>
91 struct Prepend;
92
93 template<typename T, typename...TYPES>
94 struct Prepend<T, Types<TYPES...>>
95 {
96 using Seq = Types<T, TYPES...>;
97 using List = Types<T, TYPES...>::List;
98 };
99
100
101
107 template<class H, class T>
108 struct Types< Node<H,T> >
109 {
111 using Seq = Prepend< H
112 , typename Types<T>::Seq
113 >::Seq;
114 };
115 template<>
116 struct Types<Nil>
117 {
118 using List = Nil;
119 using Seq = Types<>;
120 };
121 template<>
123 : Types<Nil>
124 { };
125
126
127
128
129
132 template<class TYPES>
133 struct Split;
134
135 template<typename T1, typename...TS>
136 struct Split<Types<T1,TS...> >
137 {
138 using List = Types<T1,TS...>::List;
139
140 using Head = T1;
142 using Tail = Types<TS...>;
143
144 // for finding the end we need the help of typelist-util.hpp
145
147 using TailList = Tail::List;
148
152 };
153
154 template<>
155 struct Split<Types<>>
156 {
157 using List = Nil;
158
159 using Head = Nil;
160 using First = Types<>;
161 using Tail = Types<>;
162
163 // for finding the end we need the help of typelist-util.hpp
164
166 using TailList = Nil;
167
169 using Last = Types<>;
170 using End = Nil;
171 };
172
173
174
175
180 template<class TYPES, uint i=1>
182 {
184 public:
185 using Type = Shifted<Tail,i-1>::Type;
187 };
188
189 template<class TYPES>
190 struct Shifted<TYPES,0>
191 {
192 using Type = TYPES;
194 };
195
196
197
202 template<typename...TYPES, size_t i>
203 struct Pick<Types<TYPES...>, i>
204 {
205 using Type = Shifted<Types<TYPES...>, i>::Head;
206 };
207
208
209
214 template<typename T, size_t N>
215 struct Repeat
216 {
217 using Rem = Repeat<T, N-1>::Seq;
219 };
220
221 template<typename T>
222 struct Repeat<T,0>
223 {
224 using Seq = Types<>;
225 };
226
227
228
229}} // namespace lib::meta
230#endif
Helper: generate a type sequence left shifted by i steps, filling in Nil at the end.
Split< Type >::Head Head
Shifted< Tail, i-1 >::Type Type
Split< TYPES >::Tail Tail
Simple and lightweight helpers for metaprogramming and type detection.
constexpr size_t indexOfType()
Find the index of the first incidence of a type in a type-sequence.
enable_if_c< Cond::value, T >::type enable_if
SFINAE helper to control the visibility of specialisations and overloads.
Definition meta/util.hpp:87
Node< Nil, Nil > NilNode
Definition typelist.hpp:96
Prepend< H, typename Types< T >::Seq >::Seq Seq
Repeat< T, N-1 >::Seq Rem
Shifted< Types< TYPES... >, i >::Head Type
Prepend< T, Rem >::Seq Seq
std::integral_constant< size_t, siz > SizConst
Definition meta/util.hpp:56
»Empty« mark
Definition typelist.hpp:82
Type list with head and tail; T ≡ Nil marks list end.
Definition typelist.hpp:90
pick the n-th element from a typelist
access the last list element
Helper: prepend a type to an existing type sequence, thus shifting all elements within the sequence t...
Generate a type-sequence filled with N times the same type T.
Helper: separate parts of a type sequence.
variadic sequence of types
Definition typelist.hpp:102
Implementation namespace for support and library code.
Metafunction counting the number of Types in the collection.
Metaprogramming: Helpers for manipulating lists-of-types.
A template metaprogramming technique for manipulating collections of types.