Embedded Template Library
1.0
Loading...
Searching...
No Matches
largest.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2014 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
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
64
namespace
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.
85
using
type =
typename
etl::conditional
<(
etl::size_of<T1>::value
>
etl::size_of<largest_other>::value
),
// Boolean
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
{
93
size =
etl::size_of<type>::value
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
{
109
size =
etl::size_of<type>::value
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
>
135
struct
largest_type
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>
158
struct
largest_type
<
T1
,
void
,
void
,
void
,
void
,
void
,
void
,
void
,
159
void
,
void
,
void
,
void
,
void
,
void
,
void
,
void
>
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.
184
using
type =
typename
etl::conditional
<(
etl::alignment_of<T1>::value
>
etl::alignment_of<largest_other>::value
),
// Boolean
185
T1
,
// TrueType
186
largest_other>
// FalseType
187
::type;
// The largest type of the two.
188
189
// The largest alignment.
190
enum
191
{
192
value =
etl::alignment_of<type>::value
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
{
206
value =
etl::alignment_of<type>::value
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
>
226
struct
largest_alignment
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.
233
typedef
typename
etl::conditional
<(
etl::alignment_of<T1>::value
>
etl::alignment_of<largest_other>::value
),
// Boolean
234
T1
,
// TrueType
235
largest_other>
// FalseType
236
::type type;
// The largest type of the two.
237
238
// The largest alignment.
239
enum
240
{
241
value =
etl::alignment_of<type>::value
242
};
243
};
244
245
//***************************************************************************
246
// Specialisation for one template parameter.
247
//***************************************************************************
248
template
<
typename
T1>
249
struct
largest_alignment
<
T1
,
void
,
void
,
void
,
void
,
void
,
void
,
void
,
250
void
,
void
,
void
,
void
,
void
,
void
,
void
,
void
>
251
{
252
typedef
T1
type
;
253
254
enum
255
{
256
value =
etl::alignment_of<type>::value
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
271
typedef
typename
etl::smallest_int_for_bits<etl::integral_limits<typename etl::make_signed<T>::type
>::bits + 1>::type type;
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
289
typedef
typename
etl::smallest_uint_for_bits<etl::integral_limits<typename etl::make_unsigned<T>::type
>::bits + 1>::type type;
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
{
372
size =
etl::largest_type<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::size
,
373
alignment =
etl::largest_alignment<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>::value
374
};
375
};
376
#endif
377
}
378
379
#endif
etl::largest
Definition
largest.h:367
etl::largest_alignment
Definition
largest.h:227
etl::largest_type
Definition
largest.h:136
etl::alignment_of
add_rvalue_reference
Definition
type_traits_generator.h:1327
etl::conditional
conditional
Definition
type_traits_generator.h:1160
etl::is_integral
is_integral
Definition
type_traits_generator.h:1001
etl
bitset_ext
Definition
absolute.h:38
etl::size
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition
iterator.h:1187
platform.h
smallest.h
etl::larger_int_type
Defines a type that is as larger or larger than the specified type. Will return the specified type is...
Definition
largest_generator.h:316
etl::pair
pair holds two objects of arbitrary type
Definition
utility.h:164
etl::size_of
size_of
Definition
type_traits_generator.h:1597
type_traits.h
include
etl
largest.h
Generated on Thu Jan 2 2025 19:14:45 for Embedded Template Library by
1.9.8