Embedded Template Library 1.0
Loading...
Searching...
No Matches
smallest_cpp03_generator.h
1/******************************************************************************
2The MIT License(MIT)
3
4Embedded Template Library.
5https://github.com/ETLCPP/etl
6https://www.etlcpp.com
7
8Copyright(c) 2026 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//***************************************************************************
30// THIS FILE HAS BEEN AUTO GENERATED. DO NOT EDIT THIS FILE.
31//***************************************************************************
32
33/*[[[cog
34import cog
35cog.outl("//***************************************************************************")
36cog.outl("/// Template to determine the smallest type and size.")
37cog.outl("/// Supports up to %s types." % NTypes)
38cog.outl("/// Defines 'value_type' which is the type of the smallest parameter.")
39cog.outl("/// Defines 'size' which is the size of the smallest parameter.")
40cog.outl("///\\ingroup smallest")
41cog.outl("//***************************************************************************")
42cog.out("template <typename T1, ")
43for n in range(2, int(NTypes)):
44 cog.out("typename T%s = void, " % n)
45 if n % 4 == 0:
46 cog.outl("")
47 cog.out(" ")
48cog.outl("typename T%s = void>" % int(NTypes))
49cog.outl("struct smallest_type")
50cog.outl("{")
51cog.outl("private:")
52cog.outl("")
53cog.outl(" // Declaration.")
54cog.outl(" template <bool Boolean, typename TrueType, typename FalseType>")
55cog.outl(" struct choose_type;")
56cog.outl("")
57cog.outl(" // Specialisation for 'true'.")
58cog.outl(" // Defines 'type' as 'TrueType'.")
59cog.outl(" template <typename TrueType, typename FalseType>")
60cog.outl(" struct choose_type<true, TrueType, FalseType>")
61cog.outl(" {")
62cog.outl(" typedef TrueType type;")
63cog.outl(" };")
64cog.outl("")
65cog.outl(" // Specialisation for 'false'. ")
66cog.outl(" // Defines 'type' as 'FalseType'.")
67cog.outl(" template <typename TrueType, typename FalseType>")
68cog.outl(" struct choose_type<false, TrueType, FalseType>")
69cog.outl(" {")
70cog.outl(" typedef FalseType type;")
71cog.outl(" };")
72cog.outl("")
73cog.outl("public:")
74cog.outl("")
75cog.outl(" // Define 'smallest_other' as 'smallest_type' with all but the first parameter. ")
76cog.out(" typedef typename smallest_type<")
77for n in range(2, int(NTypes)):
78 cog.out("T%s, " % n)
79 if n % 16 == 0:
80 cog.outl("")
81 cog.out(" ")
82cog.outl("T%s>::type smallest_other;" % int(NTypes))
83cog.outl("")
84cog.outl(" // Set 'type' to be the smallest of the first parameter and any of the others.")
85cog.outl(" // This is recursive.")
86cog.outl(" typedef typename choose_type<(sizeof(T1) < sizeof(smallest_other)), // Boolean")
87cog.outl(" T1, // TrueType")
88cog.outl(" smallest_other> // FalseType")
89cog.outl(" ::type type; // The smallest type of the two.")
90cog.outl("")
91cog.outl(" // The size of the smallest type.")
92cog.outl(" enum")
93cog.outl(" {")
94cog.outl(" size = sizeof(type)")
95cog.outl(" };")
96cog.outl("};")
97cog.outl("")
98cog.outl("//***************************************************************************")
99cog.outl("// Specialisation for one template parameter.")
100cog.outl("//***************************************************************************")
101cog.outl("template <typename T1>")
102cog.out("struct smallest_type<T1, ")
103for n in range(2, int(NTypes)):
104 cog.out("void, ")
105 if n % 8 == 0:
106 cog.outl("")
107 cog.out(" ")
108cog.outl("void>")
109cog.outl("{")
110cog.outl(" typedef T1 type;")
111cog.outl("")
112cog.outl(" enum")
113cog.outl(" {")
114cog.outl(" size = sizeof(type)")
115cog.outl(" };")
116cog.outl("};")
117]]]*/
118/*[[[end]]]*/