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>
|
2022-05-22 14:52:47 +00:00
|
|
|
constexpr TRemoveReference<T>&& MoveTemp(T&& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-11-15 14:15:10 +00:00
|
|
|
using CastType = TRemoveReference<T>;
|
|
|
|
return static_cast<CastType&&>(Obj);
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-11-15 14:15:10 +00:00
|
|
|
constexpr T CopyTemp(T& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-11-15 14:15:10 +00:00
|
|
|
return const_cast<const T&>(Obj);
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-11-15 14:15:10 +00:00
|
|
|
constexpr T CopyTemp(const T& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-11-15 14:15:10 +00:00
|
|
|
return Obj;
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-11-15 14:15:10 +00:00
|
|
|
constexpr T&& CopyTemp(T&& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-11-15 14:15:10 +00:00
|
|
|
return MoveTemp(Obj);
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-05-22 14:52:47 +00:00
|
|
|
constexpr T&& Forward(TRemoveReference<T>& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-11-15 14:15:10 +00:00
|
|
|
return static_cast<T&&>(Obj);
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-05-22 14:52:47 +00:00
|
|
|
constexpr T&& Forward(TRemoveReference<T>&& Obj)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-11-15 14:15:10 +00:00
|
|
|
return static_cast<T&&>(Obj);
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 14:03:54 +00:00
|
|
|
template <typename T> requires (requires(T& A, T& B) { A.Swap(B); }
|
|
|
|
|| (CMoveConstructible<T> && CMoveAssignable<T>))
|
2022-02-04 08:34:41 +00:00
|
|
|
constexpr void Swap(T& A, T& B)
|
2022-02-03 08:45:34 +00:00
|
|
|
{
|
2022-04-14 14:41:22 +00:00
|
|
|
if constexpr (requires(T& A, T& B) { A.Swap(B); })
|
|
|
|
{
|
|
|
|
A.Swap(B);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
T Temp = MoveTemp(A);
|
|
|
|
A = MoveTemp(B);
|
|
|
|
B = MoveTemp(Temp);
|
|
|
|
}
|
2022-02-03 08:45:34 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 14:03:54 +00:00
|
|
|
template <typename T, typename U = T> requires (CMoveConstructible<T> && CAssignableFrom<T&, U>)
|
2022-02-04 08:34:41 +00:00
|
|
|
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-11-21 14:04:17 +00:00
|
|
|
constexpr TAddRValueReference<T> DeclVal();
|
2022-02-03 08:45:34 +00:00
|
|
|
|
2022-11-16 14:03:54 +00:00
|
|
|
template <typename T> requires (CObject<T>)
|
2022-02-09 09:07:47 +00:00
|
|
|
constexpr T* AddressOf(T& Object)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char&>(Object)));
|
|
|
|
}
|
|
|
|
|
2022-05-15 15:10:02 +00:00
|
|
|
template <typename T> requires (!CObject<T>)
|
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-11-21 15:28:19 +00:00
|
|
|
// This macro is used in place of using type aliases, see Atomic.h, etc
|
|
|
|
#define STRONG_INHERIT(...) /* BaseClass */ \
|
|
|
|
/* struct DerivedClass : */ public __VA_ARGS__ \
|
|
|
|
{ \
|
|
|
|
private: \
|
|
|
|
\
|
|
|
|
using BaseClassTypedef = __VA_ARGS__; \
|
|
|
|
\
|
|
|
|
public: \
|
|
|
|
\
|
|
|
|
using BaseClassTypedef::BaseClassTypedef; \
|
|
|
|
using BaseClassTypedef::operator=; \
|
|
|
|
\
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:45:34 +00:00
|
|
|
NAMESPACE_MODULE_END(Utility)
|
|
|
|
NAMESPACE_MODULE_END(Redcraft)
|
|
|
|
NAMESPACE_REDCRAFT_END
|