ams: remove TYPED_STORAGE() macro in favor of template

This commit is contained in:
Michael Scire 2021-03-21 18:47:30 -07:00
parent 8d9174b227
commit aff0da9427
31 changed files with 55 additions and 57 deletions

View file

@ -25,7 +25,7 @@ namespace ams::util {
class BoundedMap {
private:
std::array<std::optional<Key>, N> keys;
std::array<TYPED_STORAGE(Value), N> values;
std::array<TypedStorage<Value>, N> values;
private:
ALWAYS_INLINE void FreeEntry(size_t i) {
this->keys[i].reset();

View file

@ -569,7 +569,7 @@ namespace ams::util {
return util::GetParentReference<Member, Derived>(&node);
}
private:
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
static constexpr TypedStorage<Derived> DerivedStorage = {};
static_assert(std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage));
};
@ -582,7 +582,7 @@ namespace ams::util {
using ListType = IntrusiveList<Derived, IntrusiveListMemberTraitsDeferredAssert>;
static constexpr bool IsValid() {
TYPED_STORAGE(Derived) DerivedStorage = {};
TypedStorage<Derived> DerivedStorage = {};
return std::addressof(GetParent(GetNode(GetReference(DerivedStorage)))) == GetPointer(DerivedStorage);
}
private:

View file

@ -498,7 +498,7 @@ namespace ams::util {
return util::GetParentPointer<Member, Derived>(node);
}
private:
static constexpr TYPED_STORAGE(Derived) DerivedStorage = {};
static constexpr TypedStorage<Derived> DerivedStorage = {};
static_assert(GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage));
};
@ -513,7 +513,7 @@ namespace ams::util {
using TreeTypeImpl = impl::IntrusiveRedBlackTreeImpl;
static constexpr bool IsValid() {
TYPED_STORAGE(Derived) DerivedStorage = {};
TypedStorage<Derived> DerivedStorage = {};
return GetParent(GetNode(GetPointer(DerivedStorage))) == GetPointer(DerivedStorage);
}
private:

View file

@ -63,7 +63,7 @@ namespace ams::util {
union Union {
char c;
UnionHolder first_union;
TYPED_STORAGE(ParentType) parent;
TypedStorage<ParentType> parent;
/* This coerces the active member to be c. */
constexpr Union() : c() { /* ... */ }
@ -110,7 +110,7 @@ namespace ams::util {
template<typename ParentType, typename MemberType>
struct OffsetOfCalculator {
static constexpr std::ptrdiff_t OffsetOf(MemberType ParentType::*member) {
constexpr TYPED_STORAGE(ParentType) Holder = {};
constexpr TypedStorage<ParentType> Holder = {};
const auto *parent = GetPointer(Holder);
const auto *target = std::addressof(parent->*member);
return static_cast<const uint8_t *>(static_cast<const void *>(target)) - static_cast<const uint8_t *>(static_cast<const void *>(parent));

View file

@ -20,30 +20,28 @@
namespace ams::util {
template<typename T, size_t Size, size_t Align>
template<typename T, size_t Size = sizeof(T), size_t Align = alignof(T)>
struct TypedStorage {
typename std::aligned_storage<Size, Align>::type _storage;
};
#define TYPED_STORAGE(...) ::ams::util::TypedStorage<__VA_ARGS__, sizeof(__VA_ARGS__), alignof(__VA_ARGS__)>
template<typename T>
static constexpr ALWAYS_INLINE T *GetPointer(TYPED_STORAGE(T) &ts) {
static constexpr ALWAYS_INLINE T *GetPointer(TypedStorage<T> &ts) {
return static_cast<T *>(static_cast<void *>(std::addressof(ts._storage)));
}
template<typename T>
static constexpr ALWAYS_INLINE const T *GetPointer(const TYPED_STORAGE(T) &ts) {
static constexpr ALWAYS_INLINE const T *GetPointer(const TypedStorage<T> &ts) {
return static_cast<const T *>(static_cast<const void *>(std::addressof(ts._storage)));
}
template<typename T>
static constexpr ALWAYS_INLINE T &GetReference(TYPED_STORAGE(T) &ts) {
static constexpr ALWAYS_INLINE T &GetReference(TypedStorage<T> &ts) {
return *GetPointer(ts);
}
template<typename T>
static constexpr ALWAYS_INLINE const T &GetReference(const TYPED_STORAGE(T) &ts) {
static constexpr ALWAYS_INLINE const T &GetReference(const TypedStorage<T> &ts) {
return *GetPointer(ts);
}