fork(1) download
  1. #include <cassert>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. void filter(std::vector<int>& v, const std::vector<bool>& b)
  7. {
  8. assert(v.size() == b.size());
  9. auto it = b.begin();
  10. v.erase(std::remove_if(v.begin(), v.end(), [&](int) { return *it++; }), v.end());
  11. }
  12.  
  13.  
  14.  
  15. int main()
  16. {
  17. std::vector<int> v = {0, 1, 2, 3, 4, 5, 6};
  18. std::vector<bool> b = {true, true, false, false, true, false, true};
  19.  
  20. filter(v, b);
  21. for (auto i : v) {
  22. std::cout << " " << i;
  23. }
  24.  
  25. }
  26.  
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
 2 3 5