mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +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
Notes:
sideshowbarker
2024-07-17 20:55:19 +09:00
Author: https://github.com/alimpfard
Commit: 95b8c1745a
Pull-request: https://github.com/SerenityOS/serenity/pull/11866
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