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

3
#include <functional>
4
5
#include <type_traits>

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

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

  } // end namespace tag

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

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

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

38
39
40
41
42
43
  template <class T>
  struct ValueCategory<std::reference_wrapper<T>, std::enable_if_t< std::is_arithmetic<T>::value >>
  {
    using type = tag::scalar;
  };

44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  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;
  };
67
68
69
70
71
72
73
74
75
76
77
78
79
80

  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

81
} // end namespace AMDiS