DASH  0.3.0
Meta.h
1 #ifndef DASH__META_H__INCLUDED
2 #define DASH__META_H__INCLUDED
3 
4 #include <dash/Types.h>
5 #include <dash/meta/TypeInfo.h>
6 
7 #include <type_traits>
8 
9 
10 #ifndef DOXYGEN
11 
12 #define DASH__META__DEFINE_TRAIT__HAS_TYPE(DepType) \
13  template<typename T> \
14  struct has_type_##DepType { \
15  private: \
16  typedef char yes; \
17  typedef struct { char array[2]; } no; \
18  template<typename C> static yes test(typename C:: DepType *); \
19  template<typename C> static no test(...); \
20  public: \
21  static constexpr bool value = sizeof(test<T>(0)) == sizeof(yes); \
22  };
23 
24 #endif // DOXYGEN
25 
26 namespace dash {
27 
28 
29 template<class...> struct conjunction : std::true_type { };
30 
31 template<class Cond0> struct conjunction<Cond0> : Cond0 { };
32 
33 template<class Cond0, class... CondN>
34 struct conjunction<Cond0, CondN...>
35 : std::conditional<
36  bool(Cond0::value),
37  conjunction<CondN...>,
38  Cond0 >
39 { };
40 
41 
42 
48 DASH__META__DEFINE_TRAIT__HAS_TYPE(iterator)
54 DASH__META__DEFINE_TRAIT__HAS_TYPE(const_iterator)
60 DASH__META__DEFINE_TRAIT__HAS_TYPE(reference)
66 DASH__META__DEFINE_TRAIT__HAS_TYPE(const_reference)
72 DASH__META__DEFINE_TRAIT__HAS_TYPE(value_type)
73 
74 
75 } // namespace dash
76 
77 #include <type_traits>
78 #include <functional>
79 
80 #ifndef DOXYGEN
81 
82 namespace dash {
83 
84 /*
85  * For reference, see
86  *
87  * "Working Draft, C++ Extension for Ranges"
88  * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4569.pdf
89  *
90  */
91 
92 template <class I>
93 using reference_t = typename std::add_lvalue_reference<I>::type;
94 
95 template <class I>
96 using rvalue_reference_t =
97  decltype(std::move(std::declval<dash::reference_t<I>>()));
98 
99 // void f(ValueType && val) {
100 // std::string i(move(val));
101 // // ...
102 // }
103 //
104 // ValueType val;
105 // std::bind(f, dash::make_adv(std::move(val)))();
106 
107 template<typename T> struct adv {
108  T _value;
109  explicit adv(T && value) : _value(std::forward<T>(value)) {}
110  template<typename ...U> T && operator()(U &&...) {
111  return std::forward<T>(_value);
112  }
113 };
114 
115 template<typename T> adv<T> make_adv(T && value) {
116  return adv<T> { std::forward<T>(value) };
117 }
118 
119 } // namespace dash
120 
121 namespace dash {
122 namespace functional {
123 
124 /*
125  * Obtaining parameter types and return type from a lambda:
126  * see http://coliru.stacked-crooked.com/a/6a87fadcf44c6a0f
127  */
128 
129 template <typename T>
130 struct closure_traits : closure_traits<decltype(&T::operator())> {
131 };
132 
133 #define REM_CTOR(...) __VA_ARGS__
134 #define SPEC(cv, var, is_var) \
135  template <typename C, typename R, typename... Args> \
136  struct closure_traits<R (C::*)(Args... REM_CTOR var) cv> { /* NOLINT */ \
137  using arity = std::integral_constant<std::size_t, sizeof...(Args)>; \
138  using is_variadic = std::integral_constant<bool, is_var>; \
139  using is_const = std::is_const<int cv>; /* NOLINT */ \
140  \
141  using result_type = R; \
142  \
143  template <std::size_t i> \
144  using arg = typename std::tuple_element<i, std::tuple<Args...>>::type; \
145  };
146 
147 SPEC(const, (, ...), 1)
148 SPEC(const, (), 0)
149 SPEC(, (, ...), 1)
150 SPEC(, (), 0)
151 
152 } // namespace functional
153 } // namespace dash
154 
155 namespace std {
156  // Must be defined in global std namespace.
157  template<typename T>
158  struct is_bind_expression< dash::adv<T> > : std::true_type {};
159 }
160 
161 #endif // DOXYGEN
162 
163 #endif // DASH__META_H__INCLUDED
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
Definition: cstddef.h:8