ITK  5.2.0
Insight Toolkit
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  * http://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 namespace itk
25 {
26 
28 namespace mpl
29 {
30 
31 namespace Details
32 {
33 
40 template <int N, typename TA, typename TB>
41 struct SizeToType;
42 
47 template <int N>
48 struct Identity
49 {
50  using Type = char[N];
51 };
52 
58 #define ITK_ASSOCIATE(N, Typed) \
59  template <typename TA, typename TB> \
60  struct SizeToType<N, TA, TB> \
61  { \
62  using Type = Typed; \
63  };
64 
65 ITK_ASSOCIATE(1, TA);
66 ITK_ASSOCIATE(2, TB);
67 
68 ITK_ASSOCIATE(3, short);
69 ITK_ASSOCIATE(4, unsigned short);
70 ITK_ASSOCIATE(5, int);
71 ITK_ASSOCIATE(6, unsigned int);
72 ITK_ASSOCIATE(7, long);
73 ITK_ASSOCIATE(8, unsigned long);
74 ITK_ASSOCIATE(9, long long);
75 ITK_ASSOCIATE(10, unsigned long long);
76 ITK_ASSOCIATE(11, float);
77 ITK_ASSOCIATE(12, double);
78 ITK_ASSOCIATE(13, long double);
79 #undef ITK_ASSOCIATE
80 } // namespace Details
81 
102 template <typename TA, typename TB>
103 struct 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 & Check(typename Details::SizeToType<3, TA, TB>::Type, int);
116  static Details::Identity<4>::Type & Check(typename Details::SizeToType<4, TA, TB>::Type, int);
117  static Details::Identity<5>::Type & Check(typename Details::SizeToType<5, TA, TB>::Type, int);
118  static Details::Identity<6>::Type & Check(typename Details::SizeToType<6, TA, TB>::Type, int);
119  static Details::Identity<7>::Type & Check(typename Details::SizeToType<7, TA, TB>::Type, int);
120  static Details::Identity<8>::Type & Check(typename Details::SizeToType<8, TA, TB>::Type, int);
121  static Details::Identity<9>::Type & Check(typename Details::SizeToType<9, TA, TB>::Type, int);
122  static Details::Identity<10>::Type & Check(typename Details::SizeToType<10, TA, TB>::Type, int);
123  static Details::Identity<11>::Type & Check(typename Details::SizeToType<11, TA, TB>::Type, int);
124  static Details::Identity<12>::Type & Check(typename Details::SizeToType<12, TA, TB>::Type, int);
125  static Details::Identity<13>::Type & Check(typename Details::SizeToType<13, TA, TB>::Type, int);
126 
127 public:
143  using Type = typename Details::SizeToType<sizeof Check(a + b, 0), TA, TB>::Type;
144 };
145 } // end namespace mpl
147 
149 } // end namespace itk
150 
151 #endif // itkPromoteType_h
Details
Definition: itkVariableLengthVector.h:1044
itkMacro.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24