TypeTraits.hpp 1.33 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pragma once

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

#if AMDIS_HAS_CXX_CONSTEXPR_IF
#define IF_CONSTEXPR if constexpr
#else
#define IF_CONSTEXPR if
#endif

namespace AMDiS
{
  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;

33
34
35
36
37
38
39
40
41
42

  /// Macro for forwarding universal references to obj
  #define FWD(obj) std::forward<decltype(obj)>(obj)

  /// A decay version of decltype, similar to GCCs __typeof__
  #define TYPEOF(...) remove_cvref_t<decltype(__VA_ARGS__)>

  /// Extract the static value of an integral_constant variable
  #define VALUE(...) TYPEOF(__VA_ARGS__)::value

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  // ---------------------------------------------------------------------------

  /// A variadic type list
  template <class... Ts>
  struct Types {};

  template <class... Ts>
  using Types_t = Types<std::decay_t<Ts>...>;


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


  /// Create a unique_ptr by copy/move construction
  template <class Obj>
  auto makeUniquePtr(Obj&& obj)
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
62
    return std::make_unique<remove_cvref_t<Obj>>(FWD(obj));
63
64
65
  }

} // end namespace AMDiS