fix(typetraits): fix compile errors caused by TCommonType and TCommonReference when there is no matching type
This commit is contained in:
parent
172a92edfe
commit
c70d22c85b
@ -413,14 +413,6 @@ void TestTypeTraits()
|
||||
always_check((TIsSame<int32, TConditional<true, int32, int64>::Type>::Value));
|
||||
always_check((TIsSame<int64, TConditional<false, int32, int64>::Type>::Value));
|
||||
|
||||
always_check((TIsSame<int32, TCommonType<int8, int32>::Type>::Value));
|
||||
always_check((TIsSame<int64, TCommonType<int8, int32, int64>::Type>::Value));
|
||||
always_check((TIsSame<double, TCommonType<float, double>::Type>::Value));
|
||||
|
||||
always_check((TIsSame<int32, TCommonReference<int8, int32>::Type>::Value));
|
||||
always_check((TIsSame<int64, TCommonReference<int8, int32, int64>::Type>::Value));
|
||||
always_check((TIsSame<double, TCommonReference<float, double>::Type>::Value));
|
||||
|
||||
always_check((TIsSame<int, TUnderlyingType<ETestEnumClass>::Type>::Value));
|
||||
always_check((TIsSame<uint8, TUnderlyingType<ETestEnumClass8>::Type>::Value));
|
||||
always_check((TIsSame<uint32, TUnderlyingType<ETestEnumClass32>::Type>::Value));
|
||||
@ -433,6 +425,16 @@ void TestTypeTraits()
|
||||
always_check((TIsSame<void, TVoid<int32>::Type>::Value));
|
||||
always_check((TIsSame<void, TVoid<int32, int64>::Type>::Value));
|
||||
|
||||
// Common.h
|
||||
|
||||
always_check((TIsSame<int32, TCommonType<int8, int32>::Type>::Value));
|
||||
always_check((TIsSame<int64, TCommonType<int8, int32, int64>::Type>::Value));
|
||||
always_check((TIsSame<double, TCommonType<float, double>::Type>::Value));
|
||||
|
||||
always_check((TIsSame<int32, TCommonReference<int8, int32>::Type>::Value));
|
||||
always_check((TIsSame<int64, TCommonReference<int8, int32, int64>::Type>::Value));
|
||||
always_check((TIsSame<double, TCommonReference<float, double>::Type>::Value));
|
||||
|
||||
}
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
|
29
Redcraft.Utility/Source/Public/TypeTraits/Common.h
Normal file
29
Redcraft.Utility/Source/Public/TypeTraits/Common.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "TypeTraits/HelperClasses.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
NAMESPACE_PRIVATE_BEGIN
|
||||
|
||||
struct FNoopStruct { };
|
||||
|
||||
template <typename... Types> concept CCommonType = requires { typename NAMESPACE_STD::common_type_t<Types...>; };
|
||||
template <typename... Types> concept CCommonReference = requires { typename NAMESPACE_STD::common_reference_t<Types...>; };
|
||||
|
||||
template <typename... Types> struct TCommonType { using Type = NAMESPACE_STD::common_type_t<Types...>; };
|
||||
template <typename... Types> struct TCommonReference { using Type = NAMESPACE_STD::common_reference_t<Types...>; };
|
||||
|
||||
NAMESPACE_PRIVATE_END
|
||||
|
||||
template <typename... Types> struct TCommonType : TConditional<NAMESPACE_PRIVATE::CCommonType<Types...>, NAMESPACE_PRIVATE::TCommonType<Types...>, NAMESPACE_PRIVATE::FNoopStruct>::Type { };
|
||||
template <typename... Types> struct TCommonReference : TConditional<NAMESPACE_PRIVATE::CCommonReference<Types...>, NAMESPACE_PRIVATE::TCommonReference<Types...>, NAMESPACE_PRIVATE::FNoopStruct>::Type { };
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
@ -50,8 +50,6 @@ template <size_t Size, typename... Types> struct TAlignedUnion { using Type =
|
||||
template <typename T> struct TDecay { using Type = NAMESPACE_STD::decay_t<T>; };
|
||||
template <bool B, typename T = void> struct TEnableIf { using Type = NAMESPACE_STD::enable_if_t<B, T>; };
|
||||
template <bool B, typename T, typename F> struct TConditional { using Type = NAMESPACE_STD::conditional_t<B, T, F>; };
|
||||
template <typename... Types> struct TCommonType { using Type = NAMESPACE_STD::common_type_t<Types...>; };
|
||||
template <typename... Types> struct TCommonReference { using Type = NAMESPACE_STD::common_reference_t<Types...>; };
|
||||
template <typename T> struct TUnderlyingType { using Type = NAMESPACE_STD::underlying_type_t<T>; };
|
||||
template <typename F, typename... Args> struct TInvokeResult { using Type = NAMESPACE_STD::invoke_result_t<F, Args...>; }; // FIXME: The result for char(&())[2] is wrong on MSVC
|
||||
template <typename... Types> struct TVoid { using Type = void; };
|
||||
|
@ -7,3 +7,4 @@
|
||||
#include "TypeTraits/TypeProperties.h"
|
||||
#include "TypeTraits/SupportedOperations.h"
|
||||
#include "TypeTraits/Miscellaneous.h"
|
||||
#include "TypeTraits/Common.h"
|
||||
|
Loading…
Reference in New Issue
Block a user