DUNE-FEM (unstable)

matrixconcepts.hh
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
13#include <dune/common/std/type_traits.hh>
14
15
16
17namespace Dune {
18
19 template<class, int, int>
20 class FieldMatrix;
21
22 template<class>
23 class DynamicMatrix;
24
25}
26
27namespace 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
70 template<class T>
71 class IsDenseMatrix : public std::false_type {};
72
73 template<class K, int ROWS, int COLS>
74 class IsDenseMatrix<Dune::FieldMatrix<K, ROWS, COLS>> : public std::true_type {};
75
76 template<class K>
77 class IsDenseMatrix<Dune::DynamicMatrix<K>> : public std::true_type {};
78
79 // Check if T is a dense matrix. This is implemented by specialization.
80 template<class T>
81 constexpr bool IsDenseMatrix_v = Impl::IsDenseMatrix<T>::value;
82
83
84
85} // namespace Dune::Impl
86
87
88
89#endif // DUNE_COMMON_MATRIXCONCEPTS_HH
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:145
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)