Tatooine
type_list.h
Go to the documentation of this file.
1#ifndef TATOOINE_TYPE_LIST_H
2#define TATOOINE_TYPE_LIST_H
3//==============================================================================
6//==============================================================================
7namespace tatooine {
8//==============================================================================
18//==============================================================================
19template <typename... Ts>
20struct type_list_impl;
21//==============================================================================
27//==============================================================================
29template <typename TypeList>
31//------------------------------------------------------------------------------
33template <typename TypeList>
35//------------------------------------------------------------------------------
37template <typename... Types>
39 : std::integral_constant<std::size_t, sizeof...(Types)> {};
40//==============================================================================
42//==============================================================================
48//==============================================================================
50template <typename TypeList, std::size_t I>
53//------------------------------------------------------------------------------
55template <typename TypeList, std::size_t I>
57//------------------------------------------------------------------------------
59template <typename Front, typename... Rest, std::size_t I>
60struct type_list_at_impl<type_list_impl<Front, Rest...>, I> {
61 using type = typename type_list_at_impl<type_list_impl<Rest...>, I - 1>::type;
62};
63//------------------------------------------------------------------------------
65template <std::size_t I>
68};
69//------------------------------------------------------------------------------
71template <typename Front, typename... Rest>
72struct type_list_at_impl<type_list_impl<Front, Rest...>, 0> {
73 using type = Front;
74};
75//==============================================================================
77//==============================================================================
82//==============================================================================
83template <typename TypeList>
85//------------------------------------------------------------------------------
86template <typename TypeList>
89//------------------------------------------------------------------------------
90template <typename... Types>
92 using type = variadic::back_type<Types...>;
93};
94//------------------------------------------------------------------------------
95template <>
97};
98//==============================================================================
100//==============================================================================
105//==============================================================================
106template <typename TypeList>
108//------------------------------------------------------------------------------
109template <typename TypeList>
112//------------------------------------------------------------------------------
113template <typename... Types>
115 using type = variadic::front_type<Types...>;
116};
117//------------------------------------------------------------------------------
118template <>
120};
121//==============================================================================
123//==============================================================================
129//==============================================================================
130template <typename TypeList, typename NewBack>
132//------------------------------------------------------------------------------
133template <typename TypeList, typename NewBack>
136//------------------------------------------------------------------------------
137template <typename... Types, typename NewBack>
138struct type_list_push_back_impl<type_list_impl<Types...>, NewBack> {
139 using type = type_list_impl<Types..., NewBack>;
140};
141//==============================================================================
143//==============================================================================
149//==============================================================================
150template <typename TypeList, typename NewFront>
152//------------------------------------------------------------------------------
153template <typename TypeList, typename NewFront>
156//------------------------------------------------------------------------------
157template <typename... Types, typename NewFront>
158struct type_list_push_front_impl<type_list_impl<Types...>, NewFront> {
159 using type = type_list_impl<NewFront, Types...>;
160};
161//==============================================================================
163//==============================================================================
169//==============================================================================
170template <typename TypeList, typename... TypesAccumulator>
172//------------------------------------------------------------------------------
173template <typename TypeList>
175//------------------------------------------------------------------------------
176template <typename T0, typename T1, typename... Rest,
177 typename... TypesAccumulator>
178struct type_list_pop_back_impl<type_list_impl<T0, T1, Rest...>, TypesAccumulator...> {
179 using type = typename type_list_pop_back_impl<type_list_impl<T1, Rest...>,
180 TypesAccumulator..., T0>::type;
181};
182//------------------------------------------------------------------------------
183template <typename T, typename... TypesAccumulator>
184struct type_list_pop_back_impl<type_list_impl<T>, TypesAccumulator...> {
185 using type = type_list_impl<TypesAccumulator...>;
186};
187//------------------------------------------------------------------------------
188template <typename... TypesAccumulator>
189struct type_list_pop_back_impl<type_list_impl<>, TypesAccumulator...> {
190 using type = type_list_impl<TypesAccumulator...>;
191};
192//==============================================================================
194//==============================================================================
200//==============================================================================
201template <typename TypeList>
203//------------------------------------------------------------------------------
204template <typename TypeList>
206//------------------------------------------------------------------------------
207template <typename Front, typename... Back>
209 using type = type_list_impl<Back...>;
210};
211//------------------------------------------------------------------------------
212template <>
215};
216//==============================================================================
218//==============================================================================
222//==============================================================================
223template <typename TypeList, typename T>
225//------------------------------------------------------------------------------
226template <typename TypeList, typename T>
227static auto constexpr type_list_contains =
229//------------------------------------------------------------------------------
230template <typename SetHead, typename... SetRest, typename T>
231struct type_list_contains_impl<type_list_impl<SetHead, SetRest...>, T> {
232 static auto constexpr value =
233 type_list_contains_impl<type_list_impl<SetRest...>, T>::value;
234};
235//------------------------------------------------------------------------------
236template <typename SetHead, typename... SetRest>
237struct type_list_contains_impl<type_list_impl<SetHead, SetRest...>,
238 SetHead> : std::true_type {};
239//------------------------------------------------------------------------------
240template <typename T>
241struct type_list_contains_impl<type_list_impl<>, T> : std::false_type {};
242//==============================================================================
244//==============================================================================
247template <typename... Ts>
249 using this_type = type_list_impl<Ts...>;
250
253 template <typename T>
255 template <typename T>
257
260
261 template <typename T>
262 static bool constexpr contains = type_list_contains<this_type, T>;
263
264 static auto constexpr size = type_list_size<this_type>;
265
266 static bool constexpr empty = size == 0;
267
268 template <std::size_t I>
270};
271//==============================================================================
276template <>
279
280 template <typename T>
282
283 template <typename T>
285
286 template <typename T>
287 static bool constexpr contains = type_list_contains<this_type, T>;
288
289 static auto constexpr size = 0;
290
291 static bool constexpr empty = true;
292
293 template <std::size_t I>
295};
296//==============================================================================
298template <typename... Ts>
301//==============================================================================
302} // namespace tatooine
303//==============================================================================
304#endif
typename type_list_at_impl< TypeList, I >::type type_list_at
Access to the Ith element of TypeList.
Definition: type_list.h:56
typename type_list_back_impl< TypeList >::type type_list_back
Definition: type_list.h:88
static auto constexpr type_list_contains
Definition: type_list.h:227
typename type_list_front_impl< TypeList >::type type_list_front
Definition: type_list.h:111
typename type_list_pop_back_impl< TypeList >::type type_list_pop_back
Definition: type_list.h:174
typename type_list_pop_front_impl< TypeList >::type type_list_pop_front
Definition: type_list.h:205
typename type_list_push_back_impl< TypeList, NewBack >::type type_list_push_back
Definition: type_list.h:135
typename type_list_push_front_impl< TypeList, NewFront >::type type_list_push_front
Definition: type_list.h:155
static auto constexpr type_list_size
Size of a tatooine::type_list_impl.
Definition: type_list.h:34
typename front_type_impl< Ts... >::type front_type
Definition: variadic_helpers.h:41
typename back_type_impl< Ts... >::type back_type
Definition: variadic_helpers.h:57
Definition: algorithm.h:6
T type
Definition: common_type.h:13
typename type_list_at_impl< type_list_impl< Rest... >, I - 1 >::type type
Definition: type_list.h:61
Access to the Ith element of TypeList.
Definition: type_list.h:51
variadic::back_type< Types... > type
Definition: type_list.h:92
Definition: type_list.h:84
Definition: type_list.h:224
variadic::front_type< Types... > type
Definition: type_list.h:115
Definition: type_list.h:107
An empty struct that holds types.
Definition: type_list.h:277
type_list_at< this_type, I > at
Definition: type_list.h:294
type_list_push_front< this_type, T > push_front
Definition: type_list.h:284
type_list_push_back< this_type, T > push_back
Definition: type_list.h:281
An empty struct that holds types.
Definition: type_list.h:248
type_list_pop_front< this_type > pop_front
Definition: type_list.h:259
type_list_front< this_type > front
Definition: type_list.h:251
static bool constexpr empty
Definition: type_list.h:266
type_list_back< this_type > back
Definition: type_list.h:252
static bool constexpr contains
Definition: type_list.h:262
type_list_pop_back< this_type > pop_back
Definition: type_list.h:258
static auto constexpr size
Definition: type_list.h:264
type_list_push_back< this_type, T > push_back
Definition: type_list.h:254
type_list_at< this_type, I > at
Definition: type_list.h:269
type_list_push_front< this_type, T > push_front
Definition: type_list.h:256
Definition: type_list.h:52
typename type_list_pop_back_impl< type_list_impl< T1, Rest... >, TypesAccumulator..., T0 >::type type
Definition: type_list.h:180
Definition: type_list.h:171
Definition: type_list.h:202
Definition: type_list.h:131
Definition: type_list.h:151
Size of a tatooine::type_list_impl.
Definition: type_list.h:30