Embedded Template Library 1.0
Loading...
Searching...
No Matches
largest.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2014 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#if 0
32#error THIS HEADER IS A GENERATOR. DO NOT INCLUDE.
33#endif
34
35//***************************************************************************
36// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.
37//***************************************************************************
38
39//***************************************************************************
40// To generate to header file, run this at the command line.
41// Note: You will need Python and COG installed.
42//
43// python -m cogapp -d -e -olargest.h -DNTypes=<n> largest_generator.h
44// Where <n> is the number of types to support.
45//
46// e.g.
47// To generate handlers for up to 16 types...
48// python -m cogapp -d -e -olargest.h -DNTypes=16 largest_generator.h
49//
50// See generate.bat
51//***************************************************************************
52
53#ifndef ETL_LARGEST_INCLUDED
54#define ETL_LARGEST_INCLUDED
55
58
59#include "platform.h"
60#include "type_traits.h"
61#include "smallest.h"
62#include "static_assert.h"
63
64namespace etl
65{
66#if ETL_USING_CPP11 && !defined(ETL_LARGEST_TYPE_FORCE_CPP03_IMPLEMENTATION)
67 //***************************************************************************
72 //***************************************************************************
73 template <typename T1, typename... TRest>
74 class largest_type
75 {
76 private:
77
78 // Define 'largest_other' as 'largest_type' with all but the first parameter.
79 using largest_other = typename largest_type<TRest...>::type;
80
81 public:
82
83 // Set 'type' to be the largest of the first parameter and any of the others.
84 // This is recursive.
86 T1, // TrueType
87 largest_other> // FalseType
88 ::type; // The largest type of the two.
89
90 // The size of the largest type.
91 enum
92 {
94 };
95 };
96
97 //***************************************************************************
98 // Specialisation for one template parameter.
99 //***************************************************************************
100 template <typename T1>
101 class largest_type<T1>
102 {
103 public:
104
105 using type = T1;
106
107 enum
108 {
110 };
111 };
112
113#if ETL_USING_CPP11
114 template <typename... T>
115 using largest_type_t = typename largest_type<T...>::type;
116#endif
117
118#if ETL_USING_CPP17
119 template <typename... T>
120 constexpr size_t largest_type_v = largest_type<T...>::size;
121#endif
122
123#else
124 //***************************************************************************
130 //***************************************************************************
131 template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
132 typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
133 typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
134 typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
136 {
137 // Define 'largest_other' as 'largest_type' with all but the first parameter.
138 typedef typename largest_type<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::type largest_other;
139
140 // Set 'type' to be the largest of the first parameter and any of the others.
141 // This is recursive.
142 typedef typename etl::conditional<(sizeof(T1) > sizeof(largest_other)), // Boolean
143 T1, // TrueType
144 largest_other> // FalseType
145 ::type type; // The largest type of the two.
146
147 // The size of the largest type.
148 enum
149 {
150 size = sizeof(type)
151 };
152 };
153
154 //***************************************************************************
155 // Specialisation for one template parameter.
156 //***************************************************************************
157 template <typename T1>
160 {
161 typedef T1 type;
162
163 enum
164 {
165 size = sizeof(type)
166 };
167 };
168#endif
169
170#if ETL_USING_CPP11 && !defined(ETL_LARGEST_ALIGNMENT_FORCE_CPP03_IMPLEMENTATION)
171 //***************************************************************************
175 //***************************************************************************
176 template <typename T1, typename... TRest>
177 struct largest_alignment
178 {
179 // Define 'largest_other' as 'largest_type' with all but the first parameter.
180 using largest_other = typename largest_alignment<TRest...>::type;
181
182 // Set 'type' to be the largest of the first parameter and any of the others.
183 // This is recursive.
185 T1, // TrueType
186 largest_other> // FalseType
187 ::type; // The largest type of the two.
188
189 // The largest alignment.
190 enum
191 {
193 };
194 };
195
196 //***************************************************************************
197 // Specialisation for one template parameter.
198 //***************************************************************************
199 template <typename T1>
200 struct largest_alignment<T1>
201 {
202 typedef T1 type;
203
204 enum
205 {
207 };
208 };
209
210#if ETL_USING_CPP17
211 template <typename... T>
212 inline constexpr size_t largest_alignment_v = largest_alignment<T...>::value;
213#endif
214
215#else
216 //***************************************************************************
221 //***************************************************************************
222 template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
223 typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
224 typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
225 typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
227 {
228 // Define 'largest_other' as 'largest_type' with all but the first parameter.
229 typedef typename largest_alignment<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::type largest_other;
230
231 // Set 'type' to be the largest of the first parameter and any of the others.
232 // This is recursive.
234 T1, // TrueType
235 largest_other> // FalseType
236 ::type type; // The largest type of the two.
237
238 // The largest alignment.
239 enum
240 {
242 };
243 };
244
245 //***************************************************************************
246 // Specialisation for one template parameter.
247 //***************************************************************************
248 template <typename T1>
251 {
252 typedef T1 type;
253
254 enum
255 {
257 };
258 };
259#endif
260
261 //***************************************************************************
265 //***************************************************************************
266 template <typename T>
267 struct larger_int_type
268 {
269 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type");
270
272 };
273
274#if ETL_USING_CPP11
275 template <typename T>
276 using larger_int_type_t = typename larger_int_type<T>::type;
277#endif
278
279 //***************************************************************************
283 //***************************************************************************
284 template <typename T>
285 struct larger_uint_type
286 {
287 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type");
288
290 };
291
292#if ETL_USING_CPP11
293 template <typename T>
294 using larger_uint_type_t = typename larger_uint_type<T>::type;
295#endif
296
297 //***************************************************************************
302 //***************************************************************************
303 template <typename T, bool IS_SIGNED = etl::is_signed<T>::value>
304 struct larger_type;
305
306 template <typename T>
307 struct larger_type<T, false>
308 {
309 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type");
310
311 typedef typename etl::smallest_uint_for_bits<etl::integral_limits<T>::bits + 1>::type type;
312 };
313
314 template <typename T>
315 struct larger_type<T, true>
316 {
317 ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Must be an integral type");
318
319 typedef typename etl::smallest_int_for_bits<etl::integral_limits<T>::bits + 1>::type type;
320 };
321
322#if ETL_USING_CPP11
323 template <typename T>
324 using larger_type_t = typename larger_type<T>::type;
325#endif
326
327#if ETL_USING_CPP11 && !defined(ETL_LARGEST_FORCE_CPP03_IMPLEMENTATION)
328 //***************************************************************************
332 //***************************************************************************
333 template <typename... T>
334 struct largest
335 {
336 using type = typename etl::largest_type<T...>::type;
337
338 enum
339 {
340 size = etl::largest_type<T...>::size,
341 alignment = etl::largest_alignment<T...>::value
342 };
343 };
344
345#if ETL_USING_CPP11
346 template <typename... T>
347 using largest_t = typename largest<T...>::type;
348#endif
349
350#if ETL_USING_CPP17
351 template <typename... T>
352 inline constexpr size_t largest_size = largest<T...>::size;
353#endif
354
355#else
356 //***************************************************************************
361 //***************************************************************************
362 template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
363 typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
364 typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
365 typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
366 struct largest
367 {
368 typedef typename etl::largest_type<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::type type;
369
370 enum
371 {
374 };
375 };
376#endif
377}
378
379#endif
Definition largest.h:367
Definition largest.h:227
Definition largest.h:136
add_rvalue_reference
Definition type_traits_generator.h:1322
conditional
Definition type_traits_generator.h:1155
is_integral
Definition type_traits_generator.h:996
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1187
Defines a type that is as larger or larger than the specified type. Will return the specified type is...
Definition largest_generator.h:316
pair holds two objects of arbitrary type
Definition utility.h:164
size_of
Definition type_traits_generator.h:1592