2022-02-09 13:46:39 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CoreTypes.h"
|
|
|
|
#include "Templates/Invoke.h"
|
|
|
|
#include "Templates/Utility.h"
|
|
|
|
#include "TypeTraits/TypeTraits.h"
|
|
|
|
|
|
|
|
NAMESPACE_REDCRAFT_BEGIN
|
|
|
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
|
|
|
NAMESPACE_MODULE_BEGIN(Utility)
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class TReferenceWrapper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using Type = T;
|
|
|
|
|
2022-03-04 14:53:24 +00:00
|
|
|
template <typename U> requires (!TIsSame<TReferenceWrapper, typename TRemoveCVRef<U>::Type>::Value)
|
2022-02-09 13:46:39 +00:00
|
|
|
constexpr TReferenceWrapper(U&& Object) : Ptr(AddressOf(Forward<U>(Object))) { }
|
|
|
|
|
|
|
|
TReferenceWrapper(const TReferenceWrapper&) = default;
|
|
|
|
TReferenceWrapper& operator=(const TReferenceWrapper& x) = default;
|
|
|
|
|
|
|
|
constexpr operator T&() const { return *Ptr; }
|
|
|
|
constexpr T& Get() const { return *Ptr; }
|
|
|
|
|
|
|
|
template <typename... Types>
|
|
|
|
constexpr TInvokeResult<T&, Types...>::Type operator()(Types&&... Args) const
|
|
|
|
{
|
|
|
|
return Invoke(Get(), Forward<Types>(Args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
T* Ptr;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
TReferenceWrapper(T&) -> TReferenceWrapper<T>;
|
|
|
|
|
2022-04-24 15:08:00 +00:00
|
|
|
template <typename T>
|
|
|
|
void Ref(const T&&) = delete;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr TReferenceWrapper<T> Ref(T& InValue)
|
|
|
|
{
|
|
|
|
return TReferenceWrapper<T>(InValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr TReferenceWrapper<T> Ref(TReferenceWrapper<T> InValue)
|
|
|
|
{
|
|
|
|
return Ref(InValue.Get());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr TReferenceWrapper<const T> Ref(const T& InValue)
|
|
|
|
{
|
|
|
|
return TReferenceWrapper<const T>(InValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr TReferenceWrapper<const T> Ref(TReferenceWrapper<T> InValue)
|
|
|
|
{
|
|
|
|
return Ref(InValue.Get());
|
|
|
|
}
|
|
|
|
|
2022-03-31 09:36:48 +00:00
|
|
|
template <typename T> struct TIsTReferenceWrapper : FFalse { };
|
|
|
|
template <typename T> struct TIsTReferenceWrapper<TReferenceWrapper<T>> : FTrue { };
|
|
|
|
|
2022-03-26 11:33:28 +00:00
|
|
|
template <typename T> struct TUnwrapReference { using Type = T; };
|
|
|
|
template <typename T> struct TUnwrapReference<TReferenceWrapper<T>> { using Type = T&; };
|
|
|
|
|
|
|
|
template <typename T> struct TUnwrapRefDecay { using Type = typename TUnwrapReference<typename TDecay<T>::Type>::Type; };
|
|
|
|
|
2022-02-09 13:46:39 +00:00
|
|
|
NAMESPACE_MODULE_END(Utility)
|
|
|
|
NAMESPACE_MODULE_END(Redcraft)
|
|
|
|
NAMESPACE_REDCRAFT_END
|