diff options
| author | Dominik Laskowski <domlaskowski@google.com> | 2022-11-15 11:34:33 -0500 |
|---|---|---|
| committer | Dominik Laskowski <domlaskowski@google.com> | 2023-04-18 19:28:35 -0400 |
| commit | 80872bddcc529d750c12349675504ea00271712a (patch) | |
| tree | 3e151d2772fe229b1bc94d11d718294e1af2427c /libs/ftl/algorithm_test.cpp | |
| parent | ccda33e2eb762b0f9ffff3de982011b6fc7f84ec (diff) | |
SF: Clean up ftl::SmallMap lookup fallbacks
Avoid std::cref to a local variable, which is not intuitive and incurs
construction in the non-fallback case.
Bug: 185536303
Test: ftl_test
Change-Id: I1c5a94bdab105a04f8230fe762bdc433eea5c97a
Diffstat (limited to 'libs/ftl/algorithm_test.cpp')
| -rw-r--r-- | libs/ftl/algorithm_test.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libs/ftl/algorithm_test.cpp b/libs/ftl/algorithm_test.cpp index 8052caf642..487b1b8759 100644 --- a/libs/ftl/algorithm_test.cpp +++ b/libs/ftl/algorithm_test.cpp @@ -47,4 +47,20 @@ TEST(Algorithm, FindIf) { EXPECT_EQ(opt->get(), ftl::StaticVector("tiramisu"sv)); } +TEST(Algorithm, StaticRef) { + using namespace std::string_view_literals; + + const ftl::SmallMap map = ftl::init::map(13, "tiramisu"sv)(14, "upside-down cake"sv); + ASSERT_EQ("???"sv, + map.get(20).or_else(ftl::static_ref<std::string_view>([] { return "???"sv; }))->get()); + + using Map = decltype(map); + + ASSERT_EQ("snow cone"sv, + ftl::find_if(map, [](const auto& pair) { return pair.second.front() == 's'; }) + .transform(ftl::to_mapped_ref<Map>) + .or_else(ftl::static_ref<std::string_view>([] { return "snow cone"sv; })) + ->get()); +} + } // namespace android::test |
