fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template<int RepeatTimes, typename F, class ... mutrArgs>
  6. void run(
  7. vector<int>& vec,
  8. F mutr,
  9. mutrArgs ... args
  10. )
  11. {
  12. for (int times{0} ; times < RepeatTimes ; ++times)
  13. for (auto& item : vec)
  14. mutr(item, args...);
  15. }
  16.  
  17. void adder(int& i, const int& val)
  18. {
  19. i += val;
  20. }
  21.  
  22. int main()
  23. {
  24. vector<int> v{0,1,2,3,4,5,6,7,8,9};
  25. const int addValue{4};
  26. run<2>(
  27. v,
  28. &adder,
  29. addValue
  30. );
  31. for (auto i : v)
  32. cout << i << " ";
  33. cout << endl;
  34. }
  35.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
8 9 10 11 12 13 14 15 16 17