feat(typetraits): add TypeTraits/PrimaryType.h and the corresponding testing
This commit is contained in:
13
Redcraft.Utility/Source/Public/Testing/TypeTraitsTesting.h
Normal file
13
Redcraft.Utility/Source/Public/Testing/TypeTraitsTesting.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
void REDCRAFTUTILITY_API TestTypeTraits();
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
52
Redcraft.Utility/Source/Public/TypeTraits/HelperClasses.h
Normal file
52
Redcraft.Utility/Source/Public/TypeTraits/HelperClasses.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
NAMESPACE_BEGIN(TypeTraits)
|
||||
|
||||
template <typename InType, InType InValue>
|
||||
struct TConstant
|
||||
{
|
||||
using Type = InType;
|
||||
static constexpr Type Value = InValue;
|
||||
constexpr operator Type() const { return Value; }
|
||||
constexpr Type operator()() const { return Value; }
|
||||
};
|
||||
|
||||
template <bool InValue>
|
||||
using TBoolConstant = TConstant<bool, InValue>;
|
||||
|
||||
template <int32 InValue>
|
||||
using TIntegralConstant = TConstant<int32, InValue>;
|
||||
|
||||
using FTrue = TBoolConstant<true>;
|
||||
using FFalse = TBoolConstant<false>;
|
||||
|
||||
template <typename... Types>
|
||||
struct TAnd;
|
||||
|
||||
template <typename LHS, typename... RHS>
|
||||
struct TAnd<LHS, RHS...> : TBoolConstant<LHS::Value&& TAnd<RHS...>::Value> { };
|
||||
|
||||
template <>
|
||||
struct TAnd<> : FTrue { };
|
||||
|
||||
template <typename... Types>
|
||||
struct TOr;
|
||||
|
||||
template <typename LHS, typename... RHS>
|
||||
struct TOr<LHS, RHS...> : TBoolConstant<LHS::Value || TOr<RHS...>::Value> { };
|
||||
|
||||
template <>
|
||||
struct TOr<> : FFalse { };
|
||||
|
||||
template <typename Type>
|
||||
struct TNot : TBoolConstant<!Type::Value> { };
|
||||
|
||||
NAMESPACE_END(TypeTraits)
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
44
Redcraft.Utility/Source/Public/TypeTraits/PrimaryType.h
Normal file
44
Redcraft.Utility/Source/Public/TypeTraits/PrimaryType.h
Normal file
@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "TypeTraits/HelperClasses.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
NAMESPACE_BEGIN(TypeTraits)
|
||||
|
||||
template <typename T> struct TIsVoid : TBoolConstant<NAMESPACE_STD::is_void_v<T>> { };
|
||||
template <typename T> struct TIsNullPointer : TBoolConstant<NAMESPACE_STD::is_null_pointer_v<T>> { };
|
||||
template <typename T> struct TIsIntegral : TBoolConstant<NAMESPACE_STD::is_integral_v<T>> { };
|
||||
template <typename T> struct TIsFloatingPoint : TBoolConstant<NAMESPACE_STD::is_floating_point_v<T>> { };
|
||||
template <typename T> struct TIsArray : TBoolConstant<NAMESPACE_STD::is_array_v<T>> { };
|
||||
template <typename T> struct TIsPointer : TBoolConstant<NAMESPACE_STD::is_pointer_v<T>> { };
|
||||
template <typename T> struct TIsLValueReference : TBoolConstant<NAMESPACE_STD::is_lvalue_reference_v<T>> { };
|
||||
template <typename T> struct TIsRValueReference : TBoolConstant<NAMESPACE_STD::is_rvalue_reference_v<T>> { };
|
||||
template <typename T> struct TIsMemberObjectPointer : TBoolConstant<NAMESPACE_STD::is_member_object_pointer_v<T>> { };
|
||||
template <typename T> struct TIsMemberFunctionPointer : TBoolConstant<NAMESPACE_STD::is_member_function_pointer_v<T>> { };
|
||||
template <typename T> struct TIsEnum : TBoolConstant<NAMESPACE_STD::is_enum_v<T>> { };
|
||||
template <typename T> struct TIsUnion : TBoolConstant<NAMESPACE_STD::is_union_v<T>> { };
|
||||
template <typename T> struct TIsClass : TBoolConstant<NAMESPACE_STD::is_class_v<T>> { };
|
||||
template <typename T> struct TIsFunction : TBoolConstant<NAMESPACE_STD::is_function_v<T>> { };
|
||||
|
||||
NAMESPACE_PRIVATE_BEGIN
|
||||
|
||||
static char(&Resolve(int))[2];
|
||||
static char Resolve(...);
|
||||
|
||||
template <typename T>
|
||||
struct TIsEnumConvertibleToInt : TBoolConstant<sizeof(Resolve(T())) - 1> { };
|
||||
|
||||
NAMESPACE_PRIVATE_END
|
||||
|
||||
template <typename T>
|
||||
struct TIsEnumClass : TBoolConstant<TAnd<TIsEnum<T>, TNot<NAMESPACE_PRIVATE::TIsEnumConvertibleToInt<T>>>::Value> { };
|
||||
|
||||
NAMESPACE_END(TypeTraits)
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
Reference in New Issue
Block a user