Я нашел статью, которая содержит этот код:
template <typename ReturnType, typename... Args>
std::function<ReturnType (Args...)>
memoize(std::function<ReturnType (Args...)> func)
{
std::map<std::tuple<Args...>, ReturnType> cache;
return ([=](Args... args) mutable {
std::tuple<Args...> t(args...);
if (cache.find(t) == cache.end())
cache[t] = func(args...);
return cache[t];
});
}
Можете ли вы это объяснить? Я не могу понять много вещей здесь, но самое странное, что кеш является локальным, а не статическим, но, возможно, я ошибаюсь и...