ValueCategory.hpp 1.58 KB
Newer Older
1
2
#pragma once

3
4
#include <type_traits>

5
6
7
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>

8
namespace AMDiS
9
{
10
  namespace tag
11
  {
12
    // some tags representing traits classes or categories
13
14
15
16
    struct none {};
    struct scalar {};
    struct vector {};
    struct matrix {};
17
    struct unknown {};
18
19
20

  } // end namespace tag

21
22
  /// Category of type T, e.g. scalar, vector matrix, specified by a tag
  template <class T, class = void>
23
24
25
26
  struct ValueCategory
  {
    using type = tag::unknown;
  };
27
28
29

  template <class T>
  using ValueCategory_t = typename ValueCategory<T>::type;
30

31
32
33
34
35
  template <class T>
  struct ValueCategory<T, std::enable_if_t< std::is_arithmetic<T>::value >>
  {
    using type = tag::scalar;
  };
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  template <class K, int SIZE>
  struct ValueCategory< Dune::FieldVector<K, SIZE> >
  {
    using type = tag::vector;
  };

  template <class K>
  struct ValueCategory< Dune::FieldVector<K, 1> >
  {
    using type = tag::scalar;
  };

  template <class K, int ROWS, int COLS>
  struct ValueCategory< Dune::FieldMatrix<K, ROWS, COLS> >
  {
    using type = tag::matrix;
  };

  template <class K>
  struct ValueCategory< Dune::FieldMatrix<K, 1, 1> >
  {
    using type = tag::scalar;
  };
60
61
62
63
64
65
66
67
68
69
70
71
72
73

  namespace Category
  {
    template <class T>
    constexpr bool Scalar = std::is_same<ValueCategory_t<T>, tag::scalar>::value;

    template <class T>
    constexpr bool Vector = std::is_same<ValueCategory_t<T>, tag::vector>::value;

    template <class T>
    constexpr bool Matrix = std::is_same<ValueCategory_t<T>, tag::matrix>::value;

  } // end namespace Category

74
} // end namespace AMDiS