diff --git a/AK/Variant.h b/AK/Variant.h index ee423927a0..ed477b7bd4 100644 --- a/AK/Variant.h +++ b/AK/Variant.h @@ -226,7 +226,7 @@ template struct Variant : public Detail::MergeAndDeduplicatePacks>...> { public: - using IndexType = Conditional; // Note: size+1 reserved for internal value checks + using IndexType = Conditional<(sizeof...(Ts) < 255), u8, size_t>; // Note: size+1 reserved for internal value checks private: static constexpr IndexType invalid_index = sizeof...(Ts); @@ -518,6 +518,9 @@ private: IndexType m_index; }; +template +struct TypeList> : TypeList { }; + } #if USING_AK_GLOBALLY diff --git a/Tests/AK/TestVariant.cpp b/Tests/AK/TestVariant.cpp index 37bbf646cd..88a3e5fb7d 100644 --- a/Tests/AK/TestVariant.cpp +++ b/Tests/AK/TestVariant.cpp @@ -260,3 +260,16 @@ TEST_CASE(default_empty) EXPECT(my_variant.has()); EXPECT(!my_variant.has()); } + +TEST_CASE(type_list_specialization) +{ + EXPECT_EQ((TypeList>::size), 1u); + EXPECT_EQ((TypeList>::size), 2u); + EXPECT_EQ((TypeList>::size), 3u); + + using MyVariant = Variant; + using MyList = TypeList; + EXPECT((IsSame, Empty>)); + EXPECT((IsSame, int>)); + EXPECT((IsSame, String>)); +}