fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <random>
  4. #include <algorithm>
  5. #include <iterator>
  6. #include <functional>
  7.  
  8. int main() {
  9. const size_t N = 10;
  10.  
  11. std::vector<int> a(N);
  12.  
  13. std::mt19937 gen { std::random_device()() };
  14. std::uniform_int_distribution<> dist(-10,10);
  15.  
  16. std::generate(a.begin(), a.end(), std::bind(dist,gen));
  17.  
  18. std::cout<<"--- before ---\n";
  19. std::copy(a.begin(), a.end(), std::ostream_iterator<int>(std::cout, " "));
  20.  
  21. a.erase(std::remove_if(a.begin(), a.end(), std::bind2nd(std::modulus<int>(),2)), a.end());
  22.  
  23. std::cout<<"\n--- after ---\n";
  24. if (!a.empty())
  25. std::copy(a.begin(), a.end(), std::ostream_iterator<int>(std::cout, " "));
  26. else std::cout << "not found!\n";
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 4340KB
stdin
Standard input is empty
stdout
--- before ---
3 8 -8 -10 6 3 4 3 1 -7 
--- after ---
8 -8 -10 6 4