fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. int add(int a, int b)
  5. {
  6. return a + b;
  7. }
  8.  
  9. template <typename T1, typename T2, typename T3>
  10. std::function<T1(T3)> curry(std::function<T1(T2, T3)> f, T2 a)
  11. {
  12. return [=](T3 b) -> T1 { return f(a, b); };
  13. }
  14.  
  15. template <typename T1, typename T2, typename T3>
  16. inline std::function<T1(T3)> curry(T1(*f)(T2, T3), T2 a)
  17. {
  18. return curry(std::function<T1(T2, T3)>(f), a);
  19. }
  20.  
  21. int main()
  22. {
  23. std::function<int(int)> add1 = curry(add, 1);
  24. std::cout << add1(2) << std::endl;
  25. }
  26.  
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
3