[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:48:48 PST 2025
================
@@ -2610,6 +2610,30 @@ template <typename T> using has_sizeof = decltype(sizeof(T));
template <typename T>
constexpr bool is_incomplete_v = !is_detected<detail::has_sizeof, T>::value;
+/// A utility for working with maps that allows concisely expressing "perform
+/// and cache this expensive computation only if it isn't already cached".
+/// Use it like so:
+///
+/// ```cpp
+/// std::unordered_map<K, V> Cache;
+/// auto& Value = Cache.try_emplace(
+/// Key, llvm::defer {[] { /* heavy work */ }}).first->second;
----------------
kuhar wrote:
I don't get it -- how is this different than passing the lambda directly?
https://github.com/llvm/llvm-project/pull/171008
More information about the llvm-commits
mailing list