Advertisement
wowonline

Untitled

Apr 7th, 2022
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template <typename iter>
  5. void func(iter it)
  6. {
  7.     *it = (*it) * 2;
  8. }
  9.  
  10. template <typename iter, typename func>
  11. void myapply(iter begin, iter end, func f)
  12. {
  13.     for (iter it = begin; it != end; ++it) {
  14.         f(it);
  15.     }
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21.     std::vector<int> v = {1, 2, 3, 4};
  22.     myapply(v.begin(), v.end(), func);
  23.  
  24.     for (int c : v) {
  25.         std::cout << c << std::endl;
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement