feat(typetraits): add TypeTraits/TypeProperties.h and the corresponding testing
This commit is contained in:
parent
29c01baf63
commit
7490dfae67
@ -3,6 +3,7 @@
|
||||
#include "TypeTraits/HelperClasses.h"
|
||||
#include "TypeTraits/PrimaryType.h"
|
||||
#include "TypeTraits/CompositeType.h"
|
||||
#include "TypeTraits/TypeProperties.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
@ -13,10 +14,16 @@ NAMESPACE_MODULE_BEGIN(Utility)
|
||||
int32 TestObject;
|
||||
void TestFunction() { }
|
||||
|
||||
struct FTestStruct { };
|
||||
struct FTestStructA { };
|
||||
struct FTestStructB { int32 Member; };
|
||||
struct FTestStructC { FTestStructC() { } };
|
||||
struct FTestStructD { FTestStructD(const FTestStructD&) { } };
|
||||
struct FTestStructE { virtual void Member() = 0; };
|
||||
struct FTestStructF { int32 MemberA; private: int32 MemberB; };
|
||||
struct FTestStructG { char MemberA; float MemberB; short MemberC; int MemberD; };
|
||||
struct FTestStructH final : FTestStructE { virtual void Member() override { } };
|
||||
|
||||
enum ETestEnum { };
|
||||
|
||||
enum class ETestEnumClass { };
|
||||
|
||||
union FTestUnion { };
|
||||
@ -81,61 +88,58 @@ void TestTypeTraits()
|
||||
always_check(!TypeTraits::TIsRValueReference<int32&>::Value);
|
||||
always_check(TypeTraits::TIsRValueReference<int32&&>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsMemberObjectPointer<int32(FTestStruct::*)>::Value);
|
||||
always_check(!TypeTraits::TIsMemberObjectPointer<int32(FTestStruct::*)()>::Value);
|
||||
always_check(TypeTraits::TIsMemberObjectPointer<int32(FTestStructA::*)>::Value);
|
||||
always_check(!TypeTraits::TIsMemberObjectPointer<int32(FTestStructA::*)()>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsMemberFunctionPointer<int32(FTestStruct::*)>::Value);
|
||||
always_check(TypeTraits::TIsMemberFunctionPointer<int32(FTestStruct::*)()>::Value);
|
||||
always_check(!TypeTraits::TIsMemberFunctionPointer<int32(FTestStructA::*)>::Value);
|
||||
always_check(TypeTraits::TIsMemberFunctionPointer<int32(FTestStructA::*)()>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsEnum<int32>::Value);
|
||||
always_check(!TypeTraits::TIsEnum<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsEnum<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsEnum<ETestEnum>::Value);
|
||||
always_check(TypeTraits::TIsEnum<ETestEnumClass>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsUnion<int32>::Value);
|
||||
always_check(!TypeTraits::TIsUnion<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsUnion<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsUnion<FTestUnion>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsUnion<int32>::Value);
|
||||
always_check(!TypeTraits::TIsUnion<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsUnion<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsUnion<FTestUnion>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsFunction<int32>::Value);
|
||||
always_check(!TypeTraits::TIsFunction<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsFunction<FTestStructA>::Value);
|
||||
always_check(!TypeTraits::TIsFunction<FTestUnion>::Value);
|
||||
always_check(TypeTraits::TIsFunction<int32(int32)>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsEnumClass<ETestEnum>::Value);
|
||||
always_check(TypeTraits::TIsEnumClass<ETestEnumClass>::Value);
|
||||
|
||||
// CompositeType.h
|
||||
|
||||
always_check(!TypeTraits::TIsFundamental<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsFundamental<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsFundamental<int32>::Value);
|
||||
always_check(TypeTraits::TIsFundamental<float>::Value);
|
||||
always_check(!TypeTraits::TIsFundamental<int32*>::Value);
|
||||
always_check(TypeTraits::TIsFundamental<void>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsArithmetic<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsArithmetic<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsArithmetic<int32>::Value);
|
||||
always_check(TypeTraits::TIsArithmetic<float>::Value);
|
||||
always_check(!TypeTraits::TIsArithmetic<int32*>::Value);
|
||||
always_check(!TypeTraits::TIsArithmetic<void>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsScalar<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsScalar<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsScalar<int32>::Value);
|
||||
always_check(TypeTraits::TIsScalar<float>::Value);
|
||||
always_check(TypeTraits::TIsScalar<int32*>::Value);
|
||||
always_check(!TypeTraits::TIsScalar<void>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsObject<FTestStruct>::Value);
|
||||
always_check(!TypeTraits::TIsObject<FTestStruct&>::Value);
|
||||
always_check(TypeTraits::TIsObject<FTestStructA>::Value);
|
||||
always_check(!TypeTraits::TIsObject<FTestStructA&>::Value);
|
||||
always_check(TypeTraits::TIsObject<int32>::Value);
|
||||
always_check(TypeTraits::TIsObject<int32*>::Value);
|
||||
always_check(!TypeTraits::TIsObject<int32&>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsCompound<FTestStruct>::Value);
|
||||
always_check(TypeTraits::TIsCompound<FTestStruct&>::Value);
|
||||
always_check(TypeTraits::TIsCompound<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsCompound<FTestStructA&>::Value);
|
||||
always_check(!TypeTraits::TIsCompound<int32>::Value);
|
||||
always_check(TypeTraits::TIsCompound<int32*>::Value);
|
||||
always_check(TypeTraits::TIsCompound<int32&>::Value);
|
||||
@ -145,8 +149,72 @@ void TestTypeTraits()
|
||||
always_check(TypeTraits::TIsReference<int32&>::Value);
|
||||
always_check(TypeTraits::TIsReference<int32&&>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsMemberPointer<FTestStruct>::Value);
|
||||
always_check(TypeTraits::TIsMemberPointer<int32(FTestStruct::*)>::Value);
|
||||
always_check(!TypeTraits::TIsMemberPointer<FTestStructA>::Value);
|
||||
always_check(TypeTraits::TIsMemberPointer<int32(FTestStructA::*)>::Value);
|
||||
|
||||
// TypeProperties.h
|
||||
|
||||
always_check(!TypeTraits::TIsConst<int32>::Value);
|
||||
always_check(TypeTraits::TIsConst<const int32>::Value);
|
||||
always_check(!TypeTraits::TIsConst<volatile int32>::Value);
|
||||
always_check(TypeTraits::TIsConst<const volatile int32>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsVolatile<int32>::Value);
|
||||
always_check(!TypeTraits::TIsVolatile<const int32>::Value);
|
||||
always_check(TypeTraits::TIsVolatile<volatile int32>::Value);
|
||||
always_check(TypeTraits::TIsVolatile<const volatile int32>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsTrivial<FTestStructB>::Value);
|
||||
always_check(!TypeTraits::TIsTrivial<FTestStructC>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsTriviallyCopyable<FTestStructB>::Value);
|
||||
always_check(!TypeTraits::TIsTriviallyCopyable<FTestStructD>::Value);
|
||||
always_check(!TypeTraits::TIsTriviallyCopyable<FTestStructE>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsStandardLayout<FTestStructB>::Value);
|
||||
always_check(!TypeTraits::TIsStandardLayout<FTestStructE>::Value);
|
||||
always_check(!TypeTraits::TIsStandardLayout<FTestStructF>::Value);
|
||||
|
||||
always_check(TypeTraits::THasUniqueObjectRepresentations<FTestStructF>::Value);
|
||||
always_check(!TypeTraits::THasUniqueObjectRepresentations<FTestStructG>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsEmpty<FTestStructA>::Value);
|
||||
always_check(!TypeTraits::TIsEmpty<FTestStructB>::Value);
|
||||
always_check(TypeTraits::TIsEmpty<FTestStructC>::Value);
|
||||
always_check(TypeTraits::TIsEmpty<FTestStructD>::Value);
|
||||
always_check(!TypeTraits::TIsEmpty<FTestStructE>::Value);
|
||||
always_check(!TypeTraits::TIsEmpty<FTestStructF>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsPolymorphic<FTestStructE>::Value);
|
||||
always_check(!TypeTraits::TIsPolymorphic<FTestStructF>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsAbstract<FTestStructE>::Value);
|
||||
always_check(!TypeTraits::TIsAbstract<FTestStructH>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsFinal<FTestStructE>::Value);
|
||||
always_check(TypeTraits::TIsFinal<FTestStructH>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsAggregate<int32>::Value);
|
||||
always_check(TypeTraits::TIsAggregate<int32[64]>::Value);
|
||||
always_check(TypeTraits::TIsAggregate<FTestStructB>::Value);
|
||||
always_check(!TypeTraits::TIsAggregate<FTestStructF>::Value);
|
||||
|
||||
always_check(TypeTraits::TIsSigned<signed>::Value);
|
||||
always_check(!TypeTraits::TIsSigned<unsigned>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsUnsigned<signed>::Value);
|
||||
always_check(TypeTraits::TIsUnsigned<unsigned>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsBoundedArray<int32>::Value);
|
||||
always_check(!TypeTraits::TIsBoundedArray<int32[]>::Value);
|
||||
always_check(TypeTraits::TIsBoundedArray<int32[64]>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsUnboundedArray<int32>::Value);
|
||||
always_check(TypeTraits::TIsUnboundedArray<int32[]>::Value);
|
||||
always_check(!TypeTraits::TIsUnboundedArray<int32[64]>::Value);
|
||||
|
||||
always_check(!TypeTraits::TIsScopedEnum<ETestEnum>::Value);
|
||||
always_check(TypeTraits::TIsScopedEnum<ETestEnumClass>::Value);
|
||||
}
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
|
@ -25,19 +25,6 @@ template <typename T> struct TIsUnion : TBoolConstant<NAMESPACE_
|
||||
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)
|
||||
|
45
Redcraft.Utility/Source/Public/TypeTraits/TypeProperties.h
Normal file
45
Redcraft.Utility/Source/Public/TypeTraits/TypeProperties.h
Normal file
@ -0,0 +1,45 @@
|
||||
#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 TIsConst : TBoolConstant<NAMESPACE_STD::is_const_v<T>> { };
|
||||
template <typename T> struct TIsVolatile : TBoolConstant<NAMESPACE_STD::is_volatile_v<T>> { };
|
||||
template <typename T> struct TIsTrivial : TBoolConstant<NAMESPACE_STD::is_trivial_v<T>> { };
|
||||
template <typename T> struct TIsTriviallyCopyable : TBoolConstant<NAMESPACE_STD::is_trivially_copyable_v<T>> { };
|
||||
template <typename T> struct TIsStandardLayout : TBoolConstant<NAMESPACE_STD::is_standard_layout_v<T>> { };
|
||||
template <typename T> struct THasUniqueObjectRepresentations : TBoolConstant<NAMESPACE_STD::has_unique_object_representations_v<T>> { };
|
||||
template <typename T> struct TIsEmpty : TBoolConstant<NAMESPACE_STD::is_empty_v<T>> { };
|
||||
template <typename T> struct TIsPolymorphic : TBoolConstant<NAMESPACE_STD::is_polymorphic_v<T>> { };
|
||||
template <typename T> struct TIsAbstract : TBoolConstant<NAMESPACE_STD::is_abstract_v<T>> { };
|
||||
template <typename T> struct TIsFinal : TBoolConstant<NAMESPACE_STD::is_final_v<T>> { };
|
||||
template <typename T> struct TIsAggregate : TBoolConstant<NAMESPACE_STD::is_aggregate_v<T>> { };
|
||||
template <typename T> struct TIsSigned : TBoolConstant<NAMESPACE_STD::is_signed_v<T>> { };
|
||||
template <typename T> struct TIsUnsigned : TBoolConstant<NAMESPACE_STD::is_unsigned_v<T>> { };
|
||||
template <typename T> struct TIsBoundedArray : TBoolConstant<NAMESPACE_STD::is_bounded_array_v<T>> { };
|
||||
template <typename T> struct TIsUnboundedArray : TBoolConstant<NAMESPACE_STD::is_unbounded_array_v<T>> { };
|
||||
|
||||
NAMESPACE_PRIVATE_BEGIN
|
||||
|
||||
char(&Resolve(int64))[2];
|
||||
char Resolve(...);
|
||||
|
||||
template <typename T>
|
||||
struct TIsEnumConvertibleToInt : TBoolConstant<sizeof(Resolve(T())) - 1> { };
|
||||
|
||||
NAMESPACE_PRIVATE_END
|
||||
|
||||
template <typename T>
|
||||
struct TIsScopedEnum : TBoolConstant<TAnd<TIsEnum<T>, TNot<NAMESPACE_PRIVATE::TIsEnumConvertibleToInt<T>>>::Value> { };
|
||||
|
||||
NAMESPACE_END(TypeTraits)
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
Loading…
Reference in New Issue
Block a user