9 #ifndef LIBPMEMOBJ_CPP_LIFE_HPP
10 #define LIBPMEMOBJ_CPP_LIFE_HPP
14 #include <type_traits>
38 struct if_not_array<T[]>;
43 template <
typename T,
size_t N>
44 struct if_not_array<T[N]>;
56 struct if_size_array<T[]>;
61 template <
typename T,
size_t N>
62 struct if_size_array<T[N]> {
71 template <
typename T,
typename... Args>
73 create(
typename if_not_array<T>::type *ptr, Args &&... args)
75 #if __cpp_lib_is_aggregate
76 if constexpr (std::is_aggregate_v<T>)
77 new (
static_cast<void *
>(ptr)) T{std::forward<Args>(args)...};
79 new (
static_cast<void *
>(ptr)) T(std::forward<Args>(args)...);
81 new (
static_cast<void *
>(ptr)) T(std::forward<Args>(args)...);
88 template <
typename T,
typename... Args>
90 create(
typename if_size_array<T>::type *ptr, Args &&... args)
92 typedef typename detail::pp_array_type<T>::type I;
93 enum { N = pp_array_elems<T>::elems };
95 for (std::size_t i = 0; i < N; ++i)
96 create<I>(&(*ptr)[i], std::forward<Args>(args)...);
104 template <
typename T,
size_t... Indices,
typename Tuple>
106 create_from_tuple(
void *ptr, index_sequence<Indices...>, Tuple tuple)
108 new (ptr) T(std::get<Indices>(std::move(tuple))...);
116 template <
typename T,
typename Tuple,
typename... Args>
118 c_style_construct(
void *ptr,
void *arg)
120 auto *arg_pack =
static_cast<Tuple *
>(arg);
123 create_from_tuple<T>(ptr, index_sequence_for<Args...>{},
124 std::move(*arg_pack));
135 template <
typename T,
136 typename =
typename std::enable_if<
137 !std::is_trivially_destructible<T>::value>::type>
139 destroy(
typename if_not_array<T>::type &arg)
147 template <
typename T,
typename dummy = void,
148 typename =
typename std::enable_if<
149 std::is_trivially_destructible<T>::value>::type>
151 destroy(
typename if_not_array<T>::type &)
158 template <
typename T>
160 destroy(
typename if_size_array<T>::type &arg)
162 typedef typename detail::pp_array_type<T>::type I;
163 enum { N = pp_array_elems<T>::elems };
165 for (std::size_t i = 0; i < N; ++i)
166 destroy<I>(arg[N - 1 - i]);
Create c++14 style index sequence.
Persistent memory namespace.
Definition: allocation_flag.hpp:15