I've got a container and would like to erase elements based on a predicate. erase_if
sounds familiar, but I can't find it in C++. What's the name and where is it defined? I'd like to use it with a lambda in VS10.
Antibiotics, often in a single dose, can cure many sexually transmitted bacterial and parasitic infections, including gonorrhea, syphilis, chlamydia and trichomoniasis. Typically, you'll be treated for gonorrhea and chlamydia at the same time because the two infections often appear together.
std :: remove Transforms the range [first,last) into a range with all the elements that compare equal to val removed, and returns an iterator to the new end of that range. The function cannot alter the properties of the object containing the range of elements (i.e., it cannot alter the size of an array or a container).
If you store pointers in STL container classes you need to manually delete them before the object gets destroyed. This can be done by looping through the whole container and deleting each item, or by using some kind of smart pointer class. However do not use auto_ptr as that just does not work with containers at all.
You're probably looking for std::remove_if
, in a pattern such as:
vec.erase(std::remove_if(vec.begin(), vec.end(), predicate), vec.end());
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