From c70d22c85bf86dc2eaa118dd8b98606267eecaef Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Thu, 3 Feb 2022 21:18:19 +0800 Subject: [PATCH] fix(typetraits): fix compile errors caused by TCommonType and TCommonReference when there is no matching type --- .../Private/Testing/TypeTraitsTesting.cpp | 18 +++++++----- .../Source/Public/TypeTraits/Common.h | 29 +++++++++++++++++++ .../Source/Public/TypeTraits/Miscellaneous.h | 2 -- .../Source/Public/TypeTraits/TypeTraits.h | 1 + 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 Redcraft.Utility/Source/Public/TypeTraits/Common.h diff --git a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp index 30c846a..5cd928b 100644 --- a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp @@ -413,14 +413,6 @@ void TestTypeTraits() always_check((TIsSame::Type>::Value)); always_check((TIsSame::Type>::Value)); - always_check((TIsSame::Type>::Value)); - always_check((TIsSame::Type>::Value)); - always_check((TIsSame::Type>::Value)); - - always_check((TIsSame::Type>::Value)); - always_check((TIsSame::Type>::Value)); - always_check((TIsSame::Type>::Value)); - always_check((TIsSame::Type>::Value)); always_check((TIsSame::Type>::Value)); always_check((TIsSame::Type>::Value)); @@ -433,6 +425,16 @@ void TestTypeTraits() always_check((TIsSame::Type>::Value)); always_check((TIsSame::Type>::Value)); + // Common.h + + always_check((TIsSame::Type>::Value)); + always_check((TIsSame::Type>::Value)); + always_check((TIsSame::Type>::Value)); + + always_check((TIsSame::Type>::Value)); + always_check((TIsSame::Type>::Value)); + always_check((TIsSame::Type>::Value)); + } NAMESPACE_MODULE_END(Utility) diff --git a/Redcraft.Utility/Source/Public/TypeTraits/Common.h b/Redcraft.Utility/Source/Public/TypeTraits/Common.h new file mode 100644 index 0000000..80778a6 --- /dev/null +++ b/Redcraft.Utility/Source/Public/TypeTraits/Common.h @@ -0,0 +1,29 @@ +#pragma once + +#include "CoreTypes.h" +#include "TypeTraits/HelperClasses.h" + +#include + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +NAMESPACE_PRIVATE_BEGIN + +struct FNoopStruct { }; + +template concept CCommonType = requires { typename NAMESPACE_STD::common_type_t; }; +template concept CCommonReference = requires { typename NAMESPACE_STD::common_reference_t; }; + +template struct TCommonType { using Type = NAMESPACE_STD::common_type_t; }; +template struct TCommonReference { using Type = NAMESPACE_STD::common_reference_t; }; + +NAMESPACE_PRIVATE_END + +template struct TCommonType : TConditional, NAMESPACE_PRIVATE::TCommonType, NAMESPACE_PRIVATE::FNoopStruct>::Type { }; +template struct TCommonReference : TConditional, NAMESPACE_PRIVATE::TCommonReference, NAMESPACE_PRIVATE::FNoopStruct>::Type { }; + +NAMESPACE_MODULE_END(Utility) +NAMESPACE_MODULE_END(Redcraft) +NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h b/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h index a51a471..32b64b8 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h @@ -50,8 +50,6 @@ template struct TAlignedUnion { using Type = template struct TDecay { using Type = NAMESPACE_STD::decay_t; }; template struct TEnableIf { using Type = NAMESPACE_STD::enable_if_t; }; template struct TConditional { using Type = NAMESPACE_STD::conditional_t; }; -template struct TCommonType { using Type = NAMESPACE_STD::common_type_t; }; -template struct TCommonReference { using Type = NAMESPACE_STD::common_reference_t; }; template struct TUnderlyingType { using Type = NAMESPACE_STD::underlying_type_t; }; template struct TInvokeResult { using Type = NAMESPACE_STD::invoke_result_t; }; // FIXME: The result for char(&())[2] is wrong on MSVC template struct TVoid { using Type = void; }; diff --git a/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h b/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h index c925295..7831cde 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h @@ -7,3 +7,4 @@ #include "TypeTraits/TypeProperties.h" #include "TypeTraits/SupportedOperations.h" #include "TypeTraits/Miscellaneous.h" +#include "TypeTraits/Common.h"