feat(typetraits): add TCommonReference and the corresponding testing

This commit is contained in:
_Redstone_c_ 2022-01-11 23:21:05 +08:00
parent 8baaa50335
commit a13b5832fc
2 changed files with 14 additions and 9 deletions

View File

@ -413,6 +413,10 @@ void TestTypeTraits()
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));

View File

@ -51,6 +51,7 @@ template <typename T> struct TDecay { using Type =
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; };