Blaze  3.6
HighType.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_TYPETRAITS_HIGHTYPE_H_
36 #define _BLAZE_MATH_TYPETRAITS_HIGHTYPE_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <blaze/util/Complex.h>
44 #include <blaze/util/InvalidType.h>
45 #include <blaze/util/mpl/If.h>
50 
51 
52 namespace blaze {
53 
54 //=================================================================================================
55 //
56 // CLASS DEFINITION
57 //
58 //=================================================================================================
59 
60 //*************************************************************************************************
65 template< typename T1 // First operand
66  , typename T2 // Second operand
67  , typename = void > // Restricting condition
68 struct HighTypeHelper
69 {
70  public:
71  //**********************************************************************************************
72  using Type = INVALID_TYPE;
73  //**********************************************************************************************
74 };
76 //*************************************************************************************************
77 
78 
79 //*************************************************************************************************
84 template< typename T1, typename T2 >
85 struct HighTypeHelper< T1, T2
86  , EnableIf_t< IsIntegral_v<T1> &&
87  IsIntegral_v<T2> &&
88  ( sizeof( T1 ) < sizeof( T2 ) ) > >
89 {
90  public:
91  //**********************************************************************************************
92  using Type = T2;
93  //**********************************************************************************************
94 };
96 //*************************************************************************************************
97 
98 
99 //*************************************************************************************************
104 template< typename T1, typename T2 >
105 struct HighTypeHelper< T1, T2
106  , EnableIf_t< IsIntegral_v<T1> &&
107  IsIntegral_v<T2> &&
108  ( sizeof( T1 ) > sizeof( T2 ) ) > >
109 {
110  public:
111  //**********************************************************************************************
112  using Type = T1;
113  //**********************************************************************************************
114 };
116 //*************************************************************************************************
117 
118 
119 //*************************************************************************************************
124 template< typename T1, typename T2 >
125 struct HighTypeHelper< T1, T2
126  , EnableIf_t< IsIntegral_v<T1> &&
127  IsIntegral_v<T2> &&
128  ( sizeof( T1 ) == sizeof( T2 ) ) > >
129 {
130  public:
131  //**********************************************************************************************
132  using Type = If_t< IsSigned_v<T1>, T1, T2 >;
133  //**********************************************************************************************
134 };
136 //*************************************************************************************************
137 
138 
139 //*************************************************************************************************
144 template< typename T1, typename T2 >
145 struct HighTypeHelper< T1, T2
146  , EnableIf_t< IsIntegral_v<T1> && IsFloatingPoint_v<T2> > >
147 {
148  public:
149  //**********************************************************************************************
150  using Type = T2;
151  //**********************************************************************************************
152 };
154 //*************************************************************************************************
155 
156 
157 //*************************************************************************************************
162 template< typename T1, typename T2 >
163 struct HighTypeHelper< T1, T2
164  , EnableIf_t< IsFloatingPoint_v<T1> && IsIntegral_v<T2> > >
165 {
166  public:
167  //**********************************************************************************************
168  using Type = T1;
169  //**********************************************************************************************
170 };
172 //*************************************************************************************************
173 
174 
175 //*************************************************************************************************
180 template< typename T1, typename T2 >
181 struct HighTypeHelper< T1, T2
182  , EnableIf_t< IsFloatingPoint_v<T1> && IsFloatingPoint_v<T2> > >
183 {
184  public:
185  //**********************************************************************************************
186  using Type = If_t< ( sizeof( T1 ) < sizeof( T2 ) ), T2, T1 >;
187  //**********************************************************************************************
188 };
190 //*************************************************************************************************
191 
192 
193 //*************************************************************************************************
198 template< typename T1, typename T2 >
199 struct HighTypeHelper< T1, T2
200  , EnableIf_t< IsComplex_v<T1> && !IsComplex_v<T2> > >
201 {
202  public:
203  //**********************************************************************************************
204  using Type = T1;
205  //**********************************************************************************************
206 };
208 //*************************************************************************************************
209 
210 
211 //*************************************************************************************************
216 template< typename T1, typename T2 >
217 struct HighTypeHelper< T1, T2
218  , EnableIf_t< !IsComplex_v<T1> && IsComplex_v<T2> > >
219 {
220  public:
221  //**********************************************************************************************
222  using Type = T2;
223  //**********************************************************************************************
224 };
226 //*************************************************************************************************
227 
228 
229 //*************************************************************************************************
234 template< typename T1, typename T2 >
235 struct HighTypeHelper< T1, T2
236  , EnableIf_t< IsComplex_v<T1> && IsComplex_v<T2> > >
237 {
238  public:
239  //**********************************************************************************************
240  using Type = complex< typename HighTypeHelper< typename T1::value_type, typename T2::value_type >::Type >;
241  //**********************************************************************************************
242 };
244 //*************************************************************************************************
245 
246 
247 //*************************************************************************************************
317 template< typename T1 // First operand
318  , typename T2 // Second operand
319  , typename = void > // Restricting condition
320 struct HighType
321 {
322  public:
323  //**********************************************************************************************
325  using Type = typename HighTypeHelper<T1,T2>::Type;
327  //**********************************************************************************************
328 };
329 //*************************************************************************************************
330 
331 
332 //*************************************************************************************************
345 template< typename T1 // First operand
346  , typename T2 > // Second operand
348 //*************************************************************************************************
349 
350 } // namespace blaze
351 
352 #endif
constexpr bool IsComplex_v
Auxiliary variable template for the IsComplex type trait.The IsComplex_v variable template provides a...
Definition: IsComplex.h:139
typename If< Condition, T1, T2 >::Type If_t
Auxiliary alias template for the If class template.The If_t alias template provides a convenient shor...
Definition: If.h:109
Header file for the IsIntegral type trait.
typename EnableIf< Condition, T >::Type EnableIf_t
Auxiliary type for the EnableIf class template.The EnableIf_t alias declaration provides a convenient...
Definition: EnableIf.h:138
Base template for the HighType type trait.
Definition: HighType.h:320
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Header file for the IsFloatingPoint type trait.
constexpr bool IsFloatingPoint_v
Auxiliary variable template for the IsFloatingPoint type trait.The IsFloatingPoint_v variable templat...
Definition: IsFloatingPoint.h:95
Utility type for generic codes.
typename HighType< T1, T2 >::Type HighType_t
Auxiliary alias declaration for the HighType type trait.The HighType_t alias declaration provides a c...
Definition: HighType.h:347
Header file for the IsSigned type trait.
Header file for the IsComplex type trait.
Header file for the complex data type.
constexpr bool IsIntegral_v
Auxiliary variable template for the IsIntegral type trait.The IsIntegral_v variable template provides...
Definition: IsIntegral.h:95