Schnek
typelist.hpp
1 /*
2  * typelist.hpp
3  *
4  * Created on: 22 Jun 2023
5  * Author: hschmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2023 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #ifndef SCHNEK_GENERIC_TYPELIST_HPP_
28 #define SCHNEK_GENERIC_TYPELIST_HPP_
29 
30 #include <cstddef>
31 
32 namespace schnek {
33  namespace generic {
34  template<typename... Types>
35  struct TypeList;
36 
37  namespace internal {
38 
39  template<long n, typename T, typename... Types>
40  struct TypeListGet {
41  typedef typename TypeListGet<n-1, Types...>::type type;
42  static constexpr long value = TypeListGet<n-1, Types...>::value + 1;
43  };
44 
45  template<typename T, typename... Types>
46  struct TypeListGet<0, T, Types...> {
47  typedef T type;
48  static constexpr long value = 1;
49  };
50  }
51 
59  template<typename... Types>
60  struct TypeList {
64  static constexpr int size = sizeof...(Types);
65 
72  template<size_t n>
73  struct get
74  {
75  static_assert(n < size, "Index out of bounds");
76  typedef typename internal::TypeListGet<n, Types...>::type type;
77  };
78 
79  };
80  }
81 }
82 
83 #endif // SCHNEK_GENERIC_TYPELIST_HPP_
Definition: typelist.hpp:35
Definition: algo.hpp:30
Definition: typelist.hpp:73
Definition: typelist.hpp:40