How to remove elements from container is a common C++ interview question, so you can earn some brownie points if you read this page carefully.
如何从容器中删除元素是C ++常见的面试问题,因此,如果仔细阅读此页,可以赚取布朗尼积分。
The erase–remove idiom is a C++ technique to eliminate elements that fulfill a certain criterion from a container. However, it is possible to eliminate elements with traditional hand-written loop, but the erase–remove idiom has several advantages.
删除删除惯用语是一种C ++技术,用于从容器中删除满足特定条件的元素。 但是,可以使用传统的手写循环来消除元素,但是“擦除-删除”这一惯用法具有多个优点。
比较方式 (Comparison)
// Using a hand-written loop
std::vector<int> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for (auto iter = v.cbegin(); iter