Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- template <class T>
- class CompareVal
- {
- T val;
- public:
- CompareVal(T val) : val(val) {}
- bool operator()(T val)
- {
- return this->val == val;
- }
- };
- template <class T>
- class CompareRange
- {
- T min;
- T max;
- public:
- CompareRange(T min, T max) : min(min), max(max) {}
- bool operator()(T val)
- {
- return val >= min && val <= max;
- }
- };
- void main()
- {
- vector<int> arr = { 0,1,2,3,4,5,6,7 };
- for (auto& temp : arr)
- {
- cout << temp << ' ';
- }
- cout << endl;
- auto it = remove_if(arr.begin(), arr.end(), CompareVal<int>(5));
- arr.erase(it, arr.end());
- for (auto& temp : arr)
- {
- cout << temp << ' ';
- }
- cout << endl;
- it = remove_if(arr.begin(), arr.end(), CompareRange<int>(3, 6));
- arr.erase(it, arr.end());
- for (auto& temp : arr)
- {
- cout << temp << ' ';
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement