Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is erase_if?

Tags:

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.

like image 639
Olaf van der Spek Avatar asked Aug 06 '10 14:08

Olaf van der Spek


People also ask

How do you get rid of an STD?

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.

What STD remove returns?

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).

How do I delete a container in St Louis?

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.


1 Answers

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()); 
like image 166
Victor Nicollet Avatar answered Dec 10 '22 17:12

Victor Nicollet