1 //================================================================================================= 2 /*! 3 // \file blaze/math/typetraits/HasMult.h 4 // \brief Header file for the HasMult type trait 5 // 6 // Copyright (C) 2012-2020 Klaus Iglberger - All Rights Reserved 7 // 8 // This file is part of the Blaze library. You can redistribute it and/or modify it under 9 // the terms of the New (Revised) BSD License. Redistribution and use in source and binary 10 // forms, with or without modification, are permitted provided that the following conditions 11 // are met: 12 // 13 // 1. Redistributions of source code must retain the above copyright notice, this list of 14 // conditions and the following disclaimer. 15 // 2. Redistributions in binary form must reproduce the above copyright notice, this list 16 // of conditions and the following disclaimer in the documentation and/or other materials 17 // provided with the distribution. 18 // 3. Neither the names of the Blaze development group nor the names of its contributors 19 // may be used to endorse or promote products derived from this software without specific 20 // prior written permission. 21 // 22 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 23 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25 // SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 27 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 28 // BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 31 // DAMAGE. 32 */ 33 //================================================================================================= 34 35 #ifndef _BLAZE_MATH_TYPETRAITS_HASMULT_H_ 36 #define _BLAZE_MATH_TYPETRAITS_HASMULT_H_ 37 38 39 //************************************************************************************************* 40 // Includes 41 //************************************************************************************************* 42 43 #include <utility> 44 #include <blaze/math/typetraits/IsMatrix.h> 45 #include <blaze/math/typetraits/IsVector.h> 46 #include <blaze/util/EnableIf.h> 47 #include <blaze/util/IntegralConstant.h> 48 #include <blaze/util/typetraits/Void.h> 49 50 51 namespace blaze { 52 53 //================================================================================================= 54 // 55 // CLASS DEFINITION 56 // 57 //================================================================================================= 58 59 //************************************************************************************************* 60 /*! \cond BLAZE_INTERNAL */ 61 /*!\brief Auxiliary helper struct for the IsMultHelper type trait. 62 // \ingroup math_type_traits 63 */ 64 template< typename T1, typename T2, typename = void > 65 struct HasMultHelper 66 : public FalseType 67 {}; 68 /*! \endcond */ 69 //************************************************************************************************* 70 71 72 //************************************************************************************************* 73 /*! \cond BLAZE_INTERNAL */ 74 /*!\brief Specialization of the HasMultHelper type trait for types providing a multiplication 75 // operator. 76 // \ingroup math_type_traits 77 */ 78 template< typename T1, typename T2 > 79 struct HasMultHelper< T1, T2, Void_t< decltype( std::declval<T1>() * std::declval<T2>() ) > > 80 : public TrueType 81 {}; 82 /*! \endcond */ 83 //************************************************************************************************* 84 85 86 //************************************************************************************************* 87 /*!\brief Availability of a multiplication operator for the given data types. 88 // \ingroup math_type_traits 89 // 90 // This type trait provides the information whether a multiplication operator (i.e. operator*) 91 // exists for the two given data types \a T1 and \a T2 (taking the cv-qualifiers into account). 92 // In case the operator is available, the \a value member constant is set to \a true, the nested 93 // type definition \a Type is \a TrueType, and the class derives from \a TrueType. Otherwise 94 // \a value is set to \a false, \a Type is \a FalseType, and the class derives from \a FalseType. 95 96 \code 97 blaze::HasMult< int, int >::value // Evaluates to 1 98 blaze::HasMult< complex<float>, complex<float> >::Type // Results in TrueType 99 blaze::HasMult< DynamicVector<int>, DynamicVector<int> > // Is derived from TrueType 100 blaze::HasMult< int, complex<float> >::value // Evaluates to 0 101 blaze::HasMult< complex<int>, complex<float> >::Type // Results in FalseType 102 blaze::HasMult< DynamicMatrix<int>, DynamicVector<int> > // Is derived from FalseType 103 \endcode 104 */ 105 template< typename T1, typename T2, typename = void > 106 struct HasMult 107 : public HasMultHelper<T1,T2> 108 {}; 109 //************************************************************************************************* 110 111 112 //************************************************************************************************* 113 /*! \cond BLAZE_INTERNAL */ 114 /*!\brief Specialization of the HasMult type trait for vector multiplications. 115 // \ingroup math_type_traits 116 */ 117 template< typename T1, typename T2 > 118 struct HasMult< T1, T2, EnableIf_t< IsVector_v<T1> && IsVector_v<T2> > > 119 : public HasMult< typename T1::ElementType, typename T2::ElementType > 120 {}; 121 /*! \endcond */ 122 //************************************************************************************************* 123 124 125 //************************************************************************************************* 126 /*! \cond BLAZE_INTERNAL */ 127 /*!\brief Specialization of the HasMult type trait for matrix/vector multiplications. 128 // \ingroup math_type_traits 129 */ 130 template< typename T1, typename T2 > 131 struct HasMult< T1, T2, EnableIf_t< IsMatrix_v<T1> && IsVector_v<T2> > > 132 : public HasMult< typename T1::ElementType, typename T2::ElementType > 133 {}; 134 /*! \endcond */ 135 //************************************************************************************************* 136 137 138 //************************************************************************************************* 139 /*! \cond BLAZE_INTERNAL */ 140 /*!\brief Specialization of the HasMult type trait for vector/matrix multiplications. 141 // \ingroup math_type_traits 142 */ 143 template< typename T1, typename T2 > 144 struct HasMult< T1, T2, EnableIf_t< IsVector_v<T1> && IsMatrix_v<T2> > > 145 : public HasMult< typename T1::ElementType, typename T2::ElementType > 146 {}; 147 /*! \endcond */ 148 //************************************************************************************************* 149 150 151 //************************************************************************************************* 152 /*! \cond BLAZE_INTERNAL */ 153 /*!\brief Specialization of the HasMult type trait for matrix/matrix multiplications. 154 // \ingroup math_type_traits 155 */ 156 template< typename T1, typename T2 > 157 struct HasMult< T1, T2, EnableIf_t< IsMatrix_v<T1> && IsMatrix_v<T2> > > 158 : public HasMult< typename T1::ElementType, typename T2::ElementType > 159 {}; 160 /*! \endcond */ 161 //************************************************************************************************* 162 163 164 //************************************************************************************************* 165 /*!\brief Auxiliary variable template for the HasMult type trait. 166 // \ingroup math_type_traits 167 // 168 // The HasMult_v variable template provides a convenient shortcut to access the nested \a value 169 // of the HasMult class template. For instance, given the types \a T1 and \a T2 the following 170 // two statements are identical: 171 172 \code 173 constexpr bool value1 = blaze::HasMult<T1,T2>::value; 174 constexpr bool value2 = blaze::HasMult_v<T1,T2>; 175 \endcode 176 */ 177 template< typename T1, typename T2 > 178 constexpr bool HasMult_v = HasMult<T1,T2>::value; 179 //************************************************************************************************* 180 181 } // namespace blaze 182 183 #endif 184