fix(templates): fix FSingleton not working correctly with EBO on MSVC

make CAnyCustomStorage satisfy the concept of FSingleton
This commit is contained in:
_Redstone_c_ 2022-11-18 23:17:54 +08:00
parent a4ac19673f
commit 6a70d4273e
4 changed files with 24 additions and 13 deletions

View File

@ -15,29 +15,32 @@ NAMESPACE_MODULE_BEGIN(Utility)
// TAny's CustomStorage concept, see FAnyDefaultStorage
template <typename T>
concept CAnyCustomStorage =
CSameAs<decltype(T::InlineSize), const size_t> &&
CSameAs<decltype(T::InlineAlignment), const size_t> &&
requires(const T& A)
concept CAnyCustomStorage = CDefaultConstructible<T>
&& !CCopyConstructible<T> && !CMoveConstructible<T>
&& !CCopyAssignable<T> && !CMoveAssignable<T>
&& CDestructible<T>
&& CSameAs<decltype(T::InlineSize), const size_t>
&& CSameAs<decltype(T::InlineAlignment), const size_t>
&& requires(const T& A)
{
{ A.InlineAllocation() } -> CSameAs<const void*>;
{ A.HeapAllocation() } -> CSameAs<void*>;
{ A.TypeInfo() } -> CSameAs<uintptr>;
} &&
requires(T& A)
}
&& requires(T& A)
{
{ A.InlineAllocation() } -> CSameAs<void*>;
{ A.HeapAllocation() } -> CSameAs<void*&>;
{ A.TypeInfo() } -> CSameAs<uintptr&>;
} &&
requires(T& A, const T& B, T&& C)
}
&& requires(T& A, const T& B, T&& C)
{
A.CopyCustom(B);
A.MoveCustom(MoveTemp(C));
};
// TAny's default storage structure
struct alignas(16) FAnyDefaultStorage
struct alignas(16) FAnyDefaultStorage : FSingleton
{
// The built-in copy/move operators are disabled and CopyCustom/MoveCustom is used instead of them

View File

@ -54,7 +54,7 @@ NAMESPACE_PRIVATE_END
template <typename T, bool bIsRef = false> requires (CTriviallyCopyable<T>
&& CCopyConstructible<T> && CMoveConstructible<T>
&& CCopyAssignable<T> && CMoveAssignable<T>)
struct TAtomic : public FSingleton
struct TAtomic : FSingleton
{
protected:
@ -233,7 +233,7 @@ using TAtomicRef = TAtomic<T, true>;
template <typename T>
TAtomic(T) -> TAtomic<T>;
struct FAtomicFlag : public FSingleton
struct FAtomicFlag : FSingleton
{
public:

View File

@ -149,7 +149,7 @@ private:
};
template <typename CallableType>
struct alignas(16) FFunctionStorage
struct alignas(16) FFunctionStorage : FSingleton
{
//~ Begin CAnyCustomStorage Interface
inline static constexpr size_t InlineSize = 64 - sizeof(uintptr) - sizeof(CallableType);

View File

@ -20,7 +20,15 @@ struct FNonmovable
FNonmovable& operator=(FNonmovable&&) = delete;
};
struct FSingleton : public FNoncopyable, public FNonmovable { };
// Multiple inheritance is no longer used here, as that would break the EBO in MSVC
struct FSingleton // : FNoncopyable, FNonmovable
{
FSingleton() = default;
FSingleton(const FSingleton&) = delete;
FSingleton(FSingleton&&) = delete;
FSingleton& operator=(const FSingleton&) = delete;
FSingleton& operator=(FSingleton&&) = delete;
};
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)