fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. template <typename Container, typename Filter>
  6. void filter_ip(Container& c, Filter&& f)
  7. {
  8. c.erase(std::remove_if(c.begin(), c.end(),
  9. [&f](const typename Container::value_type& x) {
  10. return !f(x);
  11. }),
  12. c.end());
  13. }
  14.  
  15. int main() {
  16. std::vector<int> stuff{1, 2, 3, 4, 5};
  17. filter_ip(stuff, [](int i) { return i >= 3; });
  18. for (int i : stuff) cout << i << ", ";
  19. return 0;
  20. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
3, 4, 5,