The Sparta Modeling Framework
Loading...
Searching...
No Matches
MetaTypeList.hpp
Go to the documentation of this file.
1// <MetaTypeList.hpp> -*- C++ -*-
2
3
12#pragma once
13
14#include <type_traits>
15#include <memory> // For unique_ptr
16
17namespace MetaTypeList {
18
23 template<typename...>
24 class type_list {};
25
31 template<typename...>
32 class create;
33
37 template<typename Head, typename... Tail>
38 class create<type_list<>, Head, Tail...> :
39 public create<type_list<Head>, Tail...> {};
40
45 template<typename Head, typename... Tail, typename... Elements>
46 class create<type_list<Elements...>, Head, Tail...> :
47 public create<type_list<Elements..., Head>, Tail...> {};
48
54 template<typename... Elements>
55 class create<type_list<Elements...>> {
56 public:
57 using type = type_list<Elements...>;
58 };
59
63 template<typename... Elements>
64 using create_t = typename create<type_list<Elements...>>::type;
65
72 template<typename>
73 class frontT;
74
78 template<typename Head, typename... Tail>
79 class frontT<type_list<Head, Tail...>> {
80 public:
81 using type = Head;
82 };
83
87 template<typename List>
88 using front = typename frontT<List>::type;
89
96 template<typename>
98
102 template<typename Head, typename... Tail>
103 class pop_frontT<type_list<Head, Tail...>> {
104 public:
105 using type = type_list<Tail...>;
106 };
107
111 template<typename List>
113
121 template<typename, typename>
123
127 template<typename... Elements, typename NewElement>
128 class push_frontT<type_list<Elements...>, NewElement> {
129 public:
130 using type = type_list<NewElement, Elements...>;
131 };
132
136 template<typename List, typename NewElement>
138
146 template<typename, typename>
148
152 template<typename... Elements, typename NewElement>
153 class push_backT<type_list<Elements...>, NewElement> {
154 public:
155 using type = type_list<Elements..., NewElement>;
156 };
157
161 template<typename List, typename NewElement>
163
169 template<typename List, unsigned N>
170 class nth_elementT : public nth_elementT<pop_front<List>, N-1> {};
171
175 template<typename List>
176 class nth_elementT<List, 0> : public frontT<List> {};
177
181 template<typename List, unsigned N>
183
187 template<typename>
188 class is_empty : public std::false_type {};
189
193 template<>
194 class is_empty<type_list<>> : public std::true_type {};
195
200 template<typename...>
202
207 template<typename Head, typename... Tail>
208 class get_pack_size<type_list<Head, Tail...>> {
209 public:
210 static constexpr std::size_t value =
211 1 + get_pack_size<type_list<Tail...>>::value;
212 };
213
217 template<>
219 public:
220 static constexpr std::size_t value = 0;
221 };
222
228 template<typename...>
229 struct is_meta_typelist : public std::false_type {};
230
235 template<typename... Args>
236 struct is_meta_typelist<MetaTypeList::type_list<Args...>> : public std::true_type {};
237
242 template<std::size_t, typename...>
244
250 template<std::size_t S, typename T, typename Head, typename... Tail>
251 class get_index<S, T, type_list<Head, Tail...>,
252 typename std::enable_if<std::is_same<T, Head>::value>::type> {
253 public:
254 static constexpr std::size_t value = (S - sizeof...(Tail)) - 1;
255 };
256
262 template<std::size_t S, typename T, typename Head, typename... Tail>
263 class get_index<S, T, type_list<Head, Tail...>,
264 typename std::enable_if<!std::is_same<T, Head>::value>::type> :
265 public get_index<S, T, type_list<Tail...>> {};
266
267} // namespace MetaTypeList
268
typename pop_frontT< List >::type pop_front
pop_frontT Alias Template.
typename nth_elementT< List, N >::type nth_element
nth_elementT Alias Template.
typename push_frontT< List, NewElement >::type push_front
push_frontT Alias Template.
typename create< type_list< Elements... > >::type create_t
create Alias Template.
typename frontT< List >::type front
frontT Alias Template.
typename push_backT< List, NewElement >::type push_back
push_backT Alias Template.
The Variadic Class Template create takes a variable number of different types and creates a well-form...
The class template frontT takes type_list as template param. and typedefs the type of the first templ...
Class Template to return the index of a certain type in a certain typelist.
Class Template get_pack_size return the current number of types in the type_list.
Class Template is_empty Generic case.
This class template gives us the type of Nth element in a type_list by taking advantage of the nested...
The class template pop_frontT takes type_list as template param., extracts out the first type in type...
The class template push_backT takes an existing type_list and a new type, inserts that new type at en...
The class template push_frontT takes an existing type_list and a new type, inserts that new type at f...
The variadic class template type_list has no implementation and is empty by itself.
Variadic Class Template which takes a type and matches it if that is a type_list. Generic case result...