Advertisement
EWTD

FilteringSetExample

Nov 16th, 2022 (edited)
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     set<int> a{1,2,3,4,5,6,7,8};
  9.     /*
  10.     remove_if(a.begin(),a.end(),[](int val){return val%2 == 0;});
  11.      a.begin() - iterator to const node_type, then *a.begin() = 10 isn't valid, so
  12.      remove_if can't be applied there;
  13.     */
  14.     set<int> filtered;
  15.     copy_if(a.begin(),a.end(), inserter(filtered, filtered.end()),[](int val){return val%2 == 0;});
  16.     for(const auto& v: filtered)
  17.         cout << v << ' ';
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement