2022-02-03 08:45:34 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CoreTypes.h"
|
2022-03-26 11:31:45 +00:00
|
|
|
#include "TypeTraits/CompositeType.h"
|
|
|
|
#include "TypeTraits/Miscellaneous.h"
|
|
|
|
#include "TypeTraits/SupportedOperations.h"
|
2022-02-03 08:45:34 +00:00
|
|
|
|
|
|
|
NAMESPACE_REDCRAFT_BEGIN
|
|
|
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
|
|
|
NAMESPACE_MODULE_BEGIN(Utility)
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr const T& AsConst(T& Ref)
|
|
|
|
{
|
|
|
|
return Ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void AsConst(const T&& Ref) = delete;
|
|
|
|
|
|
|
|
template <typename T, size_t N>
|
|
|
|
constexpr const T(&AsConst(T(&Array)[N]))[N]
|
|
|
|
{
|
|
|
|
return Array;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-03-13 15:18:07 +00:00
|
|
|
constexpr typename TRemoveReference<T>::Type&& MoveTemp(T&& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
|
|
|
typedef typename TRemoveReference<T>::Type CastType;
|
|
|
|
return (CastType&&)Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-03-13 15:18:07 +00:00
|
|
|
constexpr T CopyTemp(T& Val)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
|
|
|
return const_cast<const T&>(Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-03-13 15:18:07 +00:00
|
|
|
constexpr T CopyTemp(const T& Val)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
|
|
|
return Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-03-13 15:18:07 +00:00
|
|
|
constexpr T&& CopyTemp(T&& Val)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
|
|
|
return MoveTemp(Val);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-03-13 15:18:07 +00:00
|
|
|
constexpr T&& Forward(typename TRemoveReference<T>::Type& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
|
|
|
return (T&&)Obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-03-13 15:18:07 +00:00
|
|
|
constexpr T&& Forward(typename TRemoveReference<T>::Type&& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
|
|
|
return (T&&)Obj;
|
|
|
|
}
|
|
|
|
|
2022-02-04 08:34:41 +00:00
|
|
|
template <typename T> requires TIsMoveConstructible<T>::Value && TIsMoveAssignable<T>::Value
|
|
|
|
constexpr void Swap(T& A, T& B)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
|
|
|
T Temp = MoveTemp(A);
|
|
|
|
A = MoveTemp(B);
|
|
|
|
B = MoveTemp(Temp);
|
|
|
|
}
|
|
|
|
|
2022-02-04 08:34:41 +00:00
|
|
|
template <typename T, typename U = T> requires TIsMoveConstructible<T>::Value && TIsAssignable<T&, U>::Value
|
|
|
|
constexpr T Exchange(T& A, U&& B)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-02-04 08:34:41 +00:00
|
|
|
T Temp = MoveTemp(A);
|
|
|
|
A = Forward<U>(B);
|
|
|
|
return Temp;
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-03-13 15:18:07 +00:00
|
|
|
constexpr T&& DeclVal();
|
2022-02-03 08:45:34 +00:00
|
|
|
|
2022-02-09 09:07:47 +00:00
|
|
|
template <typename T> requires TIsObject<T>::Value
|
|
|
|
constexpr T* AddressOf(T& Object)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char&>(Object)));
|
|
|
|
}
|
|
|
|
|
2022-03-13 15:18:07 +00:00
|
|
|
template <typename T> requires (!TIsObject<T>::Value)
|
2022-02-09 09:07:47 +00:00
|
|
|
constexpr T* AddressOf(T& Object)
|
|
|
|
{
|
|
|
|
return &Object;
|
|
|
|
}
|
|
|
|
|
2022-03-31 01:39:30 +00:00
|
|
|
struct FIgnore
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
constexpr void operator=(T&&) const { }
|
|
|
|
};
|
|
|
|
|
|
|
|
inline constexpr FIgnore Ignore;
|
|
|
|
|
2022-02-03 08:45:34 +00:00
|
|
|
NAMESPACE_MODULE_END(Utility)
|
|
|
|
NAMESPACE_MODULE_END(Redcraft)
|
|
|
|
NAMESPACE_REDCRAFT_END
|