sandbox
Loading...
Searching...
No Matches
type_list.hpp
1#ifndef LIBSBX_UTILITY_TYPE_LIST_HPP_
2#define LIBSBX_UTILITY_TYPE_LIST_HPP_
3
4#include <cstddef>
5
6namespace sbx::utility {
7
8template<typename... Type>
9struct type_list {
10 using type = type_list;
11 inline static constexpr auto size = sizeof...(Type);
12}; // struct type_list
13
14template<std::size_t, typename>
16
17template<std::size_t Index, typename First, typename... Other>
18struct type_list_element<Index, type_list<First, Other...>> : type_list_element<Index - 1u, type_list<Other...>> { };
19
20template<typename First, typename... Other>
21struct type_list_element<0u, type_list<First, Other...>> {
22 using type = First;
23}; // struct type_list_element
24
25template<std::size_t Index, typename List>
26using type_list_element_t = typename type_list_element<Index, List>::type;
27
28template<typename, typename>
30
31template<typename Type, typename First, typename... Other>
32struct type_list_index<Type, type_list<First, Other...>> {
33 using value_type = std::size_t;
34 inline static constexpr auto value = 1u + type_list_index<Type, type_list<Other...>>::value;
35}; // struct type_list_index
36
37template<typename Type, typename... Other>
38requires (type_list_index<Type, type_list<Other...>>::value == sizeof...(Other))
39struct type_list_index<Type, type_list<Type, Other...>> {
40 using value_type = std::size_t;
41 inline static constexpr auto value = 0u;
42}; // struct type_list_index
43
44template<typename Type>
45struct type_list_index<Type, type_list<>> {
46 using value_type = std::size_t;
47 inline static constexpr auto value = 0u;
48}; // struct type_list_index
49
50template<typename Type, typename List>
51inline constexpr auto type_list_index_v = type_list_index<Type, List>::value;
52
53} // namespace sbx::utility
54
55#endif // LIBSBX_UTILITY_TYPE_LIST_HPP_
Definition: type_list.hpp:15
Definition: type_list.hpp:29
Definition: type_list.hpp:9