1 // SPDX-License-Identifier: Apache-2.0 2 // 3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au) 4 // Copyright 2008-2016 National ICT Australia (NICTA) 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 // ------------------------------------------------------------------------ 17 18 19 //! \addtogroup restrictors 20 //! @{ 21 22 23 24 // structures for template based restrictions of input/output arguments 25 // (part of the SFINAE approach) 26 // http://en.wikipedia.org/wiki/SFINAE 27 28 29 template<typename T> struct arma_scalar_only { }; 30 31 template<> struct arma_scalar_only< u8 > { typedef u8 result; }; 32 template<> struct arma_scalar_only< s8 > { typedef s8 result; }; 33 template<> struct arma_scalar_only< u16 > { typedef u16 result; }; 34 template<> struct arma_scalar_only< s16 > { typedef s16 result; }; 35 template<> struct arma_scalar_only< u32 > { typedef u32 result; }; 36 template<> struct arma_scalar_only< s32 > { typedef s32 result; }; 37 template<> struct arma_scalar_only< u64 > { typedef u64 result; }; 38 template<> struct arma_scalar_only< s64 > { typedef s64 result; }; 39 template<> struct arma_scalar_only< ulng_t > { typedef ulng_t result; }; 40 template<> struct arma_scalar_only< slng_t > { typedef slng_t result; }; 41 template<> struct arma_scalar_only< float > { typedef float result; }; 42 template<> struct arma_scalar_only< double > { typedef double result; }; 43 template<> struct arma_scalar_only< cx_float > { typedef cx_float result; }; 44 template<> struct arma_scalar_only< cx_double > { typedef cx_double result; }; 45 46 47 48 template<typename T> struct arma_integral_only { }; 49 50 template<> struct arma_integral_only< u8 > { typedef u8 result; }; 51 template<> struct arma_integral_only< s8 > { typedef s8 result; }; 52 template<> struct arma_integral_only< u16 > { typedef u16 result; }; 53 template<> struct arma_integral_only< s16 > { typedef s16 result; }; 54 template<> struct arma_integral_only< u32 > { typedef u32 result; }; 55 template<> struct arma_integral_only< s32 > { typedef s32 result; }; 56 template<> struct arma_integral_only< u64 > { typedef u64 result; }; 57 template<> struct arma_integral_only< s64 > { typedef s64 result; }; 58 template<> struct arma_integral_only< ulng_t > { typedef ulng_t result; }; 59 template<> struct arma_integral_only< slng_t > { typedef slng_t result; }; 60 61 62 63 template<typename T> struct arma_unsigned_integral_only { }; 64 65 template<> struct arma_unsigned_integral_only< u8 > { typedef u8 result; }; 66 template<> struct arma_unsigned_integral_only< u16 > { typedef u16 result; }; 67 template<> struct arma_unsigned_integral_only< u32 > { typedef u32 result; }; 68 template<> struct arma_unsigned_integral_only< u64 > { typedef u64 result; }; 69 template<> struct arma_unsigned_integral_only< ulng_t > { typedef ulng_t result; }; 70 71 72 73 template<typename T> struct arma_signed_integral_only { }; 74 75 template<> struct arma_signed_integral_only< s8 > { typedef s8 result; }; 76 template<> struct arma_signed_integral_only< s16 > { typedef s16 result; }; 77 template<> struct arma_signed_integral_only< s32 > { typedef s32 result; }; 78 template<> struct arma_signed_integral_only< s64 > { typedef s64 result; }; 79 template<> struct arma_signed_integral_only< slng_t > { typedef slng_t result; }; 80 81 82 83 template<typename T> struct arma_signed_only { }; 84 85 template<> struct arma_signed_only< s8 > { typedef s8 result; }; 86 template<> struct arma_signed_only< s16 > { typedef s16 result; }; 87 template<> struct arma_signed_only< s32 > { typedef s32 result; }; 88 template<> struct arma_signed_only< s64 > { typedef s64 result; }; 89 template<> struct arma_signed_only< slng_t > { typedef slng_t result; }; 90 template<> struct arma_signed_only< float > { typedef float result; }; 91 template<> struct arma_signed_only< double > { typedef double result; }; 92 template<> struct arma_signed_only< cx_float > { typedef cx_float result; }; 93 template<> struct arma_signed_only< cx_double > { typedef cx_double result; }; 94 95 96 97 template<typename T> struct arma_real_only { }; 98 99 template<> struct arma_real_only< float > { typedef float result; }; 100 template<> struct arma_real_only< double > { typedef double result; }; 101 102 103 template<typename T> struct arma_real_or_cx_only { }; 104 105 template<> struct arma_real_or_cx_only< float > { typedef float result; }; 106 template<> struct arma_real_or_cx_only< double > { typedef double result; }; 107 template<> struct arma_real_or_cx_only< cx_float > { typedef cx_float result; }; 108 template<> struct arma_real_or_cx_only< cx_double > { typedef cx_double result; }; 109 110 111 112 template<typename T> struct arma_cx_only { }; 113 114 template<> struct arma_cx_only< cx_float > { typedef cx_float result; }; 115 template<> struct arma_cx_only< cx_double > { typedef cx_double result; }; 116 117 118 119 template<typename T> struct arma_not_cx { typedef T result; }; 120 template<typename T> struct arma_not_cx< std::complex<T> > { }; 121 122 123 124 template<typename T> struct arma_blas_type_only { }; 125 126 template<> struct arma_blas_type_only< float > { typedef float result; }; 127 template<> struct arma_blas_type_only< double > { typedef double result; }; 128 template<> struct arma_blas_type_only< cx_float > { typedef cx_float result; }; 129 template<> struct arma_blas_type_only< cx_double > { typedef cx_double result; }; 130 131 132 133 template<typename T> struct arma_not_blas_type { typedef T result; }; 134 135 template<> struct arma_not_blas_type< float > { }; 136 template<> struct arma_not_blas_type< double > { }; 137 template<> struct arma_not_blas_type< cx_float > { }; 138 template<> struct arma_not_blas_type< cx_double > { }; 139 140 141 142 template<typename T> struct arma_op_rel_only { }; 143 144 template<> struct arma_op_rel_only< op_rel_lt_pre > { typedef int result; }; 145 template<> struct arma_op_rel_only< op_rel_lt_post > { typedef int result; }; 146 template<> struct arma_op_rel_only< op_rel_gt_pre > { typedef int result; }; 147 template<> struct arma_op_rel_only< op_rel_gt_post > { typedef int result; }; 148 template<> struct arma_op_rel_only< op_rel_lteq_pre > { typedef int result; }; 149 template<> struct arma_op_rel_only< op_rel_lteq_post > { typedef int result; }; 150 template<> struct arma_op_rel_only< op_rel_gteq_pre > { typedef int result; }; 151 template<> struct arma_op_rel_only< op_rel_gteq_post > { typedef int result; }; 152 template<> struct arma_op_rel_only< op_rel_eq > { typedef int result; }; 153 template<> struct arma_op_rel_only< op_rel_noteq > { typedef int result; }; 154 155 156 157 template<typename T> struct arma_not_op_rel { typedef int result; }; 158 159 template<> struct arma_not_op_rel< op_rel_lt_pre > { }; 160 template<> struct arma_not_op_rel< op_rel_lt_post > { }; 161 template<> struct arma_not_op_rel< op_rel_gt_pre > { }; 162 template<> struct arma_not_op_rel< op_rel_gt_post > { }; 163 template<> struct arma_not_op_rel< op_rel_lteq_pre > { }; 164 template<> struct arma_not_op_rel< op_rel_lteq_post > { }; 165 template<> struct arma_not_op_rel< op_rel_gteq_pre > { }; 166 template<> struct arma_not_op_rel< op_rel_gteq_post > { }; 167 template<> struct arma_not_op_rel< op_rel_eq > { }; 168 template<> struct arma_not_op_rel< op_rel_noteq > { }; 169 170 171 172 template<typename T> struct arma_glue_rel_only { }; 173 174 template<> struct arma_glue_rel_only< glue_rel_lt > { typedef int result; }; 175 template<> struct arma_glue_rel_only< glue_rel_gt > { typedef int result; }; 176 template<> struct arma_glue_rel_only< glue_rel_lteq > { typedef int result; }; 177 template<> struct arma_glue_rel_only< glue_rel_gteq > { typedef int result; }; 178 template<> struct arma_glue_rel_only< glue_rel_eq > { typedef int result; }; 179 template<> struct arma_glue_rel_only< glue_rel_noteq > { typedef int result; }; 180 template<> struct arma_glue_rel_only< glue_rel_and > { typedef int result; }; 181 template<> struct arma_glue_rel_only< glue_rel_or > { typedef int result; }; 182 183 184 185 template<typename T> struct arma_Mat_Col_Row_only { }; 186 187 template<typename eT> struct arma_Mat_Col_Row_only< Mat<eT> > { typedef Mat<eT> result; }; 188 template<typename eT> struct arma_Mat_Col_Row_only< Col<eT> > { typedef Col<eT> result; }; 189 template<typename eT> struct arma_Mat_Col_Row_only< Row<eT> > { typedef Row<eT> result; }; 190 191 192 193 template<typename T> struct arma_Cube_only { }; 194 template<typename eT> struct arma_Cube_only< Cube<eT> > { typedef Cube<eT> result; }; 195 196 197 template<typename T> struct arma_SpMat_SpCol_SpRow_only { }; 198 199 template<typename eT> struct arma_SpMat_SpCol_SpRow_only< SpMat<eT> > { typedef SpMat<eT> result; }; 200 template<typename eT> struct arma_SpMat_SpCol_SpRow_only< SpCol<eT> > { typedef SpCol<eT> result; }; 201 template<typename eT> struct arma_SpMat_SpCol_SpRow_only< SpRow<eT> > { typedef SpRow<eT> result; }; 202 203 204 205 template<bool> struct enable_if { }; 206 template<> struct enable_if<true> { typedef int result; }; 207 208 209 template<bool, typename result_type > struct enable_if2 { }; 210 template< typename result_type > struct enable_if2<true, result_type> { typedef result_type result; }; 211 212 213 214 //! @} 215