OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
common.hpp
1 #ifndef COMMON_HPP
2 #define COMMON_HPP
3 
4 #include <type_traits>
5 #include <random>
6 #include "memory/memory.hpp"
7 #include "util/for_each_ref.hpp"
8 #include "util/variadic_to_vmpl.hpp"
9 
10 constexpr int RUN_ON_DEVICE = 1024;
11 
12 #define GCC_VERSION (__GNUC__ * 10000 \
13  + __GNUC_MINOR__ * 100 \
14  + __GNUC_PATCHLEVEL__)
15 
16 
17 template<unsigned int N,typename T>
19 {
20  T sa[N];
21 };
22 
23 namespace std
24 {
25  // We need the definition of std::to_string that work on string
26  inline static std::string to_string(std::string s)
27  {
28  return s;
29  }
30 }
31 
32 
40 namespace openfpm
41 {
42  template <class T>
43  constexpr typename std::add_const<T>::type & as_const(T& t) noexcept
44  {
45  return t;
46  }
47 
48  template <typename> struct Debug;
49 }
50 
52  // {3,3,3,3,3,3,.....}
53  template<size_t index, size_t N> struct Fill_three {
54  enum { value = 3 };
55  };
56 
58  template<size_t index, size_t N> struct Fill_zero {
59  enum { value = 0 };
60  };
61 
63  template<size_t index, size_t N> struct Fill_two {
64  enum { value = 2 };
65  };
66 
68  template<size_t index, size_t N> struct Fill_one {
69  enum { value = 1 };
70  };
71 
73 template<typename> struct Void
74 {
76  typedef void type;
77 };
78 
79 template<typename T, typename Sfinae = void>
80 struct has_attributes: std::false_type {};
81 
82 
94 template<typename T>
95 struct has_attributes<T, typename Void<decltype( T::attributes::name[0] )>::type> : std::true_type
96 {};
97 
98 template<typename T, typename Sfinae = void>
99 struct has_typedef_type: std::false_type {};
100 
111 template<typename T>
112 struct has_typedef_type<T, typename Void< typename T::type>::type> : std::true_type
113 {};
114 
115 template<typename T, typename Sfinae = void>
116 struct has_vector_kernel: std::false_type {};
117 
127 template<typename T>
128 struct has_vector_kernel<T, typename Void< typename T::vector_kernel >::type> : std::true_type
129 {};
130 
131 template<typename T, typename Sfinae = void>
132 struct has_set_d: std::false_type {};
133 
137 template<typename T>
138 struct has_set_d<T, typename Void<decltype( std::declval<T>().set_d(0,0) )>::type> : std::true_type
139 {};
140 
141 template<typename T, typename Sfinae = void>
142 struct has_data: std::false_type {};
143 
153 template<typename T>
154 struct has_data<T, typename Void<decltype( T::data )>::type> : std::true_type
155 {};
156 
157 template<typename T, typename Sfinae = void>
158 struct has_posMask: std::false_type {};
159 
167 template<typename T>
168 struct has_posMask<T, typename Void<decltype( T::stag_mask )>::type> : std::true_type
169 {};
170 
171 
188 template<bool cond, typename T>
190 {
191  enum
192  {
193  value = std::is_same<decltype(std::declval<T>().data),typename T::type>::value
194  };
195 };
196 
197 
198 template<typename T>
200 {
201  enum
202  {
203  value = false
204  };
205 };
206 
207 
208 template<typename T, typename Sfinae = void>
209 struct has_noPointers: std::false_type {};
210 
211 
223 template<typename T>
224 struct has_noPointers<T, typename Void<decltype( T::noPointers() )>::type> : std::true_type
225 {};
226 
239 template<typename ObjType, typename Sfinae = void>
240 struct has_pack: std::false_type {};
241 
242 template<typename ObjType>
243 struct has_pack<ObjType, typename Void<decltype( ObjType::pack() )>::type> : std::true_type
244 {};
245 
258 template<typename ObjType, typename Sfinae = void>
259 struct has_toKernel: std::false_type {};
260 
261 template<typename ObjType>
262 struct has_toKernel<ObjType, typename Void<decltype( std::declval<ObjType>().toKernel() )>::type> : std::true_type
263 {};
264 
277 template<typename ObjType, typename Sfinae = void>
278 struct has_packRequest: std::false_type {};
279 
280 template<typename ObjType>
281 struct has_packRequest<ObjType, typename Void<decltype( ObjType::packRequest() )>::type> : std::true_type
282 {};
283 
284 
297 template<typename ObjType, typename Sfinae = void>
298 struct has_packMem: std::false_type {};
299 
308 template<typename ObjType>
309 struct has_packMem<ObjType, typename Void<decltype( ObjType::packMem() )>::type> : std::true_type
310 {};
311 
322 template<typename T, bool = is_typedef_and_data_same<has_typedef_type<T>::value && has_data<T>::value,T>::value>
323 struct is_openfpm_native : std::false_type
324 {};
325 
326 
327 template<typename T>
328 struct is_openfpm_native<T,true> : std::true_type
329 {};
330 
331 template<typename T, typename Sfinae = void>
332 struct has_value_type_ofp: std::false_type {};
333 
343 template<typename T>
344 struct has_value_type_ofp<T, typename Void< typename T::value_type>::type> : std::true_type
345 {};
346 
347 
349 template<size_t index, size_t N> struct MetaFunc {
350  enum { value = index + N };
351 };
352 
353 
354 template<size_t index, size_t N> struct MetaFuncOrd {
355  enum { value = index };
356 };
357 
359 
360 template<typename ObjType, typename Sfinae = void>
361 struct isDynStruct: std::false_type
362 {
363  constexpr static bool value()
364  {
365  return false;
366  }
367 };
368 
369 template<typename ObjType>
370 struct isDynStruct<ObjType, typename Void<decltype( ObjType::isCompressed() )>::type> : std::true_type
371 {
372  constexpr static bool value()
373  {
374  return ObjType::isCompressed();
375  }
376 };
377 
378 template<typename T, typename Sfinae = void>
379 struct is_Box: std::false_type {};
380 
381 
387 template<typename T>
388 struct is_Box<T, typename Void< typename T::yes_is_box>::type> : std::true_type
389 {};
390 
391 template<typename T, typename Sfinae = void>
392 struct is_Point: std::false_type {};
393 
394 
400 template<typename T>
401 struct is_Point<T, typename Void< typename T::yes_is_point>::type> : std::true_type
402 {};
403 
404 #endif
convert a type into constant type
Definition: aggregate.hpp:292
{0,0,0,0,....}
Definition: common.hpp:58
has_Pack check if a type has defined a method called Pack
Definition: common.hpp:240
check if T::type and T.data has the same type
Definition: common.hpp:189
has_packRequest check if a type has defined a method called packRequest
Definition: common.hpp:278
is_openfpm_native check if a type is an openfpm native structure type
Definition: common.hpp:323
Compile time array functor needed to generate array at compile-time of type.
Definition: common.hpp:53
Void structure.
Definition: common.hpp:73
[Metafunction definition]
Definition: common.hpp:349
has_calculateMem check if a type has defined a method called calculateMem
Definition: common.hpp:298
{1,1,1,1,....}
Definition: common.hpp:68
{2,2,2,2,....}
Definition: common.hpp:63
void type
define void type
Definition: common.hpp:76
has_toKernel check if a type has defined a method called toKernel
Definition: common.hpp:259