AddTrait.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_TRAITS_ADDTRAIT_H_
36 #define _BLAZE_MATH_TRAITS_ADDTRAIT_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
43 #include <utility>
45 #include <blaze/util/Complex.h>
46 #include <blaze/util/EnableIf.h>
47 #include <blaze/util/InvalidType.h>
48 #include <blaze/util/mpl/If.h>
52 
53 
54 namespace blaze {
55 
56 //=================================================================================================
57 //
58 // CLASS DEFINITION
59 //
60 //=================================================================================================
61 
62 //*************************************************************************************************
64 template< typename, typename, typename = void > struct AddTrait;
65 template< typename, typename, typename = void > struct AddTraitEval1;
66 template< typename, typename, typename = void > struct AddTraitEval2;
68 //*************************************************************************************************
69 
70 
71 //*************************************************************************************************
73 template< typename T1, typename T2 >
74 auto evalAddTrait( T1&, T2& )
75  -> typename AddTraitEval1<T1,T2>::Type;
76 
77 template< typename T1, typename T2 >
78 auto evalAddTrait( const T1&, const T2& )
79  -> typename AddTrait<T1,T2>::Type;
80 
81 template< typename T1, typename T2 >
82 auto evalAddTrait( const volatile T1&, const T2& )
83  -> typename AddTrait<T1,T2>::Type;
84 
85 template< typename T1, typename T2 >
86 auto evalAddTrait( const T1&, const volatile T2& )
87  -> typename AddTrait<T1,T2>::Type;
88 
89 template< typename T1, typename T2 >
90 auto evalAddTrait( const volatile T1&, const volatile T2& )
91  -> typename AddTrait<T1,T2>::Type;
93 //*************************************************************************************************
94 
95 
96 //*************************************************************************************************
141 template< typename T1 // Type of the left-hand side operand
142  , typename T2 // Type of the right-hand side operand
143  , typename > // Restricting condition
144 struct AddTrait
145 {
146  public:
147  //**********************************************************************************************
149  using Type = decltype( evalAddTrait( std::declval<T1&>(), std::declval<T2&>() ) );
151  //**********************************************************************************************
152 };
153 //*************************************************************************************************
154 
155 
156 //*************************************************************************************************
161 template< typename T >
162 struct AddTrait< T, T, EnableIf_t< IsBuiltin_v<T> > >
163 {
164  public:
165  //**********************************************************************************************
166  using Type = Decay_t<T>;
167  //**********************************************************************************************
168 };
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
178 template< typename T1, typename T2 >
179 struct AddTrait< complex<T1>, T2, EnableIf_t< IsBuiltin_v<T2> > >
180 {
181  public:
182  //**********************************************************************************************
183  using Type = CommonType_t< complex<T1> , T2 >;
184  //**********************************************************************************************
185 };
187 //*************************************************************************************************
188 
189 
190 //*************************************************************************************************
195 template< typename T1, typename T2 >
196 struct AddTrait< T1, complex<T2>, EnableIf_t< IsBuiltin_v<T1> > >
197 {
198  public:
199  //**********************************************************************************************
200  using Type = CommonType_t< T1, complex<T2> >;
201  //**********************************************************************************************
202 };
204 //*************************************************************************************************
205 
206 
207 //*************************************************************************************************
212 template< typename T1, typename T2 >
213 struct AddTrait< complex<T1>, complex<T2> >
214 {
215  public:
216  //**********************************************************************************************
217  using Type = CommonType_t< complex<T1>, complex<T2> >;
218  //**********************************************************************************************
219 };
221 //*************************************************************************************************
222 
223 
224 //*************************************************************************************************
237 template< typename T1, typename T2 >
239 //*************************************************************************************************
240 
241 
242 //*************************************************************************************************
247 template< typename T1 // Type of the left-hand side operand
248  , typename T2 // Type of the right-hand side operand
249  , typename > // Restricting condition
250 struct AddTraitEval1
251 {
252  public:
253  //**********************************************************************************************
254  using Type = typename AddTraitEval2<T1,T2>::Type;
255  //**********************************************************************************************
256 };
258 //*************************************************************************************************
259 
260 
261 //*************************************************************************************************
266 template< typename T1 // Type of the left-hand side operand
267  , typename T2 // Type of the right-hand side operand
268  , typename > // Restricting condition
269 struct AddTraitEval2
270 {
271  private:
272  //**********************************************************************************************
273  struct AddType { using Type = decltype( std::declval<T1>() + std::declval<T2>() ); };
274  struct Failure { using Type = INVALID_TYPE; };
275  //**********************************************************************************************
276 
277  public:
278  //**********************************************************************************************
279  using Type = typename If_t< HasAdd_v<T1,T2>, AddType, Failure >::Type;
280  //**********************************************************************************************
281 };
283 //*************************************************************************************************
284 
285 } // namespace blaze
286 
287 #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 HasAdd 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.
typename AddTrait< T1, T2 >::Type AddTrait_t
Auxiliary alias declaration for the AddTrait class template.The AddTrait_t alias declaration provides...
Definition: AddTrait.h:238
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.
Header file for the CommonType type trait.
Base template for the AddTrait class.
Definition: AddTrait.h:144
Utility type for generic codes.
Header file for the IsBuiltin type trait.
Header file for the complex data type.