SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
typelist.h
1#pragma once
2
3#include "spark/mpl/type_seq.h"
4
5namespace spark::mpl
6{
7 template <typename... Ts>
8 struct typelist;
9
10 // Base struct contains values and methods available in all typelists specializations
11 template <typename... Ts>
13 {
17 inline static constexpr std::size_t size = type_seq::size_v<Ts...>;
18
22 inline static constexpr bool empty = type_seq::empty_v<Ts...>;
23
28 template <typename T>
29 inline static constexpr bool contains = type_seq::contains_v<T, Ts...>;
30
35 template <typename T>
36 using push_front = type_seq::push_front_t<T, typelist<Ts...>>;
37
42 template <typename T>
43 using push_back = type_seq::push_back_t<T, typelist<Ts...>>;
44
49
54 template <template <typename...> typename T>
55 using convert = type_seq::convert_t<T, Ts...>;
56 };
57
58 // Specialization for empty typelist
59 template <>
60 struct typelist<> : typelist_base<> {};
61
62 // Specialization for typelist with at least one type
63 template <typename First, typename... Ts>
64 struct typelist<First, Ts...> : typelist_base<First, Ts...>
65 {
70 template <typename T>
71 inline static constexpr std::size_t index_of = type_seq::index_of_v<T, First, Ts...>;
72
77 template <typename T>
78 inline static constexpr std::size_t find = type_seq::find_v<T, Ts...>;
79
83 using front = type_seq::front_t<First, Ts...>;
84
88 using back = type_seq::back_t<First, Ts...>;
89
93 using pop_front = type_seq::pop_front_t<typelist<First, Ts...>>;
94
98 using pop_back = type_seq::pop_back_t<typelist<First, Ts...>>;
99
104 template <std::size_t N>
105 using at = type_seq::at_t<N, typelist<First, Ts...>>;
106
111 template <typename T>
112 using erase = type_seq::erase_t<T, typelist<First, Ts...>>;
113
118 template <std::size_t N>
119 using erase_at = type_seq::erase_at_t<N, typelist<First, Ts...>>;
120
126 template <std::size_t N, typename T>
127 using insert_at = type_seq::insert_at_t<N, T, typelist<First, Ts...>>;
128
134 template <typename T, typename U>
135 using replace = type_seq::replace_t<T, U, typelist<First, Ts...>>;
136
142 template <std::size_t N, typename T>
143 using replace_at = type_seq::replace_at_t<N, T, typelist<First, Ts...>>;
144
148 using reverse = type_seq::reverse_t<typelist<First, Ts...>>;
149
154 template <template <typename> typename F>
155 using filter = type_seq::filter_t<F, typelist<First, Ts...>>;
156
161 template <template <typename...> typename T>
162 using convert = type_seq::convert_t<T, First, Ts...>;
163
168 template <template <typename> typename F>
169 using transform = type_seq::transform_t<F, typelist<First, Ts...>>;
170 };
171
176 template <typename... Lists>
177 using typelist_concat = type_seq::concat_t<Lists...>;
178
183 template <typename List>
184 using typelist_flatten = type_seq::flatten_t<List>;
185
192 template <template <typename, typename> typename Matcher, typename L1, typename L2>
193 static constexpr bool typelist_match = type_seq::match_v<Matcher, L1, L2>;
194}
type_seq::insert_at_t< N, T, typelist< First, Ts... > > insert_at
Insert a type at the index N of the typelist.
Definition typelist.h:127
type_seq::pop_back_t< typelist< First, Ts... > > pop_back
Remove the last type of the typelist.
Definition typelist.h:98
type_seq::reverse_t< typelist< First, Ts... > > reverse
Reverse the typelist.
Definition typelist.h:148
type_seq::replace_at_t< N, T, typelist< First, Ts... > > replace_at
Replace the type at index N by the type T in the typelist.
Definition typelist.h:143
type_seq::replace_t< T, U, typelist< First, Ts... > > replace
Replace the type T by the type U in the typelist.
Definition typelist.h:135
type_seq::transform_t< F, typelist< First, Ts... > > transform
Apply the function F to each type of the typelist.
Definition typelist.h:169
type_seq::filter_t< F, typelist< First, Ts... > > filter
Filter the typelist with the predicate F.
Definition typelist.h:155
type_seq::erase_t< T, typelist< First, Ts... > > erase
Erase the type T from the typelist.
Definition typelist.h:112
type_seq::pop_front_t< typelist< First, Ts... > > pop_front
Remove the first type of the typelist.
Definition typelist.h:93
type_seq::back_t< First, Ts... > back
The last type of the typelist.
Definition typelist.h:88
type_seq::at_t< N, typelist< First, Ts... > > at
Get the type at the index N.
Definition typelist.h:105
type_seq::convert_t< T, First, Ts... > convert
Convert the typelist with the function F.
Definition typelist.h:162
type_seq::front_t< First, Ts... > front
The first type of the typelist.
Definition typelist.h:83
type_seq::erase_at_t< N, typelist< First, Ts... > > erase_at
Erase the type at index N from the typelist.
Definition typelist.h:119
Definition typelist.h:60
Definition typelist.h:13
static constexpr std::size_t size
Number of elements in the typelist.
Definition typelist.h:17
type_seq::push_back_t< T, typelist< Ts... > > push_back
Add a type at the back of the typelist.
Definition typelist.h:43
type_seq::push_front_t< T, typelist< Ts... > > push_front
Add a type at the front of the typelist.
Definition typelist.h:36
static constexpr bool contains
Is the typelist contains the type T.
Definition typelist.h:29
static constexpr bool empty
Is the typelist empty.
Definition typelist.h:22
type_seq::convert_t< T, Ts... > convert
Convert the typelist with the function F.
Definition typelist.h:55
Definition typelist.h:8