feat(typetraits): add TypeTraits/TypeProperties.h and the corresponding testing

This commit is contained in:
2021-12-12 22:54:43 +08:00
parent 29c01baf63
commit 7490dfae67
3 changed files with 135 additions and 35 deletions

View File

@ -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)