1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

AK: Make Variant::visit() prefer overloads accepting T const& over T&

This makes the following code behave as expected:

    Variant<int, String> x { some_string() };
    x.visit(
        [](String const&) {}, // Expectation is for this to be called
        [](auto&) {});
This commit is contained in:
Ali Mohammad Pur 2022-01-13 20:59:13 +03:30 committed by Ali Mohammad Pur
parent 9de33629da
commit 95b8c1745a
2 changed files with 46 additions and 1 deletions

View file

@ -48,6 +48,20 @@ TEST_CASE(visit_const)
[&](auto const&) {});
EXPECT(correct);
correct = false;
auto the_value_but_not_const = the_value;
the_value_but_not_const.visit(
[&](String const&) { correct = true; },
[&](auto&) {});
EXPECT(correct);
correct = false;
the_value_but_not_const.visit(
[&]<typename T>(T&) { correct = !IsConst<T>; });
EXPECT(correct);
}
TEST_CASE(destructor)