summaryrefslogtreecommitdiff
path: root/Tests/AK
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-01-13 20:59:13 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-01-14 11:35:40 +0330
commit95b8c1745a4a9377f629ca204f90add44ac41bf1 (patch)
treef6b7ec8c0b8498e6479b5e5f0e34ba82e7986bf4 /Tests/AK
parent9de33629daa95a0bb175824d189dc8ae1f65a77d (diff)
downloadserenity-95b8c1745a4a9377f629ca204f90add44ac41bf1.zip
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&) {});
Diffstat (limited to 'Tests/AK')
-rw-r--r--Tests/AK/TestVariant.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/Tests/AK/TestVariant.cpp b/Tests/AK/TestVariant.cpp
index af87669671..f55d176537 100644
--- a/Tests/AK/TestVariant.cpp
+++ b/Tests/AK/TestVariant.cpp
@@ -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)