Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- std::function<int(int)> repeatN(std::function<int(int)> func, int N) {
- if (N == 1) { return func; }
- else {
- std::function<int(int)> repeated = [func, N](int x) { return func(repeatN(func, N - 1)(x)); };
- return repeated;
- }
- }
- int AddOne(int arg) { return arg + 1; }
- int main()
- {
- std::cout << repeatN(AddOne, 5)(3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement