AK: Allow testing Empty instances for equality

This also makes it possible to compare `Variant<Empty, Ts...>`
objects if operator== exists for all Ts
This commit is contained in:
Shannon Booth 2023-07-27 22:14:56 +12:00 committed by Ali Mohammad Pur
parent 4f9f21e8fe
commit bf7af25a82
Notes: sideshowbarker 2024-07-16 23:34:49 +09:00
2 changed files with 30 additions and 0 deletions

View file

@ -217,6 +217,7 @@ using MergeAndDeduplicatePacks = InheritFromPacks<MakeIndexSequence<sizeof...(Ps
namespace AK {
struct Empty {
constexpr bool operator==(Empty const&) const = default;
};
template<typename T>

View file

@ -273,3 +273,32 @@ TEST_CASE(type_list_specialization)
EXPECT((IsSame<typename MyList::template Type<1>, int>));
EXPECT((IsSame<typename MyList::template Type<2>, String>));
}
TEST_CASE(variant_equality)
{
using MyVariant = Variant<Empty, int, float>;
{
MyVariant variant1 = 1;
MyVariant variant2 = 1;
EXPECT_EQ(variant1, variant2);
}
{
MyVariant variant1 = 1;
MyVariant variant2 = 1.5f;
EXPECT_NE(variant1, variant2);
}
{
MyVariant variant1 = 1;
MyVariant variant2;
EXPECT_NE(variant1, variant2);
}
{
MyVariant variant1;
MyVariant variant2;
EXPECT_EQ(variant1, variant2);
}
}