diff --git a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp index 17d48d4..bfcb3c7 100644 --- a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp @@ -180,8 +180,8 @@ void TestVariant() TVariant TempB(Invalid); TVariant TempC(InPlaceType, 0); TVariant TempD(0); - TVariant TempE(0l); - TVariant TempF(0.0); +// TVariant TempE(0ll); +// TVariant TempF(0.0); TVariant TempG(TempA); TVariant TempH(TempD); TVariant TempI(TVariant(0)); @@ -240,7 +240,13 @@ void TestVariant() Swap(TempW, TempX); Swap(TempW, TempX); } - + + { +// TVariant TempA = false; +// TempA.Visit([](auto& A) { A = true; }); +// always_check(TempA.GetValue()); + } + { struct FTracker { diff --git a/Redcraft.Utility/Source/Public/Templates/Variant.h b/Redcraft.Utility/Source/Public/Templates/Variant.h index 0ef5a95..cc12518 100644 --- a/Redcraft.Utility/Source/Public/Templates/Variant.h +++ b/Redcraft.Utility/Source/Public/Templates/Variant.h @@ -43,39 +43,28 @@ struct TVariantAlternativeImpl> using Type = Meta::TType>; }; -template -struct TVariantSelectedType; - -template -struct TVariantSelectedType +template +struct TVariantOverloadType { - using TypeAlternativeA = TConditional, U, void>; - using TypeAlternativeB = typename TVariantSelectedType::Type; + using FrontType = Meta::TFront; + using NextSequence = Meta::TPop; + using NextUniqueSequence = typename TVariantOverloadType::Type; - using Type = TConditional, void>, TypeAlternativeB, - TConditional, void>, TypeAlternativeA, - TConditional, TRemoveCVRef>, TypeAlternativeB, TypeAlternativeA>>>; - - // 0 - Type not found - // 1 - Same type found - // 2 - Multiple types found - // 3 - The type found - static constexpr uint8 Flag = CSameAs, void> ? 0 : - CSameAs, TRemoveCVRef> ? 2 : - CSameAs, TRemoveCVRef< T>> ? 1 : - !CSameAs, void> && !CSameAs ? 2 : 3; - - static constexpr bool Value = Flag & 1; + // T_i x[] = { Forward(t) }; + static constexpr bool bConditional = requires { DeclVal()({ DeclVal() }); }; + using Type = TConditional, NextUniqueSequence>; }; template -struct TVariantSelectedType +struct TVariantOverloadType> { - static constexpr uint8 Flag = 0; - using Type = void; + using Type = TTypeSequence<>; }; +template +using TVariantSelectedType = Meta::TOverloadResolution>::Type>; + NAMESPACE_PRIVATE_END template @@ -129,10 +118,10 @@ public: : TVariant(InPlaceIndex>>, Forward(Args)...) { } - template requires (NAMESPACE_PRIVATE::TVariantSelectedType, Ts...>::Value + template requires (requires { typename NAMESPACE_PRIVATE::TVariantSelectedType; } && !CTInPlaceType> && !CTInPlaceIndex> && !CBaseOf>) - constexpr TVariant(T&& InValue) : TVariant(InPlaceType, Ts...>::Type>, Forward(InValue)) + constexpr TVariant(T&& InValue) : TVariant(InPlaceType>, Forward(InValue)) { } constexpr ~TVariant() requires (true && ... && CTriviallyDestructible) = default; @@ -190,10 +179,10 @@ public: return *this; } - template requires (NAMESPACE_PRIVATE::TVariantSelectedType, Ts...>::Value) + template requires (requires { typename NAMESPACE_PRIVATE::TVariantSelectedType; }) constexpr TVariant& operator=(T&& InValue) { - using SelectedType = typename NAMESPACE_PRIVATE::TVariantSelectedType, Ts...>::Type; + using SelectedType = NAMESPACE_PRIVATE::TVariantSelectedType; if (GetIndex() == TVariantIndex>) GetValue() = Forward(InValue); else