refactor(typetraits): replaces template class type traits with concepts for TypeTraits/TypeProperties.h

This commit is contained in:
_Redstone_c_ 2022-05-15 23:22:49 +08:00
parent 22fe906eda
commit c316b8f190
6 changed files with 67 additions and 69 deletions

View File

@ -270,7 +270,7 @@ void TestVariant()
{
using T = decltype(Arg);
always_check(Arg == 10);
always_check(TIsConst<typename TRemoveReference<T>::Type>::Value == bIsConst);
always_check(CConst<typename TRemoveReference<T>::Type> == bIsConst);
always_check(CLValueReference<T> == bIsLValue);
always_check(CRValueReference<T> == bIsRValue);
return 0;

View File

@ -166,67 +166,67 @@ void TestTypeTraits()
// TypeProperties.h
always_check(!TIsConst<int32>::Value);
always_check(TIsConst<const int32>::Value);
always_check(!TIsConst<volatile int32>::Value);
always_check(TIsConst<const volatile int32>::Value);
always_check(!CConst<int32>);
always_check(CConst<const int32>);
always_check(!CConst<volatile int32>);
always_check(CConst<const volatile int32>);
always_check(!TIsVolatile<int32>::Value);
always_check(!TIsVolatile<const int32>::Value);
always_check(TIsVolatile<volatile int32>::Value);
always_check(TIsVolatile<const volatile int32>::Value);
always_check(!CVolatile<int32>);
always_check(!CVolatile<const int32>);
always_check(CVolatile<volatile int32>);
always_check(CVolatile<const volatile int32>);
always_check(TIsTrivial<FTestStructB>::Value);
always_check(!TIsTrivial<FTestStructC>::Value);
always_check(CTrivial<FTestStructB>);
always_check(!CTrivial<FTestStructC>);
always_check(TIsTriviallyCopyable<FTestStructB>::Value);
always_check(!TIsTriviallyCopyable<FTestStructD>::Value);
always_check(!TIsTriviallyCopyable<FTestStructE>::Value);
always_check(CTriviallyCopyable<FTestStructB>);
always_check(!CTriviallyCopyable<FTestStructD>);
always_check(!CTriviallyCopyable<FTestStructE>);
always_check(TIsStandardLayout<FTestStructB>::Value);
always_check(!TIsStandardLayout<FTestStructE>::Value);
always_check(!TIsStandardLayout<FTestStructF>::Value);
always_check(CStandardLayout<FTestStructB>);
always_check(!CStandardLayout<FTestStructE>);
always_check(!CStandardLayout<FTestStructF>);
always_check(THasUniqueObjectRepresentations<FTestStructF>::Value);
always_check(!THasUniqueObjectRepresentations<FTestStructG>::Value);
always_check(CUniqueObjectRepresentible<FTestStructF>);
always_check(!CUniqueObjectRepresentible<FTestStructG>);
always_check(TIsEmpty<FTestStructA>::Value);
always_check(!TIsEmpty<FTestStructB>::Value);
always_check(TIsEmpty<FTestStructC>::Value);
always_check(TIsEmpty<FTestStructD>::Value);
always_check(!TIsEmpty<FTestStructE>::Value);
always_check(!TIsEmpty<FTestStructF>::Value);
always_check(CEmpty<FTestStructA>);
always_check(!CEmpty<FTestStructB>);
always_check(CEmpty<FTestStructC>);
always_check(CEmpty<FTestStructD>);
always_check(!CEmpty<FTestStructE>);
always_check(!CEmpty<FTestStructF>);
always_check(TIsPolymorphic<FTestStructE>::Value);
always_check(!TIsPolymorphic<FTestStructF>::Value);
always_check(CPolymorphic<FTestStructE>);
always_check(!CPolymorphic<FTestStructF>);
always_check(TIsAbstract<FTestStructE>::Value);
always_check(!TIsAbstract<FTestStructH>::Value);
always_check(CAbstract<FTestStructE>);
always_check(!CAbstract<FTestStructH>);
always_check(!TIsFinal<FTestStructE>::Value);
always_check(TIsFinal<FTestStructH>::Value);
always_check(!CFinal<FTestStructE>);
always_check(CFinal<FTestStructH>);
always_check(!TIsAggregate<int32>::Value);
always_check(TIsAggregate<int32[64]>::Value);
always_check(TIsAggregate<FTestStructB>::Value);
always_check(!TIsAggregate<FTestStructF>::Value);
always_check(!CAggregate<int32>);
always_check(CAggregate<int32[64]>);
always_check(CAggregate<FTestStructB>);
always_check(!CAggregate<FTestStructF>);
always_check(TIsSigned<signed>::Value);
always_check(!TIsSigned<unsigned>::Value);
always_check(CSigned<signed>);
always_check(!CSigned<unsigned>);
always_check(!TIsUnsigned<signed>::Value);
always_check(TIsUnsigned<unsigned>::Value);
always_check(!CUnsigned<signed>);
always_check(CUnsigned<unsigned>);
always_check(!TIsBoundedArray<int32>::Value);
always_check(!TIsBoundedArray<int32[]>::Value);
always_check(TIsBoundedArray<int32[64]>::Value);
always_check(!CBoundedArray<int32>);
always_check(!CBoundedArray<int32[]>);
always_check(CBoundedArray<int32[64]>);
always_check(!TIsUnboundedArray<int32>::Value);
always_check(TIsUnboundedArray<int32[]>::Value);
always_check(!TIsUnboundedArray<int32[64]>::Value);
always_check(!CUnboundedArray<int32>);
always_check(CUnboundedArray<int32[]>);
always_check(!CUnboundedArray<int32[64]>);
always_check(!TIsScopedEnum<ETestEnum>::Value);
always_check(TIsScopedEnum<ETestEnumClass>::Value);
always_check(!CScopedEnum<ETestEnum>);
always_check(CScopedEnum<ETestEnumClass>);
// SupportedOperations.h

View File

@ -364,7 +364,7 @@ private:
TypeInfo = reinterpret_cast<uintptr>(&SelectedTypeInfo);
constexpr bool bIsInlineStorable = sizeof(SelectedType) <= InlineSize && alignof(SelectedType) <= InlineAlignment;
constexpr bool bIsTriviallyStorable = bIsInlineStorable && TIsTrivial<SelectedType>::Value && TIsTriviallyCopyable<SelectedType>::Value;
constexpr bool bIsTriviallyStorable = bIsInlineStorable && CTrivial<SelectedType> && CTriviallyCopyable<SelectedType>;
if constexpr (bIsTriviallyStorable)
{

View File

@ -51,7 +51,7 @@ NAMESPACE_PRIVATE_END
#endif
template <typename T, bool bIsRef = false> requires TIsTriviallyCopyable<T>::Value
template <typename T, bool bIsRef = false> requires CTriviallyCopyable<T>
&& TIsCopyConstructible<T>::Value && TIsMoveConstructible<T>::Value
&& TIsCopyAssignable<T>::Value && TIsMoveAssignable<T>::Value
struct TAtomic : public FSingleton

View File

@ -18,8 +18,8 @@ template <typename T> concept CScalar = NAMESPACE_STD::is_scalar_v<T>;
template <typename T> concept CCompound = NAMESPACE_STD::is_compound_v<T>;
template <typename T> concept CMemberPointer = NAMESPACE_STD::is_member_pointer_v<T>;
template <typename T> concept CSignedIntegral = CIntegral<T> && TIsSigned<T>::Value;
template <typename T> concept CUnsignedIntegral = CIntegral<T> && TIsUnsigned<T>::Value;
template <typename T> concept CSignedIntegral = CIntegral<T> && CSigned<T>;
template <typename T> concept CUnsignedIntegral = CIntegral<T> && CUnsigned<T>;
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)

View File

@ -10,24 +10,22 @@ NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft)
NAMESPACE_MODULE_BEGIN(Utility)
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>> { };
template <typename T>
struct TIsScopedEnum : TBoolConstant<CEnum<T> && !TIsConvertible<T, int64>::Value> { };
template <typename T> concept CConst = NAMESPACE_STD::is_const_v<T>;
template <typename T> concept CVolatile = NAMESPACE_STD::is_volatile_v<T>;
template <typename T> concept CTrivial = NAMESPACE_STD::is_trivial_v<T>;
template <typename T> concept CTriviallyCopyable = NAMESPACE_STD::is_trivially_copyable_v<T>;
template <typename T> concept CStandardLayout = NAMESPACE_STD::is_standard_layout_v<T>;
template <typename T> concept CUniqueObjectRepresentible = NAMESPACE_STD::has_unique_object_representations_v<T>;
template <typename T> concept CEmpty = NAMESPACE_STD::is_empty_v<T>;
template <typename T> concept CPolymorphic = NAMESPACE_STD::is_polymorphic_v<T>;
template <typename T> concept CAbstract = NAMESPACE_STD::is_abstract_v<T>;
template <typename T> concept CFinal = NAMESPACE_STD::is_final_v<T>;
template <typename T> concept CAggregate = NAMESPACE_STD::is_aggregate_v<T>;
template <typename T> concept CSigned = NAMESPACE_STD::is_signed_v<T>;
template <typename T> concept CUnsigned = NAMESPACE_STD::is_unsigned_v<T>;
template <typename T> concept CBoundedArray = NAMESPACE_STD::is_bounded_array_v<T>;
template <typename T> concept CUnboundedArray = NAMESPACE_STD::is_unbounded_array_v<T>;
template <typename T> concept CScopedEnum = CEnum<T> && !TIsConvertible<T, int64>::Value;
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)