Blaze  3.6
SubTrait.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_TRAITS_SUBTRAIT_H_
36 #define _BLAZE_MATH_TRAITS_SUBTRAIT_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 SubTrait;
65 template< typename, typename, typename = void > struct SubTraitEval1;
66 template< typename, typename, typename = void > struct SubTraitEval2;
68 //*************************************************************************************************
69 
70 
71 //*************************************************************************************************
73 template< typename T1, typename T2 >
74 auto evalSubTrait( T1&, T2& )
75  -> typename SubTraitEval1<T1,T2>::Type;
76 
77 template< typename T1, typename T2 >
78 auto evalSubTrait( const T1&, const T2& )
79  -> typename SubTrait<T1,T2>::Type;
80 
81 template< typename T1, typename T2 >
82 auto evalSubTrait( const volatile T1&, const T2& )
83  -> typename SubTrait<T1,T2>::Type;
84 
85 template< typename T1, typename T2 >
86 auto evalSubTrait( const T1&, const volatile T2& )
87  -> typename SubTrait<T1,T2>::Type;
88 
89 template< typename T1, typename T2 >
90 auto evalSubTrait( const volatile T1&, const volatile T2& )
91  -> typename SubTrait<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 SubTrait
145 {
146  public:
147  //**********************************************************************************************
149  using Type = decltype( evalSubTrait( std::declval<T1&>(), std::declval<T2&>() ) );
151  //**********************************************************************************************
152 };
153 //*************************************************************************************************
154 
155 
156 //*************************************************************************************************
161 template< typename T >
162 struct SubTrait< T, T, EnableIf_t< IsBuiltin_v<T> > >
163 {
164  public:
165  //**********************************************************************************************
166  using Type = RemoveCVRef_t<T>;
167  //**********************************************************************************************
168 };
170 //*************************************************************************************************
171 
172 
173 //*************************************************************************************************
178 template< typename T1, typename T2 >
179 struct SubTrait< 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 SubTrait< 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 SubTrait< 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 SubTraitEval1
251 {
252  public:
253  //**********************************************************************************************
254  using Type = typename SubTraitEval2<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 SubTraitEval2
270 {
271  private:
272  //**********************************************************************************************
273  struct SubType { 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< HasSub_v<T1,T2>, SubType, Failure >::Type;
280  //**********************************************************************************************
281 };
283 //*************************************************************************************************
284 
285 } // namespace blaze
286 
287 #endif
typename SubTrait< T1, T2 >::Type SubTrait_t
Auxiliary alias declaration for the SubTrait class template.The SubTrait_t alias declaration provides...
Definition: SubTrait.h:238
Header file for the RemoveCVRef type trait.
Header file for the HasSub 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.
Utility type for generic codes.
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.
Base template for the SubTrait class.
Definition: SubTrait.h:144