dune-common  2.11
matrixconcepts.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_COMMON_MATRIXCONCEPTS_HH
6 #define DUNE_COMMON_MATRIXCONCEPTS_HH
7 
8 
9 
10 #include <utility>
11 #include <type_traits>
12 
14 
15 
16 
17 namespace Dune {
18 
19  template<class, int, int>
20  class FieldMatrix;
21 
22  template<class>
23  class DynamicMatrix;
24 
25 }
26 
27 namespace Dune::Impl {
28 
29 
30  // Some traits for checking matrix concepts. Currently these are
31  // all technical internal helpers that just serve different headers
32  // to do internal checks and are thus collected here.
33 
34  template<class T>
35  using IsMatrixHelper = std::void_t<decltype(std::declval<T>().N(), std::declval<T>().M())>;
36 
37  template<class T>
38  struct IsMatrix : public Dune::Std::is_detected<IsMatrixHelper, T> {};
39 
40  // Check if T is a matrix by checking for member functions N() and M().
41  template<class T>
42  constexpr bool IsMatrix_v = Impl::IsMatrix<T>::value;
43 
44 
45 
46  template<class T>
47  using IsStaticSizeMatrixHelper = std::void_t<decltype(T::rows, T::cols)>;
48 
49  template<class T>
50  struct IsStaticSizeMatrix : public Dune::Std::is_detected<IsStaticSizeMatrixHelper, T> {};
51 
52  // Check if T is a statically sized matrix by checking for static members rows and cols.
53  template<class T>
54  constexpr bool IsStaticSizeMatrix_v = Impl::IsStaticSizeMatrix<T>::value;
55 
56 
57 
58  template<class T>
59  class IsFieldMatrix : public std::false_type {};
60 
61  template< class K, int ROWS, int COLS>
62  class IsFieldMatrix<Dune::FieldMatrix<K, ROWS, COLS>> : public std::true_type {};
63 
64  // Check if T is an instance of FieldMatrix
65  template<class T>
66  constexpr bool IsFieldMatrix_v = Impl::IsFieldMatrix<T>::value;
67 
68 
69 
82  template<class T>
83  class IsDenseMatrix : public std::false_type {};
84 
85  template<class T>
86  class IsDenseMatrix<const T> : public IsDenseMatrix<T> {};
87 
88  template<class K, int ROWS, int COLS>
89  class IsDenseMatrix<Dune::FieldMatrix<K, ROWS, COLS>> : public std::true_type {};
90 
91  template<class K>
92  class IsDenseMatrix<Dune::DynamicMatrix<K>> : public std::true_type {};
93 
94  // Check if T is a dense matrix. This is implemented by specialization.
95  template<class T>
96  constexpr bool IsDenseMatrix_v = Impl::IsDenseMatrix<T>::value;
97 
98 
99 
100 } // namespace Dune::Impl
101 
102 
103 
104 #endif // DUNE_COMMON_MATRIXCONCEPTS_HH
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:141
Definition: bigunsignedint.hh:37
Dune namespace
Definition: alignedallocator.hh:12