From 2a3a5aec35f91e7620743dd62965bb6b4b83682e Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Tue, 5 Apr 2022 13:20:00 +0800 Subject: [PATCH] refactor(templates): make TAny use the construct when the operator= is delete --- Redcraft.Utility/Source/Public/Templates/Any.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Templates/Any.h b/Redcraft.Utility/Source/Public/Templates/Any.h index 3e94ddc..3e8349a 100644 --- a/Redcraft.Utility/Source/Public/Templates/Any.h +++ b/Redcraft.Utility/Source/Public/Templates/Any.h @@ -74,8 +74,9 @@ using FAnyMoveConstructFunc = void(*)(void*, void*); template void AnyCopyAssign(void* Target, const void* Source) { - if constexpr (!TIsCopyAssignable::Value) check_no_entry(); - else *reinterpret_cast(Target) = *reinterpret_cast(Source); + if constexpr (TIsCopyAssignable::Value) *reinterpret_cast(Target) = *reinterpret_cast(Source); + else if constexpr (TIsCopyConstructible::Value) { AnyDestroy(Target); AnyCopyConstruct(Target, Source); } + else check_no_entry(); } using FAnyCopyAssignFunc = void(*)(void*, const void*); @@ -83,8 +84,9 @@ using FAnyCopyAssignFunc = void(*)(void*, const void*); template void AnyMoveAssign(void* Target, void* Source) { - if constexpr (!TIsMoveAssignable::Value) check_no_entry(); - else *reinterpret_cast(Target) = MoveTemp(*reinterpret_cast(Source)); + if constexpr (TIsMoveAssignable::Value) *reinterpret_cast(Target) = MoveTemp(*reinterpret_cast(Source)); + else if constexpr (TIsMoveConstructible::Value) { AnyDestroy(Target); AnyMoveConstruct(Target, Source); } + else check_no_entry(); } using FAnyMoveAssignFunc = void(*)(void*, void*); @@ -121,8 +123,8 @@ struct TAnyRTTIHelper NAMESPACE_PRIVATE_END -inline constexpr size_t ANY_DEFAULT_INLINE_SIZE = 64 - sizeof(FTypeInfo) - sizeof(const NAMESPACE_PRIVATE::FAnyRTTI*); -inline constexpr size_t ANY_DEFAULT_INLINE_ALIGNMENT = Memory::MINIMUM_ALIGNMENT; +inline constexpr size_t ANY_DEFAULT_INLINE_SIZE = 48; +inline constexpr size_t ANY_DEFAULT_INLINE_ALIGNMENT = 16; template struct TAny @@ -331,7 +333,7 @@ private: const NAMESPACE_PRIVATE::FAnyRTTI* RTTI; template - void EmplaceImpl(Types&&... Args) + FORCEINLINE void EmplaceImpl(Types&&... Args) { TypeInfo = Typeid(SelectedType);