Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help me understand std::erase

Tags:

c++

stl

In the book 'C++ In A Nutshell', there is the following example code

std::vector<int> data
...
std::erase(std::remove(data.begin(), data.end(), 42),
  data.end());

I thought that 'erase' was a member function, so shouldn't that be 'data.erase' rather than 'std::erase'? Is there some way the c++ compiler can tell what member you wanted to call a member function on, or did the book omit any documentation of an erase template function, or is the example wrong?

like image 724
Paul Tomblin Avatar asked Feb 26 '26 00:02

Paul Tomblin


1 Answers

erase is a member function. The sample provided is incorrect.

like image 110
Pavel Minaev Avatar answered Feb 27 '26 13:02

Pavel Minaev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!