The task of removing elements with a certain property from a std::vector or other container lends itself to a functional style implementation: Why bother with l
This will become available in a C++17-ready compiler soon through the std::experimental::erase_if algorithm:
#include
#include
#include
#include
#include
int main()
{
std::vector ints { -1, 0, 1 };
std::experimental::erase_if(ints, [](int x){
return x < 0;
});
std::copy(ints.begin(), ints.end(), std::ostream_iterator(std::cout, ","));
}
Live Example that prints 0,1