I have two vectors a and b with the same size.
vector<int> a{ 4, 3, 1, 3, 1};
vector<bool> b{false,false,true,false,true};
I want to remove the element in a
if the same element in b
(the same index) is true.
After applying the function: a = 4,3,3
Note: I want to use std
algorithms or functions instead of simple for loop.
std::vector<int> v {1,2,3,4,5,6};
std::vector<bool> b {true, false, true, false, true, false};
v.erase(std::remove_if(v.begin(), v.end(),
[&b, &v](int const &i) { return b.at(&i - v.data()); }), v.end());
LIVE DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With