AK: Allow Variant::downcast<OtherVariantType>()

We usually give type aliases to variants, so their variant types are not
always available, so make it possible to downcast to another variant
type.
This commit is contained in:
Ali Mohammad Pur 2022-11-10 12:42:19 +03:30 committed by Ali Mohammad Pur
commit 40b07901ac
Notes: sideshowbarker 2024-07-17 04:38:07 +09:00
2 changed files with 43 additions and 16 deletions

View file

@ -125,6 +125,13 @@ TEST_CASE(verify_cast)
EXPECT(one_integer_to_rule_them_all.has<i8>());
EXPECT_EQ(fake_integer.get<i8>(), 60);
EXPECT_EQ(one_integer_to_rule_them_all.get<i8>(), 60);
using SomeFancyType = Variant<i8, i16>;
one_integer_to_rule_them_all = fake_integer.downcast<SomeFancyType>();
EXPECT(fake_integer.has<i8>());
EXPECT(one_integer_to_rule_them_all.has<i8>());
EXPECT_EQ(fake_integer.get<i8>(), 60);
EXPECT_EQ(one_integer_to_rule_them_all.get<i8>(), 60);
}
TEST_CASE(moved_from_state)