Embedded Template Library 1.0
Loading...
Searching...
No Matches
type_list.h
1/******************************************************************************
2The MIT License(MIT)
3
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7
8Copyright(c) 2025 John Wellbelove
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files(the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions :
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27******************************************************************************/
28
29#ifndef ETL_TYPE_LIST_INCLUDED
30#define ETL_TYPE_LIST_INCLUDED
31
32#include "platform.h"
33#include "nth_type.h"
34#include "static_assert.h"
35#include "type_traits.h"
36#include "utility.h"
37
38#if ETL_USING_CPP11
39namespace etl
40{
41 //***************************************************************************
43 //***************************************************************************
44 template <typename... TTypes>
45 struct type_list;
46
47 //***************************************************************************
49 //***************************************************************************
50 template <>
51 struct type_list<>
52 {
53 static constexpr size_t size = 0U;
54
56
57 private:
58
59 type_list() ETL_DELETE;
60 type_list(const type_list&) ETL_DELETE;
61 type_list& operator =(const type_list&) ETL_DELETE;
62 };
63
64 //***************************************************************************
66 //***************************************************************************
69 {
70 using type = THead;
71
72 static constexpr size_t size = sizeof...(TTail) + 1U;
73
74 using index_sequence_type = etl::make_index_sequence<sizeof...(TTail) + 1U>;
75
76 private:
77
78 type_list() ETL_DELETE;
79 type_list(const type_list&) ETL_DELETE;
80 type_list& operator =(const type_list&) ETL_DELETE;
81 };
82
83 //***************************************************************************
85 //***************************************************************************
88 {
89 using type = THead;
90
91 static constexpr size_t size = 1U;
92
94
95 private:
96
97 type_list() ETL_DELETE;
98 type_list(const type_list&) ETL_DELETE;
99 type_list& operator =(const type_list&) ETL_DELETE;
100 };
101
102 //***************************************************************************
104 //***************************************************************************
105 template <size_t N, typename THead, typename... TTail>
107 {
108 ETL_STATIC_ASSERT(N <= sizeof...(TTail), "etl::nth_type out of range for etl::type_list");
109
110 using type = typename nth_type<N - 1, type_list<TTail...>>::type;
111 };
112
113 //***************************************************************************
115 //***************************************************************************
116 template <typename THead, typename... TTail>
117 struct nth_type<0, type_list<THead, TTail...>>
118 {
119 using type = THead;
120 };
121
122 //***************************************************************************
124 //***************************************************************************
125 template <size_t N>
126 struct nth_type<N, type_list<>>
127 {
128 };
129
130 //***************************************************************************
132 //***************************************************************************
133 template <typename TTypeList, size_t... Indices>
134 struct type_list_select
135 {
136 using type = type_list<nth_type_t<Indices, TTypeList>...>;
137 };
138
139 template <typename TTypeList, size_t... Indices>
140 using type_list_select_t = typename type_list_select<TTypeList, Indices...>::type;
141
142 //***************************************************************************
144 //***************************************************************************
145 template <typename... TTypes>
146 struct type_list_size;
147
148 template <typename... TTypes>
149 struct type_list_size<etl::type_list<TTypes...>> : public etl::integral_constant<size_t, sizeof...(TTypes)>
150 {
151 };
152
153#if ETL_USING_CPP17
154 template <typename... TTypes>
155 inline constexpr size_t type_list_size_v = type_list_size<etl::type_list<TTypes...>>::value;
156#endif
157
158 //***************************************************************************
160 //***************************************************************************
161 template <typename... TypeLists>
162 struct type_list_cat;
163
164 //***************************************************************************
167 //***************************************************************************
168 template <typename TypeList>
169 struct type_list_cat<TypeList>
170 {
171 using type = TypeList;
172 };
173
174 //***************************************************************************
177 //***************************************************************************
178 template <typename... TTypes1, typename... TTypes2, typename... TTail>
179 struct type_list_cat<etl::type_list<TTypes1...>, etl::type_list<TTypes2...>, TTail...>
180 {
181 using type = typename type_list_cat<etl::type_list<TTypes1..., TTypes2...>, TTail...>::type;
182 };
183}
184#endif
185
186#endif
integral_constant
Definition type_traits_generator.h:827
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
pair holds two objects of arbitrary type
Definition utility.h:164
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:176