RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
staticChecks_nRows_nCols.hh
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the C++-library RFFGen. */
4 /* Copyright 2015 Lars Lubkoll */
5 /* */
6 /* RFFGen is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* RFFGen is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with RFFGen. If not, see <http://www.gnu.org/licenses/>. */
18 /* */
19 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 
21 #ifndef RFFGEN_UTIL_STATIC_CHECKS_NROWS_NCOLS_HH
22 #define RFFGEN_UTIL_STATIC_CHECKS_NROWS_NCOLS_HH
23 
24 #include <utility>
25 
26 namespace RFFGen
27 {
28  namespace Checks
29  {
33  // check functions for accessing the number of rows and columns in a dynamic matrix
34  template < class Matrix >
35  using TryCallOfRowsForMatrix = decltype(std::declval<Matrix>().rows());
36 
37  template < class Matrix >
38  using TryAccessTo_n_rowsForMatrix = decltype(std::declval<Matrix>().n_rows);
39 
40  template < class Matrix >
41  using TryCallOfColsForMatrix = decltype(std::declval<Matrix>().cols());
42 
43  template < class Matrix >
44  using TryAccessTo_n_colsForMatrix = decltype(std::declval<Matrix>().n_cols);
45 
46  template < class Matrix , class = void > struct CallOfRowsForMatrix : std::false_type {};
47  template < class Matrix > struct CallOfRowsForMatrix< Matrix , void_t< TryCallOfRowsForMatrix< Matrix > > > : std::true_type {};
48 
49  template < class Matrix , class = void > struct CallOfColsForMatrix : std::false_type {};
50  template < class Matrix > struct CallOfColsForMatrix< Matrix , void_t< TryCallOfColsForMatrix< Matrix > > > : std::true_type {};
51 
52  template < class Matrix , class = void > struct AccessTo_n_rows : std::false_type {};
53  template < class Matrix > struct AccessTo_n_rows< Matrix , void_t < TryAccessTo_n_rowsForMatrix<Matrix> > > : std::true_type {};
54 
55  template < class Matrix , class = void > struct AccessTo_n_cols : std::false_type {};
56  template < class Matrix > struct AccessTo_n_cols< Matrix , void_t < TryAccessTo_n_colsForMatrix<Matrix> > > : std::true_type {};
65  template < class Matrix >
66  constexpr bool hasRowsFunction()
67  {
68  return CallOfRowsForMatrix<Matrix>::value;
69  }
70 
75  template < class Matrix >
76  constexpr bool hasMember_n_rows()
77  {
78  return AccessTo_n_rows<Matrix>::value;
79  }
80 
85  template < class Matrix >
86  constexpr bool hasColsFunction()
87  {
88  return CallOfColsForMatrix<Matrix>::value;
89  }
90 
95  template < class Matrix >
96  constexpr bool hasMember_n_cols()
97  {
98  return AccessTo_n_cols<Matrix>::value;
99  }
100 
105  template < class Arg >
106  constexpr bool isDynamicMatrix()
107  {
108  return ( hasRowsFunction<Arg>() && hasColsFunction<Arg>() ) ||
109  ( hasMember_n_rows<Arg>() && hasMember_n_cols<Arg>() );
110  }
111 
116  template < class Arg >
117  constexpr bool isDynamicVector()
118  {
119  return hasRowsFunction<Arg>() || hasMember_n_rows<Arg>();
120  }
121  }
122 }
123 
124 #endif // RFFGEN_UTIL_STATIC_CHECKS_NROWS_NCOLS_HH
typename Detail::voider< Types...>::type void_t
Most fascinating type ever. Is always void.
Definition: voider.hh:40