From de059cb98034ca6b079585608a892831d5ab6e49 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Sun, 18 Dec 2022 19:28:33 +0800 Subject: [PATCH] fix(templates): disable TReferenceWrapper swap and enable it into FAny --- .../Source/Public/Templates/Any.h | 23 +++++++++++++++---- .../Public/Templates/ReferenceWrapper.h | 7 ------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Templates/Any.h b/Redcraft.Utility/Source/Public/Templates/Any.h index d063216..dfeb5ff 100644 --- a/Redcraft.Utility/Source/Public/Templates/Any.h +++ b/Redcraft.Utility/Source/Public/Templates/Any.h @@ -23,7 +23,7 @@ NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_PRIVATE_BEGIN template -concept CFAnyPlaceable = CDestructible> && CCopyConstructible> && CMoveConstructible> && CSwappable>; +concept CFAnyPlaceable = CDestructible> && CCopyConstructible> && CMoveConstructible>; NAMESPACE_PRIVATE_END @@ -314,10 +314,10 @@ public: case ERepresentation::Empty: break; case ERepresentation::Trivial: - uint8 Buffer[sizeof(TrivialStorage.Internal)]; - Memory::Memmove(Buffer, TrivialStorage.Internal); + uint8 TempBuffer[sizeof(TrivialStorage.Internal)]; + Memory::Memmove(TempBuffer, TrivialStorage.Internal); Memory::Memmove(TrivialStorage.Internal, InValue.TrivialStorage.Internal); - Memory::Memmove(InValue.TrivialStorage.Internal, Buffer); + Memory::Memmove(InValue.TrivialStorage.Internal, TempBuffer); break; case ERepresentation::Small: SmallStorage.RTTI->SwapObject(&SmallStorage.Internal, &InValue.SmallStorage.Internal); @@ -409,7 +409,20 @@ private: , SwapObject{ [](void* A, void* B) { - NAMESPACE_REDCRAFT::Swap(*reinterpret_cast(A), *reinterpret_cast(B)); + if constexpr (CSwappable) + { + NAMESPACE_REDCRAFT::Swap(*reinterpret_cast(A), *reinterpret_cast(B)); + } + else + { + TAlignedStorage TempBuffer; + new (&TempBuffer) T(MoveTemp(*reinterpret_cast(A))); + reinterpret_cast(A)->~T(); + new (A) T(MoveTemp(*reinterpret_cast(B))); + reinterpret_cast(B)->~T(); + new (B) T(MoveTemp(*reinterpret_cast(&TempBuffer))); + reinterpret_cast(&TempBuffer)->~T(); + } } } { } diff --git a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h index 07083e0..79f155e 100644 --- a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h +++ b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h @@ -52,13 +52,6 @@ public: return NAMESPACE_REDCRAFT::GetTypeHash(Get()); } - FORCEINLINE constexpr void Swap(TReferenceWrapper& InValue) - { - ReferencedType* Temp = Pointer; - Pointer = InValue.Pointer; - InValue.Pointer = Temp; - } - private: ReferencedType* Pointer;