Does it works correct(does nothing) when I use
vector<T> v;
v.erase(v.end());
I want to use something like
v.erase(std::find(...));
Should I if is it v.end() or not?
There is no info about it on C++.com and CPPreference
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The standard doesn’t quite spell it out, but
v.erase(q)is defined, “Erases the element pointed to byq” in[sequence.reqmts]. This means thatqmust actually point to an element, which the end iterator doesn’t. Passing in the end iterator is undefined behavior.Unfortunately, you need to write:
Of course, you could define:
c.erase()on an associative container returnsvoid, so to generalize this template to all containers you need some-> decltypeaction.