From c6620da1dd21f8545b41a03d594a7d4c35ca9b3b Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Sun, 22 May 2022 23:19:30 +0800 Subject: [PATCH] refactor(typetraits): replaces template class type traits with alias template for TypeTraits/CopyQualifiers.h --- .../Private/Testing/TypeTraitsTesting.cpp | 138 +++++++++--------- .../Source/Public/Templates/Function.h | 10 +- .../Source/Public/Templates/Tuple.h | 2 +- .../Source/Public/Templates/Variant.h | 2 +- .../Source/Public/TypeTraits/CopyQualifiers.h | 44 +++--- 5 files changed, 103 insertions(+), 93 deletions(-) diff --git a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp index 54083fe..7d4c8b8 100644 --- a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp @@ -480,81 +480,81 @@ void TestTypeTraits() // CopyQualifiers.h - always_check((CSameAs< int32, TCopyConst< int32, int32>::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); + always_check((CSameAs< int32, TCopyConst< int32, int32>>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); - always_check((CSameAs< int32, TCopyVolatile< int32, int32>::Type>)); - always_check((CSameAs< int32, TCopyVolatile::Type>)); - always_check((CSameAs< volatile int32, TCopyVolatile::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); + always_check((CSameAs< int32, TCopyVolatile< int32, int32>>)); + always_check((CSameAs< int32, TCopyVolatile>)); + always_check((CSameAs< volatile int32, TCopyVolatile>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); - always_check((CSameAs< int32, TCopyCV< int32, int32>::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); + always_check((CSameAs< int32, TCopyCV< int32, int32>>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); - always_check((CSameAs< int32, TCopyCVRef< int32, int32>::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs< volatile int32, TCopyCVRef< volatile int32, int32>::Type>)); - always_check((CSameAs< volatile int32, TCopyCVRef< int32, volatile int32>::Type>)); - always_check((CSameAs< volatile int32, TCopyCVRef< volatile int32, volatile int32>::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); + always_check((CSameAs< int32, TCopyCVRef< int32, int32>>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs< volatile int32, TCopyCVRef< volatile int32, int32>>)); + always_check((CSameAs< volatile int32, TCopyCVRef< int32, volatile int32>>)); + always_check((CSameAs< volatile int32, TCopyCVRef< volatile int32, volatile int32>>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); - always_check((CSameAs::Type>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); + always_check((CSameAs>)); // BooleanTestable.h diff --git a/Redcraft.Utility/Source/Public/Templates/Function.h b/Redcraft.Utility/Source/Public/Templates/Function.h index 0d3084c..91319ba 100644 --- a/Redcraft.Utility/Source/Public/Templates/Function.h +++ b/Redcraft.Utility/Source/Public/Templates/Function.h @@ -146,8 +146,8 @@ public: private: - using StorageType = TConditional::Type*, TAny>; - using StorageRef = TConditional::Type*, typename TCopyCVRef::Type&>; + using StorageType = TConditional*, TAny>; + using StorageRef = TConditional*, TCopyCVRef&>; using CallFunc = ResultType(*)(StorageRef, Types&&...); @@ -171,7 +171,7 @@ protected: template FORCEINLINE void EmplaceImpl(ArgTypes&&... Args) { - using CallableType = typename TCopyConst, DecayedType>::Type; + using CallableType = TCopyConst, DecayedType>; if constexpr (bIsRef) Storage = ((reinterpret_cast(AddressOf(Args))), ...); else Storage.template Emplace(Forward(Args)...); @@ -180,8 +180,8 @@ protected: { using InvokeType = TConditional< CReference, - typename TCopyCVRef::Type, - typename TCopyCVRef::Type& + TCopyCVRef, + TCopyCVRef& >; const auto GetFunc = [&Storage]() -> InvokeType diff --git a/Redcraft.Utility/Source/Public/Templates/Tuple.h b/Redcraft.Utility/Source/Public/Templates/Tuple.h index 42e13aa..1fde4b3 100644 --- a/Redcraft.Utility/Source/Public/Templates/Tuple.h +++ b/Redcraft.Utility/Source/Public/Templates/Tuple.h @@ -405,7 +405,7 @@ template requires CTTuple> struct TTupleElementSize : TConstant::ElementSize> { }; template requires CTTuple> -struct TTupleElementType { using Type = typename TCopyCVRef, typename TRemoveCVRef::template TElementType::Type>::Type; }; +struct TTupleElementType { using Type = TCopyCVRef, typename TRemoveCVRef::template TElementType::Type>; }; template requires CTTuple> struct TTupleElementIndex : TupleType::template TElementIndex { }; diff --git a/Redcraft.Utility/Source/Public/Templates/Variant.h b/Redcraft.Utility/Source/Public/Templates/Variant.h index 07ae9f8..9d17c6a 100644 --- a/Redcraft.Utility/Source/Public/Templates/Variant.h +++ b/Redcraft.Utility/Source/Public/Templates/Variant.h @@ -422,7 +422,7 @@ template requires CTVariant> struct TVariantAlternativeSize : TConstant { }; template requires CTVariant> -struct TVariantAlternativeType { using Type = typename TCopyCV, typename TRemoveCVRef::template TAlternativeType::Type>::Type; }; +struct TVariantAlternativeType { using Type = TCopyCV, typename TRemoveCVRef::template TAlternativeType::Type>; }; template requires CTVariant> struct TVariantAlternativeIndex : VariantType::template TAlternativeIndex { }; diff --git a/Redcraft.Utility/Source/Public/TypeTraits/CopyQualifiers.h b/Redcraft.Utility/Source/Public/TypeTraits/CopyQualifiers.h index 588082b..de59fbd 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/CopyQualifiers.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/CopyQualifiers.h @@ -9,27 +9,37 @@ NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Utility) -template struct TCopyConst { using Type = To; }; -template struct TCopyConst { using Type = const To; }; +NAMESPACE_PRIVATE_BEGIN -template struct TCopyVolatile { using Type = To; }; -template struct TCopyVolatile { using Type = volatile To; }; +template struct TCopyConstImpl { using Type = To; }; +template struct TCopyConstImpl { using Type = const To; }; -template struct TCopyCV { using Type = typename TCopyConst::Type>::Type; }; +template struct TCopyVolatileImpl { using Type = To; }; +template struct TCopyVolatileImpl { using Type = volatile To; }; -template struct TCopyReference { using Type = To; }; -template struct TCopyReference { using Type = To&; }; -template struct TCopyReference { using Type = To&&; }; +template struct TCopyCVImpl { using Type = typename TCopyConstImpl::Type>::Type; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&&; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&&; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&; }; -template struct TCopyCVRef { using Type = typename TCopyCV::Type&&; }; +template struct TCopyReferenceImpl { using Type = To; }; +template struct TCopyReferenceImpl { using Type = To&; }; +template struct TCopyReferenceImpl { using Type = To&&; }; + +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&&; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&&; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&; }; +template struct TCopyCVRefImpl { using Type = typename TCopyCVImpl::Type&&; }; + +NAMESPACE_PRIVATE_END + +template using TCopyConst = typename NAMESPACE_PRIVATE::TCopyConstImpl::Type; +template using TCopyVolatile = typename NAMESPACE_PRIVATE::TCopyVolatileImpl::Type; +template using TCopyCV = typename NAMESPACE_PRIVATE::TCopyCVImpl::Type; +template using TCopyReference = typename NAMESPACE_PRIVATE::TCopyReferenceImpl::Type; +template using TCopyCVRef = typename NAMESPACE_PRIVATE::TCopyCVRefImpl::Type; NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft)