mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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:
parent
4f9f21e8fe
commit
bf7af25a82
Notes:
sideshowbarker
2024-07-16 23:34:49 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/bf7af25a82 Pull-request: https://github.com/SerenityOS/serenity/pull/20219 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/alimpfard Reviewed-by: https://github.com/gmta
2 changed files with 30 additions and 0 deletions
|
@ -217,6 +217,7 @@ using MergeAndDeduplicatePacks = InheritFromPacks<MakeIndexSequence<sizeof...(Ps
|
|||
namespace AK {
|
||||
|
||||
struct Empty {
|
||||
constexpr bool operator==(Empty const&) const = default;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue