fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename F>
  5. struct curry_impl {
  6. F f;
  7. curry_impl(F f) : f(f) {}
  8. template <typename A>
  9. struct inner {
  10. F f; A a;
  11. inner(F f, A a) : f(f), a(a) {}
  12. template <typename B>
  13. auto operator () (B b) -> decltype(f(a, b)) {
  14. return f(a, b);
  15. }
  16. };
  17. template <typename A>
  18. auto operator () (A a) -> inner<A> {
  19. return inner<A>(f, a);
  20. }
  21. };
  22. template <typename F>
  23. curry_impl<F> curry(F f) {
  24. return curry_impl<F>(f);
  25. }
  26.  
  27. int main() {
  28. cout << curry([](int x, int y) { return x + y; })(21)(21) << endl;
  29. }
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
42