Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::function<int(int)> Memoize(std::function<int(int)> fn)
- {
- std::map<int, int> memo;
- std::function<int(int)> helper = [=](int pos)
- {
- if (memo.count(0) == 0)
- {
- memo[pos] = fn(pos);
- }
- return memo[pos];
- };
- return helper;
- }
- 1>Source1.cpp(24): error C2678: binary '[' : no operator found which takes a left-hand operand of type 'const std::map<_Kty,_Ty>' (or there is no acceptable conversion)
- std::function<int(int)> Memoize(std::function<int(int)> fn)
- {
- std::map<int, int> memo;
- std::function<int(int)> helper = [=](int pos) mutable // <== HERE!!
- {
- if (memo.count(0) == 0)
- {
- memo[pos] = fn(pos);
- }
- return memo[pos];
- };
- return helper;
- }
- class Helper
- {
- public:
- int operator()(int) const;
- private:
- std::map<int, int> memo;
- std::function<int(int)> fn;
- };
- std::function<int(int)> helper = [=](int pos) mutable
- // etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement