Utility.hpp 1.32 KB
Newer Older
1
2
3
4
5
6
7
8
#pragma once

#include <memory>
#include <type_traits>
#include <vector>

namespace AMDiS
{
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  namespace Impl
  {
    template <class T>
    struct UnderlyingType
    {
      using type = T;
    };

    template <class T>
    struct UnderlyingType<std::reference_wrapper<T>>
    {
      using type = T;
    };
  }

  template <class T>
  using Underlying_t = typename Impl::UnderlyingType<T>::type;

27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  namespace Impl
  {
    template <class T0, class... Ts>
    struct CommonType
    {
      using type = std::common_type_t<T0, typename CommonType<Ts...>::type>;
    };

    template <class T0>
    struct CommonType<T0>
    {
      using type = T0;
    };
  }

  template <class... T>
  using CommonType_t = typename Impl::CommonType<T...>::type;


47
48
  // ---------------------------------------------------------------------------

49

50
51
52
53
54
  /// A variadic type list
  template <class... Ts>
  struct Types {};

  template <class... Ts>
Praetorius, Simon's avatar
Praetorius, Simon committed
55
  using Types_t = Types<std::decay_t<Ts>...>;
56

57

58
59
60
61
  /// Alias that indicates ownership of resources
  template <class T>
  using owner = T;

62

63
64
  // ---------------------------------------------------------------------------

65

66
  /// generalization of get<tuple>, get<array> for vectors
67
  template <std::size_t I, class T, class A>
68
69
70
71
72
73
  T const& get(std::vector<T,A> const& vec)
  {
      return vec[I];
  }

} // end namespace AMDiS