diff options
Diffstat (limited to 'src/common/parent_of_member.h')
| -rw-r--r-- | src/common/parent_of_member.h | 14 |
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 | ||
| 12 | namespace Common { | 12 | namespace Common { |
| 13 | 13 | namespace detail { | |
| 14 | template <typename T, size_t Size, size_t Align> | 14 | template <typename T, size_t Size, size_t Align> |
| 15 | struct TypedStorage { | 15 | struct 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__)> | 20 | template <typename T> |
| 21 | using TypedStorage = detail::TypedStorageImpl<T, sizeof(T), alignof(T)>; | ||
| 20 | 22 | ||
| 21 | template <typename T> | 23 | template <typename T> |
| 22 | static constexpr T* GetPointer(TYPED_STORAGE(T) & ts) { | 24 | static 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 | ||
| 26 | template <typename T> | 28 | template <typename T> |
| 27 | static constexpr const T* GetPointer(const TYPED_STORAGE(T) & ts) { | 29 | static 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 | }; |