summaryrefslogtreecommitdiff
path: root/src/common/parent_of_member.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/parent_of_member.h')
-rw-r--r--src/common/parent_of_member.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/common/parent_of_member.h b/src/common/parent_of_member.h
index 1af31ee44..d9a14529d 100644
--- a/src/common/parent_of_member.h
+++ b/src/common/parent_of_member.h
@@ -10,21 +10,23 @@
10#include "common/common_types.h" 10#include "common/common_types.h"
11 11
12namespace Common { 12namespace Common {
13 13namespace detail {
14template <typename T, size_t Size, size_t Align> 14template <typename T, size_t Size, size_t Align>
15struct TypedStorage { 15struct TypedStorageImpl {
16 std::aligned_storage_t<Size, Align> storage_; 16 std::aligned_storage_t<Size, Align> storage_;
17}; 17};
18} // namespace detail
18 19
19#define TYPED_STORAGE(...) TypedStorage<__VA_ARGS__, sizeof(__VA_ARGS__), alignof(__VA_ARGS__)> 20template <typename T>
21using TypedStorage = detail::TypedStorageImpl<T, sizeof(T), alignof(T)>;
20 22
21template <typename T> 23template <typename T>
22static constexpr T* GetPointer(TYPED_STORAGE(T) & ts) { 24static constexpr T* GetPointer(TypedStorage<T>& ts) {
23 return static_cast<T*>(static_cast<void*>(std::addressof(ts.storage_))); 25 return static_cast<T*>(static_cast<void*>(std::addressof(ts.storage_)));
24} 26}
25 27
26template <typename T> 28template <typename T>
27static constexpr const T* GetPointer(const TYPED_STORAGE(T) & ts) { 29static constexpr const T* GetPointer(const TypedStorage<T>& ts) {
28 return static_cast<const T*>(static_cast<const void*>(std::addressof(ts.storage_))); 30 return static_cast<const T*>(static_cast<const void*>(std::addressof(ts.storage_)));
29} 31}
30 32
@@ -72,7 +74,7 @@ struct OffsetOfCalculator {
72 union Union { 74 union Union {
73 char c{}; 75 char c{};
74 UnionHolder first_union; 76 UnionHolder first_union;
75 TYPED_STORAGE(ParentType) parent; 77 TypedStorage<ParentType> parent;
76 78
77 constexpr Union() : c() {} 79 constexpr Union() : c() {}
78 }; 80 };