Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. std::function<int(int)> Memoize(std::function<int(int)> fn)
  2. {
  3. std::map<int, int> memo;
  4. std::function<int(int)> helper = [=](int pos)
  5. {
  6. if (memo.count(0) == 0)
  7. {
  8. memo[pos] = fn(pos);
  9. }
  10. return memo[pos];
  11. };
  12. return helper;
  13. }
  14.  
  15. 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)
  16.  
  17. std::function<int(int)> Memoize(std::function<int(int)> fn)
  18. {
  19. std::map<int, int> memo;
  20. std::function<int(int)> helper = [=](int pos) mutable // <== HERE!!
  21. {
  22. if (memo.count(0) == 0)
  23. {
  24. memo[pos] = fn(pos);
  25. }
  26. return memo[pos];
  27. };
  28. return helper;
  29. }
  30.  
  31. class Helper
  32. {
  33. public:
  34. int operator()(int) const;
  35. private:
  36. std::map<int, int> memo;
  37. std::function<int(int)> fn;
  38. };
  39.  
  40. std::function<int(int)> helper = [=](int pos) mutable
  41. // etc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement