From c9b1f6f516c445734e932a51def14197e837f4f9 Mon Sep 17 00:00:00 2001 From: Mateusz Karbowiak <69864511+mtszkarbowiak@users.noreply.github.com> Date: Sun, 6 Oct 2024 01:57:12 +0200 Subject: [PATCH] `Nullable` fixes --- Source/Engine/Core/Types/Nullable.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Core/Types/Nullable.h b/Source/Engine/Core/Types/Nullable.h index 655233b85..0cf4b4361 100644 --- a/Source/Engine/Core/Types/Nullable.h +++ b/Source/Engine/Core/Types/Nullable.h @@ -79,12 +79,11 @@ public: /// The wrapped value to be moved. Nullable(Nullable&& other) noexcept { - _hasValue = other._hasValue; - - if (_hasValue) + if (other._hasValue) { new (&_value) T(MoveTemp(other._value)); // Placement new (move constructor) } + _hasValue = other._hasValue; other.Reset(); } @@ -194,10 +193,10 @@ public: } /// - /// Gets an instance of the wrapped value or a default value based on r-value reference, if the wrapped value is not valid. + /// Gets a mutable reference to the wrapped value or a default value if the value is not valid. /// - /// Copy of the wrapped value or the default value. - FORCE_INLINE T GetValueOr(T&& defaultValue) const noexcept + /// Reference to the wrapped value or the default value. + FORCE_INLINE T& GetValueOr(T& defaultValue) const { return _hasValue ? _value : defaultValue; } @@ -266,8 +265,8 @@ public: /// FORCE_INLINE void Reset() { + _hasValue = false; // Reset the flag BEFORE the value is (potentially) destructed. KillOld(); - _hasValue = false; // Reset the flag AFTER the value is (potentially) destructed. } ///