From ca677697965c1c3dd95c597e10cf2c632f9692e4 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Tue, 13 Dec 2022 22:11:10 +0800 Subject: [PATCH] refactor(templates): do not allow TReferenceWrapper to rebind a new object --- .../Source/Public/Templates/ReferenceWrapper.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h index 1d20d18..70f8114 100644 --- a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h +++ b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h @@ -25,20 +25,18 @@ public: } FORCEINLINE constexpr TReferenceWrapper(const TReferenceWrapper&) = default; + FORCEINLINE constexpr TReferenceWrapper(TReferenceWrapper&&) = default; template requires (CConvertibleTo) FORCEINLINE constexpr TReferenceWrapper(const TReferenceWrapper& InValue) : Pointer(InValue.Pointer) { } - FORCEINLINE constexpr TReferenceWrapper& operator=(const TReferenceWrapper&) = default; - - template requires (CConvertibleTo) - FORCEINLINE constexpr TReferenceWrapper& operator=(const TReferenceWrapper& InValue) - { - Pointer = InValue.Pointer; - return *this; - } + template requires (CAssignableFrom) + FORCEINLINE constexpr TReferenceWrapper& operator=(T&& Object) { Get() = Forward(Object); return *this; } + + FORCEINLINE constexpr TReferenceWrapper& operator=(const TReferenceWrapper&) = delete; + FORCEINLINE constexpr TReferenceWrapper& operator=(TReferenceWrapper&&) = delete; FORCEINLINE constexpr operator ReferencedType&() const { return *Pointer; } FORCEINLINE constexpr ReferencedType& Get() const { return *Pointer; }