| 448 | // Thread-unsafe memoization |
| 449 | template<class F, class R=decltype(std::declval<F>()())> |
| 450 | static inline std::function<R()> memoize(F f) |
| 451 | { |
| 452 | bool init = false; |
| 453 | R result{}; |
| 454 | return [=]() mutable -> R { |
| 455 | if (init) |
| 456 | return result; |
| 457 | result = f(); |
| 458 | init = true; |
| 459 | return result; |
| 460 | }; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | #endif |