MultTrait.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_TRAITS_MULTTRAIT_H_
36 #define _BLAZE_MATH_TRAITS_MULTTRAIT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
47 #include <blaze/util/Complex.h>
48 #include <blaze/util/EnableIf.h>
49 #include <blaze/util/InvalidType.h>
50 #include <blaze/util/mpl/If.h>
54 
55 
56 namespace blaze {
57 
58 //=================================================================================================
59 //
60 // CLASS DEFINITION
61 //
62 //=================================================================================================
63 
64 //*************************************************************************************************
66 template< typename, typename, typename = void > struct MultTrait;
67 template< typename, typename, typename = void > struct MultTraitEval1;
68 template< typename, typename, typename = void > struct MultTraitEval2;
70 //*************************************************************************************************
71 
72 
73 //*************************************************************************************************
75 template< typename T1, typename T2 >
76 auto evalMultTrait( T1&, T2& )
77  -> typename MultTraitEval1<T1,T2>::Type;
78 
79 template< typename T1, typename T2 >
80 auto evalMultTrait( const T1&, const T2& )
81  -> typename MultTrait<T1,T2>::Type;
82 
83 template< typename T1, typename T2 >
84 auto evalMultTrait( const volatile T1&, const T2& )
85  -> typename MultTrait<T1,T2>::Type;
86 
87 template< typename T1, typename T2 >
88 auto evalMultTrait( const T1&, const volatile T2& )
89  -> typename MultTrait<T1,T2>::Type;
90 
91 template< typename T1, typename T2 >
92 auto evalMultTrait( const volatile T1&, const volatile T2& )
93  -> typename MultTrait<T1,T2>::Type;
95 //*************************************************************************************************
96 
97 
98 //*************************************************************************************************
143 template< typename T1 // Type of the left-hand side operand
144  , typename T2 // Type of the right-hand side operand
145  , typename > // Restricting condition
146 struct MultTrait
147 {
148  public:
149  //**********************************************************************************************
151  using Type = decltype( evalMultTrait( std::declval<T1&>(), std::declval<T2&>() ) );
153  //**********************************************************************************************
154 };
155 //*************************************************************************************************
156 
157 
158 //*************************************************************************************************
163 template< typename T >
164 struct MultTrait< T, T, EnableIf_t< IsBuiltin_v<T> > >
165 {
166  public:
167  //**********************************************************************************************
168  using Type = Decay_t<T>;
169  //**********************************************************************************************
170 };
172 //*************************************************************************************************
173 
174 
175 //*************************************************************************************************
180 template< typename T1, typename T2 >
181 struct MultTrait< complex<T1>, T2, EnableIf_t< IsBuiltin_v<T2> > >
182 {
183  public:
184  //**********************************************************************************************
185  using Type = CommonType_t< complex<T1> , T2 >;
186  //**********************************************************************************************
187 };
189 //*************************************************************************************************
190 
191 
192 //*************************************************************************************************
197 template< typename T1, typename T2 >
198 struct MultTrait< T1, complex<T2>, EnableIf_t< IsBuiltin_v<T1> > >
199 {
200  public:
201  //**********************************************************************************************
202  using Type = CommonType_t< T1, complex<T2> >;
203  //**********************************************************************************************
204 };
206 //*************************************************************************************************
207 
208 
209 //*************************************************************************************************
214 template< typename T1, typename T2 >
215 struct MultTrait< complex<T1>, complex<T2> >
216 {
217  public:
218  //**********************************************************************************************
219  using Type = CommonType_t< complex<T1>, complex<T2> >;
220  //**********************************************************************************************
221 };
223 //*************************************************************************************************
224 
225 
226 //*************************************************************************************************
239 template< typename T1, typename T2 >
241 //*************************************************************************************************
242 
243 
244 //*************************************************************************************************
249 template< typename T1 // Type of the left-hand side operand
250  , typename T2 // Type of the right-hand side operand
251  , typename > // Restricting condition
252 struct MultTraitEval1
253 {
254  public:
255  //**********************************************************************************************
256  using Type = typename MultTraitEval2<T1,T2>::Type;
257  //**********************************************************************************************
258 };
260 //*************************************************************************************************
261 
262 
263 //*************************************************************************************************
268 template< typename T1 // Type of the left-hand side operand
269  , typename T2 // Type of the right-hand side operand
270  , typename > // Restricting condition
271 struct MultTraitEval2
272 {
273  private:
274  //**********************************************************************************************
275  struct MultType { using Type = decltype( std::declval<T1>() * std::declval<T2>() ); };
276  struct Failure { using Type = INVALID_TYPE; };
277  //**********************************************************************************************
278 
279  public:
280  //**********************************************************************************************
281  using Type = typename If_t< HasMult_v<T1,T2>, MultType, Failure >::Type;
282  //**********************************************************************************************
283 };
285 //*************************************************************************************************
286 
287 
288 //*************************************************************************************************
293 template< typename T1, typename T2 >
294 struct MultTraitEval2< T1, T2
295  , EnableIf_t< IsRowVector_v<T1> &&
296  IsColumnVector_v<T2> > >
297 {
298  public:
299  //**********************************************************************************************
300  using Type = MultTrait_t< typename T1::ElementType, typename T2::ElementType >;
301  //**********************************************************************************************
302 };
304 //*************************************************************************************************
305 
306 } // namespace blaze
307 
308 #endif
typename Decay< T >::Type Decay_t
Auxiliary alias declaration for the Decay type trait.The Decay_t alias declaration provides a conveni...
Definition: Decay.h:98
Header file for the IsRowVector type trait.
Header file for the Decay 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
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the If class template.
Header file for the HasMult type trait.
constexpr bool IsBuiltin_v
Auxiliary variable template for the IsBuiltin type trait.The IsBuiltin_v variable template provides a...
Definition: IsBuiltin.h:95
Header file for the EnableIf class template.
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.The MultTrait_t alias declaration provid...
Definition: MultTrait.h:240
Header file for the CommonType type trait.
Utility type for generic codes.
Base template for the MultTrait class.
Definition: MultTrait.h:146
constexpr bool IsRowVector_v
Auxiliary variable template for the IsRowVector type trait.The IsRowVector_v variable template provid...
Definition: IsRowVector.h:143
Header file for the IsBuiltin type trait.
Header file for the complex data type.
Header file for the IsColumnVector type trait.