RFFGen
 All Classes Namespaces Files Functions Typedefs Enumerations Groups
rowsAndCols.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_LINEAR_ALGEBRA_ROWS_AND_COLS_HH
22 #define RFFGEN_LINEAR_ALGEBRA_ROWS_AND_COLS_HH
23 
24 #include <utility>
25 #include "extractRowsAndCols.hh"
26 #include "../Util/staticChecks_nRows_nCols.hh"
27 #include "../Util/staticChecks.hh"
28 
29 namespace RFFGen
30 {
31  namespace LinearAlgebra
32  {
36  namespace Detail
37  {
38  template <class Matrix, bool accessViaRows, bool accessVia_n_rows> struct Rows;
39 
40  template < class Matrix , bool accessVia_n_rows >
41  struct Rows<Matrix,true,accessVia_n_rows>
42  {
43  auto operator()(const Matrix& A) const
44  {
45  return A.rows();
46  }
47  };
48 
49  template < class Matrix >
50  struct Rows<Matrix,false,true>
51  {
52  const auto& operator()(const Matrix& A) const noexcept
53  {
54  return A.n_rows;
55  }
56  };
57 
58  template <class Matrix, bool accessViaCols, bool accessVia_n_cols> struct Cols;
59 
60  template < class Matrix , bool accessVia_n_cols >
61  struct Cols<Matrix,true,accessVia_n_cols>
62  {
63  auto operator()(const Matrix& A) const
64  {
65  return A.cols();
66  }
67  };
68 
69  template < class Matrix >
70  struct Cols<Matrix,false,true>
71  {
72  const auto& operator()(const Matrix& A) const noexcept
73  {
74  return A.n_cols;
75  }
76  };
77  }
85  template < class Matrix ,
86  class = std::enable_if_t<!Checks::isConstantSizeMatrix<Matrix>()> ,
87  class = std::enable_if_t<Checks::isDynamicMatrix<Matrix>()> >
88  auto rows(const Matrix& A) //noexcept(std::declval<Detail::Rows<Matrix,Checks::hasRowsFunction<Matrix>(),Checks::hasMember_n_rows<Matrix>()>()(A) -> decltype(Detail::Rows<Matrix,Checks::hasRowsFunction<Matrix>(),Checks::hasMember_n_rows<Matrix>()>()(std::declval<Matrix>()))
89  {
90  return Detail::Rows<Matrix,Checks::hasRowsFunction<Matrix>(),Checks::hasMember_n_rows<Matrix>()>()(A);
91  }
92 
96  template < class Matrix ,
97  class = std::enable_if_t<Checks::isConstantSizeMatrix<Matrix>()> >
98  constexpr auto rows() //noexcept(std::declval<Detail::Rows<Matrix,Checks::hasRowsFunction<Matrix>(),Checks::hasMember_n_rows<Matrix>()>()(A) -> decltype(Detail::Rows<Matrix,Checks::hasRowsFunction<Matrix>(),Checks::hasMember_n_rows<Matrix>()>()(std::declval<Matrix>()))
99  {
100  return numberOfRows<Matrix>();
101  }
102 
106  template < class Matrix ,
107  class = std::enable_if_t<!Checks::isConstantSizeMatrix<Matrix>()> ,
108  class = std::enable_if_t<Checks::isDynamicMatrix<Matrix>()> >
109  auto cols(const Matrix& A) //noexcept( std::declval< Detail::Cols<Matrix,Checks::hasColsFunction<Matrix>(),Checks::hasMember_n_cols<Matrix>()> >()(A)) //-> decltype(Detail::Cols<Matrix,Checks::hasColsFunction<Matrix>(),Checks::hasMember_n_cols<Matrix>()>()(std::declval<Matrix>()))
110  {
111  return Detail::Cols<Matrix,Checks::hasColsFunction<Matrix>(),Checks::hasMember_n_cols<Matrix>()>()(A);
112  }
113 
117  template < class Matrix ,
118  class = std::enable_if_t<Checks::isConstantSizeMatrix<Matrix>()> >
119  constexpr auto cols() //noexcept(std::declval<Detail::Rows<Matrix,Checks::hasRowsFunction<Matrix>(),Checks::hasMember_n_rows<Matrix>()>()(A) -> decltype(Detail::Rows<Matrix,Checks::hasRowsFunction<Matrix>(),Checks::hasMember_n_rows<Matrix>()>()(std::declval<Matrix>()))
120  {
121  return numberOfColumns<Matrix>();
122  }
123  }
124 }
125 
126 #endif // RFFGEN_LINEAR_ALGEBRA_ROWS_AND_COLS_HH