restrictors.hpp 9.8 KB

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