diff options
| -rw-r--r-- | src/common/intrusive_red_black_tree.h | 4 | ||||
| -rw-r--r-- | src/common/parent_of_member.h | 14 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/common/intrusive_red_black_tree.h b/src/common/intrusive_red_black_tree.h index 929b5497e..fb55de94e 100644 --- a/src/common/intrusive_red_black_tree.h +++ b/src/common/intrusive_red_black_tree.h | |||
| @@ -533,7 +533,7 @@ private: | |||
| 533 | } | 533 | } |
| 534 | 534 | ||
| 535 | private: | 535 | private: |
| 536 | static constexpr TYPED_STORAGE(Derived) DerivedStorage = {}; | 536 | static constexpr TypedStorage<Derived> DerivedStorage = {}; |
| 537 | static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage)); | 537 | static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage)); |
| 538 | }; | 538 | }; |
| 539 | 539 | ||
| @@ -549,7 +549,7 @@ public: | |||
| 549 | using TreeTypeImpl = impl::IntrusiveRedBlackTreeImpl; | 549 | using TreeTypeImpl = impl::IntrusiveRedBlackTreeImpl; |
| 550 | 550 | ||
| 551 | static constexpr bool IsValid() { | 551 | static constexpr bool IsValid() { |
| 552 | TYPED_STORAGE(Derived) DerivedStorage = {}; | 552 | TypedStorage<Derived> DerivedStorage = {}; |
| 553 | return GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage); | 553 | return GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage); |
| 554 | } | 554 | } |
| 555 | 555 | ||
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 | }; |