Advertisement
BeloMaximka

Belov_HW_O38

Nov 1st, 2021
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. template <class T>
  6. class CompareVal
  7. {
  8.     T val;
  9. public:
  10.     CompareVal(T val) : val(val) {}
  11.     bool operator()(T val)
  12.     {
  13.         return this->val == val;
  14.     }
  15. };
  16.  
  17. template <class T>
  18. class CompareRange
  19. {
  20.     T min;
  21.     T max;
  22. public:
  23.     CompareRange(T min, T max) : min(min), max(max) {}
  24.     bool operator()(T val)
  25.     {
  26.         return val >= min && val <= max;
  27.     }
  28. };
  29.  
  30. void main()
  31. {
  32.     vector<int> arr = { 0,1,2,3,4,5,6,7 };
  33.     for (auto& temp : arr)
  34.     {
  35.         cout << temp << ' ';
  36.     }
  37.     cout << endl;
  38.  
  39.     auto it = remove_if(arr.begin(), arr.end(), CompareVal<int>(5));
  40.     arr.erase(it, arr.end());
  41.     for (auto& temp : arr)
  42.     {
  43.         cout << temp << ' ';
  44.     }
  45.     cout << endl;
  46.  
  47.     it = remove_if(arr.begin(), arr.end(), CompareRange<int>(3, 6));
  48.     arr.erase(it, arr.end());
  49.     for (auto& temp : arr)
  50.     {
  51.         cout << temp << ' ';
  52.     }
  53.     cout << endl;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement