Does C++ standard library provide more compact and generalized version of the erase–remove idiom?
问题 We can erase one element/ entry from a container by the popular erase–remove idiom. However, many of us would have encountered some problems while applying this idiom: one can easily get into the pitfall of typos like c.erase(std::remove_if(c.begin(), c.end(), pred)); // , c.end() //---> missing here or c.erase((std::remove_if(c.begin(), c.end(), pred), c.end())) // ^^ ^^ // extra () makes it pass only c.end() to the c.erase It even follows the wrong semantics for containers like std::list by