38 #ifndef LIBPMEMOBJ_CPP_DESTROYER_HPP
39 #define LIBPMEMOBJ_CPP_DESTROYER_HPP
42 #include <type_traits>
65 struct if_not_array<T[]>;
70 template <
typename T,
size_t N>
71 struct if_not_array<T[N]>;
83 struct if_size_array<T[]>;
88 template <
typename T,
size_t N>
89 struct if_size_array<T[N]> {
98 template <
typename T,
typename... Args>
100 create(
typename if_not_array<T>::type *ptr, Args &&... args)
102 #if __cpp_lib_is_aggregate
103 if constexpr (std::is_aggregate_v<T>)
104 new (
static_cast<void *
>(ptr)) T{std::forward<Args>(args)...};
106 new (
static_cast<void *
>(ptr)) T(std::forward<Args>(args)...);
108 new (
static_cast<void *
>(ptr)) T(std::forward<Args>(args)...);
115 template <
typename T,
typename... Args>
117 create(
typename if_size_array<T>::type *ptr, Args &&... args)
119 typedef typename detail::pp_array_type<T>::type I;
120 enum { N = pp_array_elems<T>::elems };
122 for (std::size_t i = 0; i < N; ++i)
123 create<I>(&(*ptr)[i], std::forward<Args>(args)...);
129 template <
typename T,
130 typename =
typename std::enable_if<!std::is_pod<T>::value>::type>
132 destroy(
typename if_not_array<T>::type &arg)
140 template <
typename T,
typename dummy = void,
141 typename =
typename std::enable_if<std::is_pod<T>::value>::type>
143 destroy(
typename if_not_array<T>::type &)
150 template <
typename T>
152 destroy(
typename if_size_array<T>::type &arg)
154 typedef typename detail::pp_array_type<T>::type I;
155 enum { N = pp_array_elems<T>::elems };
157 for (std::size_t i = 0; i < N; ++i)
158 destroy<I>(arg[N - 1 - i]);