Tell me how to correctly walk through the vector and remove some of its elements.
Ie, is it correct to perform such actions?
for (auto it = arr.begin(); it != arr.end(); it++) { if (check(*it) == false) arr.erase(it); } Or will there be a problem with the iterator after deleting the first element?
Read the comments, thank you all for your help.
I revised the code and realized that I did not quite complete the task:
for (auto it = arr.begin(); it != arr.end(); it++) { if (check(*it) == false) { // сделать-что-то полезное с данными, которые потом будут удалены arr.erase(it); } } If you use the advice of @Harry, then the code can also be converted to this:
arr.erase(remove_if(arr.begin(), arr.end(), [](auto x) { if (check(x)) { // сделать что-то полезное с данными из x return true; } return false; }), arr.end()); ?