edits
[c11concurrency-benchmarks.git] / silo / ndb_type_traits.h
1 #ifndef _NDB_TYPE_TRAITS_H_
2 #define _NDB_TYPE_TRAITS_H_
3
4 #include <type_traits>
5
6 namespace private_ {
7
8   // std::is_trivially_destructible not supported in g++-4.7, so we
9   // do some hacky [conservative] variant of it
10   template <typename T>
11   struct is_trivially_destructible {
12     static const bool value = std::is_scalar<T>::value;
13   };
14
15   template <typename K, typename V>
16   struct is_trivially_destructible<std::pair<K, V>> {
17     static const bool value =
18       is_trivially_destructible<K>::value &&
19       is_trivially_destructible<V>::value;
20   };
21
22   // XXX: same for now
23   template <typename T>
24   struct is_trivially_copyable : public is_trivially_destructible<T> {};
25
26   // user types should add their own specializations
27
28   template <typename T>
29   struct typeutil { typedef const T & func_param_type; };
30
31   template <typename T>
32   struct primitive_typeutil { typedef T func_param_type; };
33
34   // specialize typeutil for int types to use primitive_typeutil
35
36 #define SPECIALIZE_PRIM_TYPEUTIL(tpe) \
37   template <> struct typeutil< tpe > : public primitive_typeutil< tpe > {};
38
39   SPECIALIZE_PRIM_TYPEUTIL(bool)
40   SPECIALIZE_PRIM_TYPEUTIL(int8_t)
41   SPECIALIZE_PRIM_TYPEUTIL(uint8_t)
42   SPECIALIZE_PRIM_TYPEUTIL(int16_t)
43   SPECIALIZE_PRIM_TYPEUTIL(uint16_t)
44   SPECIALIZE_PRIM_TYPEUTIL(int32_t)
45   SPECIALIZE_PRIM_TYPEUTIL(uint32_t)
46   SPECIALIZE_PRIM_TYPEUTIL(int64_t)
47   SPECIALIZE_PRIM_TYPEUTIL(uint64_t)
48 }
49
50 #endif /* _NDB_TYPE_TRAITS_H_ */