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

3
4
#include <type_traits>

5
6
7
8
9
10
11
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>

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

  } // end namespace tag

20
21
  /// Category of type T, e.g. scalar, vector matrix, specified by a tag
  template <class T, class = void>
22
23
24
25
  struct ValueCategory;

  template <class T>
  using ValueCategory_t = typename ValueCategory<T>::type;
26
27
28
29
30
31
32
  
  template <class T>
  struct ValueCategory<T, std::enable_if_t< std::is_arithmetic<T>::value >>
  {
    using type = tag::scalar;
  };
  
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  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;
  };

} // end namespace AMDiS