| 168 | template <template <typename...> class Cache, template <typename...> class MemoizerType, |
| 169 | typename Key, typename Func> |
| 170 | static 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 |
nothing calls this directly
no outgoing calls
no test coverage detected