ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkPromoteType.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkPromoteType_h
19#define itkPromoteType_h
20
21#include "itkMacro.h"
22
23// Simplification of boost::common_type
24
25
27namespace itk::mpl
28{
29
30namespace Details
31{
32
39template <int VTypeEnum, typename TA, typename TB>
40struct SizeToType;
41
46template <int VCharacters>
47struct Identity
48{
49 using Type = char[VCharacters];
50};
51
57#define ITK_ASSOCIATE(VTypeEnum, Typed) \
58 template <typename TA, typename TB> \
59 struct SizeToType<VTypeEnum, TA, TB> \
60 { \
61 using Type = Typed; \
62 }
63
64ITK_ASSOCIATE(1, TA);
65ITK_ASSOCIATE(2, TB);
66
67ITK_ASSOCIATE(3, short);
68ITK_ASSOCIATE(4, unsigned short);
69ITK_ASSOCIATE(5, int);
70ITK_ASSOCIATE(6, unsigned int);
71ITK_ASSOCIATE(7, long);
72ITK_ASSOCIATE(8, unsigned long);
73ITK_ASSOCIATE(9, long long);
74ITK_ASSOCIATE(10, unsigned long long);
75ITK_ASSOCIATE(11, float);
76ITK_ASSOCIATE(12, double);
77ITK_ASSOCIATE(13, long double);
78#undef ITK_ASSOCIATE
79} // namespace Details
80
102template <typename TA, typename TB>
103struct PromoteType
104{
105 static TA a;
106 static TB b;
107
108 // Aimed at supporting overloads
109 template <typename T>
110 static Details::Identity<1>::Type & Check(typename Details::SizeToType<1, TA, TB>::Type, T);
111 template <typename T>
112 static Details::Identity<2>::Type & Check(typename Details::SizeToType<2, TA, TB>::Type, T);
113
114 // Common numeric types
115 static Details::Identity<3>::Type &
116 Check(typename Details::SizeToType<3, TA, TB>::Type, int);
117 static Details::Identity<4>::Type &
118 Check(typename Details::SizeToType<4, TA, TB>::Type, int);
119 static Details::Identity<5>::Type &
120 Check(typename Details::SizeToType<5, TA, TB>::Type, int);
121 static Details::Identity<6>::Type &
122 Check(typename Details::SizeToType<6, TA, TB>::Type, int);
123 static Details::Identity<7>::Type &
124 Check(typename Details::SizeToType<7, TA, TB>::Type, int);
125 static Details::Identity<8>::Type &
126 Check(typename Details::SizeToType<8, TA, TB>::Type, int);
127 static Details::Identity<9>::Type &
128 Check(typename Details::SizeToType<9, TA, TB>::Type, int);
129 static Details::Identity<10>::Type &
130 Check(typename Details::SizeToType<10, TA, TB>::Type, int);
131 static Details::Identity<11>::Type &
132 Check(typename Details::SizeToType<11, TA, TB>::Type, int);
133 static Details::Identity<12>::Type &
134 Check(typename Details::SizeToType<12, TA, TB>::Type, int);
135 static Details::Identity<13>::Type &
136 Check(typename Details::SizeToType<13, TA, TB>::Type, int);
137
138public:
154 using Type = typename Details::SizeToType<sizeof Check(a + b, 0), TA, TB>::Type;
155};
156} // namespace itk::mpl
157
159
160#endif // itkPromoteType_h