Advertisement
ShadyLiar

Acc

Mar 29th, 2023 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. template<typename T>
  7. void Set(vector<T>& _vec, bool(*_filter)(T&), void(*_accumulator)(T&))
  8. {
  9.     for (T& value : _vec)
  10.     {
  11.         if (!_filter(value)) continue;
  12.         _accumulator(value);
  13.     }
  14. };
  15.  
  16.  
  17. int main()
  18. {
  19.     vector<float> vec = {5, 6, 7, 8, 9, 1, 2, 3};
  20.    
  21.     Set<float>(vec, [](float &a) { return a < 7; }, [](float &a) { a+=10;} );
  22.  
  23.     for (float& val : vec)
  24.         cout << val << " ";
  25.  
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement