From 39d12bd7e424b4a535af00a5e5f5d4fe454cbe3e Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Fri, 3 Jan 2025 01:10:04 +0800 Subject: [PATCH] refactor(templates): make TVariant conform to the style for general type identifiers --- .../Source/Public/Templates/Variant.h | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Templates/Variant.h b/Redcraft.Utility/Source/Public/Templates/Variant.h index 8682805..b656d7d 100644 --- a/Redcraft.Utility/Source/Public/Templates/Variant.h +++ b/Redcraft.Utility/Source/Public/Templates/Variant.h @@ -433,11 +433,11 @@ private: using FMoveAssignImpl = void(*)(void*, void*); using FDestroyImpl = void(*)(void* ); - static constexpr FCopyConstructImpl CopyConstructImpl[] = { [](void* A, const void* B) { if constexpr (requires(Ts* A, const Ts* B) { Memory::CopyConstruct (A, B); }) Memory::CopyConstruct (reinterpret_cast(A), reinterpret_cast(B)); else checkf(false, TEXT("The type '%s' is not copy constructible."), typeid(Ts).name()); }... }; - static constexpr FMoveConstructImpl MoveConstructImpl[] = { [](void* A, void* B) { if constexpr (requires(Ts* A, Ts* B) { Memory::MoveConstruct (A, B); }) Memory::MoveConstruct (reinterpret_cast(A), reinterpret_cast< Ts*>(B)); else checkf(false, TEXT("The type '%s' is not move constructible."), typeid(Ts).name()); }... }; - static constexpr FCopyAssignImpl CopyAssignImpl[] = { [](void* A, const void* B) { if constexpr (requires(Ts* A, const Ts* B) { Memory::CopyAssign (A, B); }) Memory::CopyAssign (reinterpret_cast(A), reinterpret_cast(B)); else checkf(false, TEXT("The type '%s' is not copy assignable."), typeid(Ts).name()); }... }; - static constexpr FMoveAssignImpl MoveAssignImpl[] = { [](void* A, void* B) { if constexpr (requires(Ts* A, Ts* B) { Memory::MoveAssign (A, B); }) Memory::MoveAssign (reinterpret_cast(A), reinterpret_cast< Ts*>(B)); else checkf(false, TEXT("The type '%s' is not move assignable."), typeid(Ts).name()); }... }; - static constexpr FDestroyImpl DestroyImpl[] = { [](void* A ) { if constexpr (requires(Ts* A ) { Memory::Destruct (A ); }) Memory::Destruct (reinterpret_cast(A) ); else checkf(false, TEXT("The type '%s' is not destructible."), typeid(Ts).name()); }... }; + static constexpr FCopyConstructImpl CopyConstructImpl[] = { [](void* A, const void* B) { if constexpr (requires(Ts* A, const Ts* B) { Memory::CopyConstruct (A, B); }) Memory::CopyConstruct (static_cast(A), static_cast(B)); else checkf(false, TEXT("The type '%s' is not copy constructible."), typeid(Ts).name()); }... }; + static constexpr FMoveConstructImpl MoveConstructImpl[] = { [](void* A, void* B) { if constexpr (requires(Ts* A, Ts* B) { Memory::MoveConstruct (A, B); }) Memory::MoveConstruct (static_cast(A), static_cast< Ts*>(B)); else checkf(false, TEXT("The type '%s' is not move constructible."), typeid(Ts).name()); }... }; + static constexpr FCopyAssignImpl CopyAssignImpl[] = { [](void* A, const void* B) { if constexpr (requires(Ts* A, const Ts* B) { Memory::CopyAssign (A, B); }) Memory::CopyAssign (static_cast(A), static_cast(B)); else checkf(false, TEXT("The type '%s' is not copy assignable."), typeid(Ts).name()); }... }; + static constexpr FMoveAssignImpl MoveAssignImpl[] = { [](void* A, void* B) { if constexpr (requires(Ts* A, Ts* B) { Memory::MoveAssign (A, B); }) Memory::MoveAssign (static_cast(A), static_cast< Ts*>(B)); else checkf(false, TEXT("The type '%s' is not move assignable."), typeid(Ts).name()); }... }; + static constexpr FDestroyImpl DestroyImpl[] = { [](void* A ) { if constexpr (requires(Ts* A ) { Memory::Destruct (A ); }) Memory::Destruct (static_cast(A) ); else checkf(false, TEXT("The type '%s' is not destructible."), typeid(Ts).name()); }... }; TAlignedUnion<1, Ts...> Value; uint8 TypeIndex; @@ -502,10 +502,10 @@ struct TVariantVisitImpl }; template - struct FInvokeEncoded; + struct TInvokeEncoded; template - struct FInvokeEncoded> + struct TInvokeEncoded> { FORCEINLINE static constexpr decltype(auto) Do(F&& Func, VariantTypes&&... Variants) { @@ -513,7 +513,7 @@ struct TVariantVisitImpl } template - struct FResult + struct TResult { FORCEINLINE static constexpr Ret Do(F&& Func, VariantTypes&&... Variants) { @@ -523,26 +523,26 @@ struct TVariantVisitImpl }; template - struct FInvokeVariant; + struct TInvokeVariant; template - struct FInvokeVariant> + struct TInvokeVariant> { FORCEINLINE static constexpr decltype(auto) Do(F&& Func, VariantTypes&&... Variants) { using FExtentIndices = TIndexSequenceFor; - using FResultType = TCommonType::Do(Forward(Func), Forward(Variants)...))...>; + using FResultType = TCommonReference::Do(Forward(Func), Forward(Variants)...))...>; using FInvokeImplType = FResultType(*)(F&&, VariantTypes&&...); - constexpr FInvokeImplType InvokeImpl[] = { FInvokeEncoded::template FResult::Do... }; + constexpr FInvokeImplType InvokeImpl[] = { TInvokeEncoded::template TResult::Do... }; return InvokeImpl[FEncodeIndices::Do({ Variants.GetIndex()... })](Forward(Func), Forward(Variants)...); } template - struct FResult + struct TResult { FORCEINLINE static constexpr Ret Do(F&& Func, VariantTypes&&... Variants) { @@ -550,7 +550,7 @@ struct TVariantVisitImpl using FInvokeImplType = Ret(*)(F&&, VariantTypes&&...); - constexpr FInvokeImplType InvokeImpl[] = { FInvokeEncoded::template FResult::Do... }; + constexpr FInvokeImplType InvokeImpl[] = { TInvokeEncoded::template TResult::Do... }; return InvokeImpl[FEncodeIndices::Do({ Variants.GetIndex()... })](Forward(Func), Forward(Variants)...); } @@ -559,15 +559,15 @@ struct TVariantVisitImpl FORCEINLINE static constexpr decltype(auto) Do(F&& Func, VariantTypes&&... Variants) { - return FInvokeVariant>::Do(Forward(Func), Forward(Variants)...); + return TInvokeVariant>::Do(Forward(Func), Forward(Variants)...); } template - struct FResult + struct TResult { FORCEINLINE static constexpr Ret Do(F&& Func, VariantTypes&&... Variants) { - return FInvokeVariant>::template FResult::Do(Forward(Func), Forward(Variants)...); + return TInvokeVariant>::template TResult::Do(Forward(Func), Forward(Variants)...); } }; }; @@ -589,7 +589,7 @@ template ::template FResult::Do(Forward(Func), Forward(FirstVariant), Forward(Variants)...); + return NAMESPACE_PRIVATE::TVariantVisitImpl::template TResult::Do(Forward(Func), Forward(FirstVariant), Forward(Variants)...); } NAMESPACE_MODULE_END(Utility)