AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
TypeTraits.hpp
1 #pragma once
2 
3 #include <memory>
4 #include <type_traits>
5 
6 namespace AMDiS
7 {
9 
16  template <class T>
17  struct remove_cvref
18  {
19  using type = std::remove_cv_t<std::remove_reference_t<T>>;
20  };
21 
23  template <class T>
24  using remove_cvref_t = typename remove_cvref<T>::type;
25 
26  namespace Impl
27  {
28  template <class T>
29  struct UnderlyingType
30  {
31  using type = T;
32  };
33 
34  template <class T>
35  struct UnderlyingType<const T>
36  {
37  using type = typename UnderlyingType<T>::type;
38  };
39 
40  template <class T>
41  struct UnderlyingType<T&>
42  {
43  using type = typename UnderlyingType<T>::type;
44  };
45 
46  template <class T>
47  struct UnderlyingType<T*>
48  {
49  using type = typename UnderlyingType<T>::type;
50  };
51 
52  template <class T>
53  struct UnderlyingType<std::reference_wrapper<T>>
54  {
55  using type = typename UnderlyingType<T>::type;
56  };
57 
58  template <class T>
59  struct UnderlyingType<std::shared_ptr<T>>
60  {
61  using type = typename UnderlyingType<T>::type;
62  };
63 
64  template <class T>
65  struct UnderlyingType<std::unique_ptr<T>>
66  {
67  using type = typename UnderlyingType<T>::type;
68  };
69  }
70 
71  template <class T>
72  using Underlying_t = typename Impl::UnderlyingType<T>::type;
73 
74 
76  #define FWD(...) static_cast<decltype(__VA_ARGS__)>(__VA_ARGS__)
77 
79  #define TYPEOF(...) AMDiS::remove_cvref_t<decltype(__VA_ARGS__)>
80 
82  #define VALUE(...) TYPEOF(__VA_ARGS__)::value
83 
84  // ---------------------------------------------------------------------------
85 
87  template <class... Ts>
88  struct Types {};
89 
90  template <class... Ts>
92 
93 
95  template <class T>
96  using owner = T;
97 
99  struct NoOp
100  {
101  template <class... T>
102  constexpr void operator()(T&&...) const { /* no nothing */ }
103  };
104 
106  template <class Obj>
107  auto makeUniquePtr(Obj&& obj)
108  {
109  return std::make_unique<TYPEOF(obj)>(FWD(obj));
110  }
111 
112  template <class Obj>
113  auto makeSharedPtr(Obj&& obj)
114  {
115  return std::make_shared<TYPEOF(obj)>(FWD(obj));
116  }
117 
118  template <bool... b>
119  using enable_if_all_t = std::enable_if_t<(b &&...)>;
120 
121 } // end namespace AMDiS
A functor with no operation.
Definition: TypeTraits.hpp:99
A variadic type list.
Definition: TypeTraits.hpp:88
typename remove_cvref< T >::type remove_cvref_t
Helper alias template for remove_cvref.
Definition: TypeTraits.hpp:24
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
Remove cv and ref qualifiers of type T.
Definition: TypeTraits.hpp:17
auto makeUniquePtr(Obj &&obj)
Create a unique_ptr by copy/move construction.
Definition: TypeTraits.hpp:107
T owner
Alias that indicates ownership of resources.
Definition: TypeTraits.hpp:96