Blaze  3.6
DivTrait.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_TRAITS_DIVTRAIT_H_
36 #define _BLAZE_MATH_TRAITS_DIVTRAIT_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 DivTrait;
65 template< typename, typename, typename = void > struct DivTraitEval1;
66 template< typename, typename, typename = void > struct DivTraitEval2;
68 //*************************************************************************************************
69 
70 
71 //*************************************************************************************************
73 template< typename T1, typename T2 >
74 auto evalDivTrait( T1&, T2& )
75  -> typename DivTraitEval1<T1,T2>::Type;
76 
77 template< typename T1, typename T2 >
78 auto evalDivTrait( const T1&, const T2& )
79  -> typename DivTrait<T1,T2>::Type;
80 
81 template< typename T1, typename T2 >
82 auto evalDivTrait( const volatile T1&, const T2& )
83  -> typename DivTrait<T1,T2>::Type;
84 
85 template< typename T1, typename T2 >
86 auto evalDivTrait( const T1&, const volatile T2& )
87  -> typename DivTrait<T1,T2>::Type;
88 
89 template< typename T1, typename T2 >
90 auto evalDivTrait( const volatile T1&, const volatile T2& )
91  -> typename DivTrait<T1,T2>::Type;
93 //*************************************************************************************************
94 
95 
96 //*************************************************************************************************
142 template< typename T1 // Type of the left-hand side operand
143  , typename T2 // Type of the right-hand side operand
144  , typename > // Restricting condition
145 struct DivTrait
146 {
147  public:
148  //**********************************************************************************************
150  using Type = decltype( evalDivTrait( std::declval<T1&>(), std::declval<T2&>() ) );
152  //**********************************************************************************************
153 };
154 //*************************************************************************************************
155 
156 
157 //*************************************************************************************************
162 template< typename T >
163 struct DivTrait< T, T, EnableIf_t< IsBuiltin_v<T> > >
164 {
165  public:
166  //**********************************************************************************************
167  using Type = RemoveCVRef_t<T>;
168  //**********************************************************************************************
169 };
171 //*************************************************************************************************
172 
173 
174 //*************************************************************************************************
179 template< typename T1, typename T2 >
180 struct DivTrait< complex<T1>, T2, EnableIf_t< IsBuiltin_v<T2> > >
181 {
182  public:
183  //**********************************************************************************************
184  using Type = CommonType_t< complex<T1> , T2 >;
185  //**********************************************************************************************
186 };
188 //*************************************************************************************************
189 
190 
191 //*************************************************************************************************
196 template< typename T1, typename T2 >
197 struct DivTrait< T1, complex<T2>, EnableIf_t< IsBuiltin_v<T1> > >
198 {
199  public:
200  //**********************************************************************************************
201  using Type = CommonType_t< T1, complex<T2> >;
202  //**********************************************************************************************
203 };
205 //*************************************************************************************************
206 
207 
208 //*************************************************************************************************
213 template< typename T1, typename T2 >
214 struct DivTrait< complex<T1>, complex<T2> >
215 {
216  public:
217  //**********************************************************************************************
218  using Type = CommonType_t< complex<T1>, complex<T2> >;
219  //**********************************************************************************************
220 };
222 //*************************************************************************************************
223 
224 
225 //*************************************************************************************************
238 template< typename T1, typename T2 >
240 //*************************************************************************************************
241 
242 
243 //*************************************************************************************************
248 template< typename T1 // Type of the left-hand side operand
249  , typename T2 // Type of the right-hand side operand
250  , typename > // Restricting condition
251 struct DivTraitEval1
252 {
253  public:
254  //**********************************************************************************************
255  using Type = typename DivTraitEval2<T1,T2>::Type;
256  //**********************************************************************************************
257 };
259 //*************************************************************************************************
260 
261 
262 //*************************************************************************************************
267 template< typename T1 // Type of the left-hand side operand
268  , typename T2 // Type of the right-hand side operand
269  , typename > // Restricting condition
270 struct DivTraitEval2
271 {
272  private:
273  //**********************************************************************************************
274  struct DivType { using Type = decltype( std::declval<T1>() / std::declval<T2>() ); };
275  struct Failure { using Type = INVALID_TYPE; };
276  //**********************************************************************************************
277 
278  public:
279  //**********************************************************************************************
280  using Type = typename If_t< HasDiv_v<T1,T2>, DivType, Failure >::Type;
281  //**********************************************************************************************
282 };
284 //*************************************************************************************************
285 
286 } // namespace blaze
287 
288 #endif
typename DivTrait< T1, T2 >::Type DivTrait_t
Auxiliary alias declaration for the DivTrait class template.The DivTrait_t alias declaration provides...
Definition: DivTrait.h:239
Header file for the RemoveCVRef 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.
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.
Header file for the HasDiv type trait.
Utility type for generic codes.
Base template for the DivTrait class.
Definition: DivTrait.h:145
typename RemoveCVRef< T >::Type RemoveCVRef_t
Auxiliary alias declaration for the RemoveCVRef type trait.The RemoveCVRef_t alias declaration provid...
Definition: RemoveCVRef.h:99
Header file for the IsBuiltin type trait.
Header file for the complex data type.