Advertisement
FRiTZZY

TP_T7_Z5

Apr 27th, 2015
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. /* Tutorijal_7 Zadatak_5 */
  2. #include <iostream>
  3. #include <functional>
  4.  
  5. using std::cout;
  6. using std::endl;
  7.  
  8. std::function<int(int)> IteriranaFunkcija(int f(int), int n) {
  9.     std::function<int(int)> r(f);
  10.  
  11.     for (int i = 0; i < n - 1; i++)
  12.         r = [r, f](int n) { return r(f(n)); };
  13.  
  14.     return r;
  15. }
  16.  
  17. int f(int n) {
  18.     return n + 1;
  19. }
  20.  
  21. int main()
  22. {
  23.     auto g = IteriranaFunkcija(f, 10);
  24.     cout << g(5);
  25.     cout << endl;
  26.     cout << IteriranaFunkcija(f, 10)(5);
  27.     cout << endl;
  28.     cout << f(f(f(f(f(f(f(f(f(f(5))))))))));
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement