10 #ifndef META_UTIL_FUNCTIONAL_H_
11 #define META_UTIL_FUNCTIONAL_H_
27 template <
class Result,
class... Args>
28 std::function<Result(Args...)> memoize(std::function<Result(Args...)> fun)
30 return [fun](Args... args)
32 static std::map<std::tuple<Args...>, Result> map_;
33 auto it = map_.find(std::make_tuple(args...));
36 return map_[std::make_tuple(args...)] = fun(args...);
48 template <
class Iter,
class Function>
49 Iter argmax(Iter begin, Iter end, Function&& fn)
51 using T = decltype(*begin);
52 return std::max_element(begin, end, [&](
const T& a,
const T& b)