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:
parent
9de33629da
commit
95b8c1745a
2 changed files with 46 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue