MCPcopy Create free account
hub / github.com/apache/arrow / Memoize

Function Memoize

cpp/src/arrow/util/cache_internal.h:170–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168template <template <typename...> class Cache, template <typename...> class MemoizerType,
169 typename Key, typename Func>
170static auto Memoize(Func&& func, int32_t cache_capacity) {
171 using Value = std::decay_t<std::invoke_result_t<Func, const Key&>>;
172 using Memoizer = MemoizerType<Key, Value, Cache<Key, Value>, Func>;
173 using RetType = typename Memoizer::RetType;
174
175 // std::function<> requires copy constructibility
176 struct {
177 RetType operator()(const Key& key) const { return (*memoized_)(key); }
178 std::shared_ptr<Memoizer> memoized_;
179 } shared_memoized = {
180 std::make_shared<Memoizer>(std::forward<Func>(func), cache_capacity)};
181
182 return std::function<RetType(const Key&)>(std::move(shared_memoized));
183}
184
185} // namespace detail
186

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected