13 alignas(
alignof(T))
char data[
sizeof(T)];
16 std::atomic<bool> destroyed =
false;
19 explicit ManuallyDrop(T && t)
21 ::new (data) T(std::move(t));
25 template<
typename... Arg>
28 ::new (data) T(std::forward<Arg>(args)...);
47 assert(!destroyed.load(std::memory_order_relaxed));
48 return reinterpret_cast<T &
>(data);
74 bool wasDestroyed = destroyed.exchange(
true, std::memory_order_acq_rel);
75 assert(!wasDestroyed);
76 return std::move(
reinterpret_cast<T &
>(data));
83 bool wasDestroyed = destroyed.exchange(
true, std::memory_order_acq_rel);
Definition manually-drop.hh:12
T & get()
Definition manually-drop.hh:43
void destroy()
Definition manually-drop.hh:80
T && take() &&
Definition manually-drop.hh:71
ManuallyDrop(std::in_place_t, Arg &&... args)
Definition manually-drop.hh:26