fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. template<class Signature>
  5. struct recursive
  6. {
  7. std::function<std::function<Signature>(recursive)> f;
  8. };
  9.  
  10. template<class R, class... Args>
  11. using type = std::function<R(Args...)>;
  12.  
  13. template<class R, class... Args>
  14. using f_type = std::function<type<R, Args...>(type<R, Args...>)>;
  15.  
  16. template<class R, class... Args>
  17. type<R, Args...> helper_for(f_type<R, Args...> f)
  18. {
  19. recursive<R(Args...)> r = { [f](recursive<R(Args...)> rf)
  20. {
  21. return f([rf](Args... args){ return rf.f(rf)(args...); });
  22. }};
  23. return r.f(r);
  24. }
  25.  
  26. std::function<long(long)> fuck(std::function<long(long)> f)
  27. {
  28. return [f](long n)->long { return (n <= 1) ? 1 : n * f(n - 1); };
  29. }
  30.  
  31. int main()
  32. {
  33. auto fuck_of_fuck = helper_for(f_type<long, long>(fuck));
  34.  
  35. std::cout << fuck_of_fuck(10);
  36. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
3628800