diff --git a/Redcraft.Utility/Source/Public/Templates/Any.h b/Redcraft.Utility/Source/Public/Templates/Any.h index 82f20b0..fdaf876 100644 --- a/Redcraft.Utility/Source/Public/Templates/Any.h +++ b/Redcraft.Utility/Source/Public/Templates/Any.h @@ -15,7 +15,26 @@ NAMESPACE_MODULE_BEGIN(Utility) // TAny's CustomStorage concept, see FAnyDefaultStorage. template -concept CAnyStorage = true; // TODO +concept CAnyCustomStorage = +// CSameAs && +// CSameAs && + requires(const T& A) + { + { A.InlineAllocation() } -> CSameAs; + { A.HeapAllocation() } -> CSameAs; + { A.TypeInfo() } -> CSameAs; + } && + requires(T& A) + { + { A.InlineAllocation() } -> CSameAs; + { A.HeapAllocation() } -> CSameAs; + { A.TypeInfo() } -> CSameAs; + } && + requires(T& A, const T& B, T&& C) + { + A.CopyCustom(B); + A.MoveCustom(MoveTemp(C)); + }; // TAny's default storage structure. struct alignas(16) FAnyDefaultStorage @@ -25,7 +44,7 @@ struct alignas(16) FAnyDefaultStorage // You can add custom variables like this. //Type Variable; - //~ Begin CAnyStorage Interface + //~ Begin CAnyCustomStorage Interface inline static constexpr size_t InlineSize = 64 - sizeof(uintptr); inline static constexpr size_t InlineAlignment = 16; constexpr void* InlineAllocation() { return &InlineAllocationImpl; } @@ -36,7 +55,7 @@ struct alignas(16) FAnyDefaultStorage constexpr uintptr TypeInfo() const { return TypeInfoImpl; } constexpr void CopyCustom(const FAnyDefaultStorage& InValue) { /* Variable = InValue.Variable; */ } // You just need to copy the custom variables. constexpr void MoveCustom( FAnyDefaultStorage&& InValue) { /* Variable = MoveTemp(InValue.Variable); */ } // You just need to move the custom variables. - //~ End CAnyStorage Interface + //~ End CAnyCustomStorage Interface union { @@ -48,11 +67,11 @@ struct alignas(16) FAnyDefaultStorage }; -static_assert(CAnyStorage); +static_assert(CAnyCustomStorage); // You can add custom storage area through CustomStorage, such as TFunction. // It is not recommended to use this, FAny is recommended. -template +template struct TAny { inline static constexpr size_t InlineSize = CustomStorage::InlineSize; @@ -460,13 +479,13 @@ private: }; -template +template constexpr bool operator==(const TAny& LHS, const T& RHS) { return LHS.template HoldsAlternative() ? LHS.template GetValue() == RHS : false; } -template +template constexpr bool operator==(const TAny& LHS, FInvalid) { return !LHS.IsValid(); @@ -474,8 +493,8 @@ constexpr bool operator==(const TAny& LHS, FInvalid) NAMESPACE_PRIVATE_BEGIN -template struct TIsTAny : FFalse { }; -template struct TIsTAny> : FTrue { }; +template struct TIsTAny : FFalse { }; +template struct TIsTAny> : FTrue { }; NAMESPACE_PRIVATE_END diff --git a/Redcraft.Utility/Source/Public/Templates/Function.h b/Redcraft.Utility/Source/Public/Templates/Function.h index 1d41d2e..5a8ede5 100644 --- a/Redcraft.Utility/Source/Public/Templates/Function.h +++ b/Redcraft.Utility/Source/Public/Templates/Function.h @@ -83,7 +83,7 @@ template struct TFunctionInfo struct alignas(16) FFunctionStorage { - //~ Begin CAnyStorage Interface + //~ Begin CAnyCustomStorage Interface inline static constexpr size_t InlineSize = 64 - sizeof(uintptr) - sizeof(CallableType); inline static constexpr size_t InlineAlignment = 16; constexpr void* InlineAllocation() { return &InlineAllocationImpl; } @@ -94,7 +94,7 @@ struct alignas(16) FFunctionStorage constexpr uintptr TypeInfo() const { return TypeInfoImpl; } constexpr void CopyCustom(const FFunctionStorage& InValue) { Callable = InValue.Callable; } constexpr void MoveCustom( FFunctionStorage&& InValue) { Callable = InValue.Callable; } - //~ End CAnyStorage Interface + //~ End CAnyCustomStorage Interface union { @@ -106,9 +106,6 @@ struct alignas(16) FFunctionStorage CallableType Callable; - template - friend struct TAny; - }; template struct TFunctionImpl;