diff --git a/Redcraft.Utility/Source/Public/Templates/Function.h b/Redcraft.Utility/Source/Public/Templates/Function.h index 40482dd..939ad4f 100644 --- a/Redcraft.Utility/Source/Public/Templates/Function.h +++ b/Redcraft.Utility/Source/Public/Templates/Function.h @@ -267,7 +267,7 @@ public: { using DecayedFunctorType = typename TDecay::Type; EmplaceImpl(Forward(Args)...); - return *reinterpret_cast::Type*>(Target()); + return Target(); } FORCEINLINE ResultType operator()(Types... Args) requires (Specifiers == EFunctionSpecifiers::None ) { return CallImpl(Forward(Args)...); } @@ -280,10 +280,15 @@ public: constexpr bool IsValid() const { return Call != nullptr; } constexpr explicit operator bool() const { return Call != nullptr; } + FORCEINLINE void* GetData() { if constexpr (FunctionType != EFunctionType::Reference) return Storage.GetData(); else return Storage; } + FORCEINLINE const void* GetData() const { if constexpr (FunctionType != EFunctionType::Reference) return Storage.GetData(); else return Storage; } + FORCEINLINE const FTypeInfo& TargetType() const requires (FunctionType != EFunctionType::Reference) { return IsValid() ? Storage.GetTypeInfo() : Typeid(void); }; - FORCEINLINE void* Target() { if constexpr (FunctionType != EFunctionType::Reference) return Storage.GetData(); else return Storage; } - FORCEINLINE const void* Target() const { if constexpr (FunctionType != EFunctionType::Reference) return Storage.GetData(); else return Storage; } + template FORCEINLINE T& Target() & requires (FunctionType != EFunctionType::Reference) && TIsSame::Type>::Value && TIsObject::Type>::Value && (!TIsArray::Type>::Value) && TIsDestructible::Type>::Value { return static_cast< StorageType& >(Storage).template GetValue(); } + template FORCEINLINE T&& Target() && requires (FunctionType != EFunctionType::Reference) && TIsSame::Type>::Value && TIsObject::Type>::Value && (!TIsArray::Type>::Value) && TIsDestructible::Type>::Value { return static_cast< StorageType&&>(Storage).template GetValue(); } + template FORCEINLINE const T& Target() const& requires (FunctionType != EFunctionType::Reference) && TIsSame::Type>::Value && TIsObject::Type>::Value && (!TIsArray::Type>::Value) && TIsDestructible::Type>::Value { return static_cast(Storage).template GetValue(); } + template FORCEINLINE const T&& Target() const&& requires (FunctionType != EFunctionType::Reference) && TIsSame::Type>::Value && TIsObject::Type>::Value && (!TIsArray::Type>::Value) && TIsDestructible::Type>::Value { return static_cast(Storage).template GetValue(); } constexpr void Reset() requires (FunctionType != EFunctionType::Reference) { Call = nullptr; } @@ -306,7 +311,7 @@ private: FORCEINLINE ResultType CallImpl(Types&&... Args) const { checkf(IsValid(), TEXT("Attempting to call an unbound TFunction!")); - return Call(const_cast(*this).Target(), Forward(Args)...); + return Call(const_cast(*this).GetData(), Forward(Args)...); } FORCEINLINE void AssignImpl(const TFunctionImpl& InValue) @@ -338,37 +343,37 @@ struct TFunctionSelect; template struct TFunctionSelect { - using Type = NAMESPACE_PRIVATE::TFunctionImpl; + using Type = TFunctionImpl; }; template struct TFunctionSelect { - using Type = NAMESPACE_PRIVATE::TFunctionImpl; + using Type = TFunctionImpl; }; template struct TFunctionSelect { - using Type = NAMESPACE_PRIVATE::TFunctionImpl; + using Type = TFunctionImpl; }; template struct TFunctionSelect { - using Type = NAMESPACE_PRIVATE::TFunctionImpl; + using Type = TFunctionImpl; }; template struct TFunctionSelect { - using Type = NAMESPACE_PRIVATE::TFunctionImpl; + using Type = TFunctionImpl; }; template struct TFunctionSelect { - using Type = NAMESPACE_PRIVATE::TFunctionImpl; + using Type = TFunctionImpl; }; NAMESPACE_PRIVATE_END