-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.hpp
More file actions
41 lines (30 loc) · 809 Bytes
/
storage.hpp
File metadata and controls
41 lines (30 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
#include <type_traits>
#include <memory>
#include "utility.hpp"
namespace ns::impl {
template <typename ... Ts>
struct generate_destroy_table {
template <typename T>
constexpr static void destroy (std::aligned_union_t <0, Ts...> & data) {
reinterpret_cast<T *> (std::addressof (data))->~T ();
}
using f_ptr = decltype (std::addressof (destroy<impl::head_t<Ts...>>));
constexpr static f_ptr table[] = {
std::addressof (destroy<Ts>)...
};
};
template <bool is_trivially_destructible, typename ... Ts>
struct storage {
std::aligned_union_t <0, Ts...> data;
std::size_t index;
};
template <typename ... Ts>
struct storage<false, Ts...> {
std::aligned_union_t <0, Ts...> data;
std::size_t index;
~storage () {
(generate_destroy_table<Ts...>::table [index] (data));
}
};
}