Advertisement
wowonline

Untitled

Apr 7th, 2022
659
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data Copied
Advertisement