Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the following syntax with the combination of erase and remove mean? [duplicate]

Possible Duplicate:
Difference between erase and remove

suppose i have a container.... what does the following mean.

c.erase(remove(c.begin(),c.end(),99),c.end());

aren't erase and remove the same? What is the specific function of erase and remove in the above example?

like image 948
Saikiran Avatar asked Dec 26 '22 13:12

Saikiran


1 Answers

It removes all elements equal to 99 from container c.

std::remove doesn't actually remove any elements. It moves all the elements of interest to the second part of the container, and returns an iterator indicating the first of these. Then the erase member function takes an iterator range to actually remove the elements from the container.

See erase-remove idiom.

like image 60
juanchopanza Avatar answered Apr 12 '23 23:04

juanchopanza