Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. std::function<int(int)> repeatN(std::function<int(int)> func, int N) {
  5.     if (N == 1) { return func; }
  6.     else {
  7.         std::function<int(int)> repeated = [func, N](int x) { return func(repeatN(func, N - 1)(x));  };
  8.         return repeated;
  9.     }
  10. }
  11.  
  12. int AddOne(int arg) { return arg + 1; }
  13.  
  14. int main()
  15. {
  16.     std::cout << repeatN(AddOne, 5)(3);
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement