Embedded Template Library 1.0
Loading...
Searching...
No Matches
type_select_generator.h
1/******************************************************************************
2The MIT License(MIT)
3
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7
8Copyright(c) 2018 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_SELECT_INCLUDED
30#define ETL_TYPE_SELECT_INCLUDED
31
32#include "platform.h"
33#include "static_assert.h"
34#include "type_traits.h"
35#include "null_type.h"
36
37/*[[[cog
38import cog
39cog.outl("#if 0")
40]]]*/
41/*[[[end]]]*/
42#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
43/*[[[cog
44import cog
45cog.outl("#endif")
46]]]*/
47/*[[[end]]]*/
48
49/*[[[cog
50import cog
51cog.outl("//***************************************************************************")
52cog.outl("// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.")
53cog.outl("//***************************************************************************")
54]]]*/
55/*[[[end]]]*/
56
57namespace etl
58{
59#if ETL_USING_CPP11 && !defined(ETL_TYPE_SELECT_FORCE_CPP03_IMPLEMENTATION)
60 //***************************************************************************
61 // Variadic version.
62 //***************************************************************************
63 template <typename... TTypes>
64 struct type_select
65 {
66 private:
67
68 //***********************************
69 template <size_t ID, size_t N, typename T1, typename... TRest>
70 struct type_select_helper
71 {
72 using type = typename etl::conditional<ID == N,
73 T1,
74 typename type_select_helper<ID, N + 1, TRest...>::type>::type;
75 };
76
77 //***********************************
78 template <size_t ID, size_t N, typename T1>
79 struct type_select_helper<ID, N, T1>
80 {
81 using type = T1;
82 };
83
84 public:
85
86 template <size_t ID>
87 struct select
88 {
89 static_assert(ID < sizeof...(TTypes), "Illegal type_select::select index");
90
91 using type = typename type_select_helper<ID, 0, TTypes...>::type;
92 };
93
94 template <size_t ID>
95 using select_t = typename select<ID>::type;
96 };
97
98 //***************************************************************************
99 // Select type alias
100 //***************************************************************************
101 template <size_t N, typename... TTypes>
102 using type_select_t = typename etl::type_select<TTypes...>:: template select_t<N>;
103
104#else
105
106 /*[[[cog
107 import cog
108 cog.outl("//***************************************************************************")
109 cog.outl("// For %s types." % int(NTypes))
110 cog.outl("//***************************************************************************")
111 cog.outl("template <typename T0,")
112 for n in range(1, int(NTypes) - 1):
113 cog.outl(" typename T%s = void," % n)
114 cog.outl(" typename T%s = void>" %(int(NTypes) - 1))
115 cog.outl("struct type_select")
116 cog.outl("{")
117 cog.outl("public:")
118 cog.outl("")
119 cog.outl(" template <size_t ID>")
120 cog.outl(" struct select")
121 cog.outl(" {")
122 cog.outl(" typedef typename etl::conditional<ID == 0, T0,")
123 for n in range(1, int(NTypes)) :
124 cog.outl(" typename etl::conditional<ID == %s, T%s," % (n, n))
125 cog.outl(" etl::null_type<0> >")
126 cog.out(" ")
127 for n in range(1, int(NTypes)) :
128 cog.out("::type>")
129 if n % 8 == 0:
130 cog.outl("")
131 cog.out(" ")
132 cog.outl("::type type;")
133 cog.outl("");
134 cog.outl(" ETL_STATIC_ASSERT(ID < %s, \"Invalid ID\");" % int(NTypes));
135 cog.outl(" };")
136 cog.outl("};")
137
138 for s in range(int(NTypes) - 1, 0, -1):
139 cog.outl("")
140 cog.outl("//***************************************************************************")
141 cog.outl("// For %s types." % int(s))
142 cog.outl("//***************************************************************************")
143 cog.out("template <")
144 for n in range(0, s - 1):
145 cog.outl("typename T%s, " % n)
146 cog.out(" ")
147 cog.outl("typename T%s>" % (s - 1))
148 cog.out("struct type_select<")
149 for n in range(0, s - 1):
150 cog.out("T%s, " % n)
151 cog.outl("T%s>" % (s - 1))
152 cog.outl("{")
153 cog.outl("public:")
154 cog.outl(" template <size_t ID>")
155 cog.outl(" struct select")
156 cog.outl(" {")
157 cog.outl(" typedef typename etl::conditional<ID == 0, T0,")
158 for n in range(1, s) :
159 cog.outl(" typename etl::conditional<ID == %s, T%s," % (n, n))
160 cog.outl(" etl::null_type<0> >")
161 cog.out(" ")
162 for n in range(1, s) :
163 cog.out("::type>")
164 if n % 8 == 0:
165 cog.outl("")
166 cog.out(" ")
167 cog.outl("::type type;")
168 cog.outl("");
169 cog.outl(" ETL_STATIC_ASSERT(ID < %s, \"Invalid ID\");" % s);
170 cog.outl(" };")
171 cog.outl("};")
172 ]]]*/
173 /*[[[end]]]*/
174#endif
175}
176
177#endif
conditional
Definition type_traits_generator.h:1155
bitset_ext
Definition absolute.h:38
Definition type_select.h:114