32template <
typename T,
typename Ret,
typename... Args>
class memoized {
34 using key_t = std::tuple<Args...>;
38 auto memoize(
bool is_complete, F &&f, Args... args)
const
41 return f(std::forward<Args>(args)...);
43 const auto key =
key_t{std::forward<Args>(args)...};
45 cache_[key] = std::apply(f, key);
53 mutable std::map<key_t, value_t>
cache_;
56template <
typename T,
typename Ret>
class memoized<T, Ret> {
61 template <
typename F>
auto memoize(
bool is_complete, F f)
const
79template <
typename T,
typename Ret>
class memoized<T, Ret, bool> {
84 template <
typename F>
auto memoize(
bool is_complete, F f,
bool arg)
const
90 if (key && !true_value_) {
94 if (!key && !false_value_) {
95 false_value_ = f(arg);
98 return key ? *true_value_ : *false_value_;
106 false_value_.reset();