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