mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-04 15:09:40 +00:00
AK: Introduce ability to default-initialize a Variant
I noticed that Variant<Empty, …> is a somewhat common pattern while working on #10080, and this will simplify a few use-cases. :^)
This commit is contained in:
parent
f261b68408
commit
743470c8f2
|
@ -210,7 +210,11 @@ public:
|
||||||
template<typename... NewTs>
|
template<typename... NewTs>
|
||||||
friend struct Variant;
|
friend struct Variant;
|
||||||
|
|
||||||
Variant() = delete;
|
Variant() requires(!can_contain<Empty>()) = delete;
|
||||||
|
Variant() requires(can_contain<Empty>())
|
||||||
|
: Variant(Empty())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef AK_HAS_CONDITIONALLY_TRIVIAL
|
#ifdef AK_HAS_CONDITIONALLY_TRIVIAL
|
||||||
Variant(const Variant&) requires(!(IsCopyConstructible<Ts> && ...)) = delete;
|
Variant(const Variant&) requires(!(IsCopyConstructible<Ts> && ...)) = delete;
|
||||||
|
|
|
@ -219,3 +219,10 @@ TEST_CASE(copy_assign)
|
||||||
EXPECT_EQ(the_value.get<String>(), "Hello, world!");
|
EXPECT_EQ(the_value.get<String>(), "Hello, world!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(default_empty)
|
||||||
|
{
|
||||||
|
Variant<Empty, int> my_variant;
|
||||||
|
EXPECT(my_variant.has<Empty>());
|
||||||
|
EXPECT(!my_variant.has<int>());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue