64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <Orange/Core/Types.h>
|
|
|
|
// Needed for placement new/delete.
|
|
#include <new>
|
|
|
|
namespace orange
|
|
{
|
|
struct FalseType { static constexpr bool Value = false; };
|
|
struct TrueType { static constexpr bool Value = true; };
|
|
|
|
template <typename T> struct IsLValueReference : FalseType {};
|
|
template <typename T> struct IsLValueReference<T&> : TrueType {};
|
|
|
|
template <typename T> struct RemoveReference_ { using Type = T; };
|
|
template <typename T> struct RemoveReference_<T&> { using Type = T; };
|
|
template <typename T> struct RemoveReference_<T&&> { using Type = T; };
|
|
|
|
template <typename T>
|
|
using RemoveReference = typename RemoveReference_<T>::Type;
|
|
|
|
template <typename T>
|
|
constexpr T&& Forward(RemoveReference<T>& t) { return static_cast<T&&>(t); }
|
|
|
|
template <typename T>
|
|
constexpr T&& Forward(RemoveReference<T>&& t)
|
|
{
|
|
static_assert(!IsLValueReference<T>::Value, "Can not forward an rvalue as an lvalue.");
|
|
return static_cast<T&&>(t);
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr RemoveReference<T>&& Move(T&& arg)
|
|
{
|
|
return static_cast<RemoveReference<T>&&>(arg);
|
|
}
|
|
|
|
template <typename T, size_t N>
|
|
[[nodiscard]] constexpr size_t Size(const T (&array)[N]) noexcept
|
|
{
|
|
(void)array;
|
|
return N;
|
|
}
|
|
|
|
template <typename T>
|
|
[[nodiscard]] constexpr T Min( const T& valMin, const T& valMax )
|
|
{
|
|
return valMin < valMax ? valMin : valMax;
|
|
}
|
|
|
|
template <typename T>
|
|
[[nodiscard]] constexpr T Max( const T& valMin, const T& valMax )
|
|
{
|
|
return valMin > valMax ? valMin : valMax;
|
|
}
|
|
|
|
template <typename T>
|
|
[[nodiscard]] constexpr T Clamp( const T& val, const T& minVal, const T& maxVal )
|
|
{
|
|
return Min( Max( val, minVal ), maxVal );
|
|
}
|
|
}
|