[llvm] [LLVM][ADT] Add helper class for working with caches (PR #171008)
Jakub Kuderski via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 7 08:50:51 PST 2025
================
@@ -1699,4 +1699,15 @@ struct Bar {};
static_assert(is_incomplete_v<Foo>, "Foo is incomplete");
static_assert(!is_incomplete_v<Bar>, "Bar is defined");
+TEST(STLExtrasTest, Defer) {
+ std::unordered_map<int, int> Cache;
+ const auto [It, Inserted]{Cache.try_emplace(1, defer{[] { return 10; }})};
+ ASSERT_TRUE(Inserted);
+ ASSERT_EQ(It->second, 10);
+ Cache.try_emplace(1, defer{[] {
+ assert(false && "this should never be executed");
+ return 0;
+ }});
+}
----------------
kuhar wrote:
This would benefit from tests without unordered_map.
https://github.com/llvm/llvm-project/pull/171008
More information about the llvm-commits
mailing list