I\'m looking for practical and educational samples of C++ / STL code fitting in few lines. My actual favorites are:
Empty a vector freeing its reserved memory:<
The following idiom is needed to actually remove the elements removed by remove() or remove_if():
vector v;
...
v.erase(remove(v.begin(), v.end(), 42), v.end());
remove() and remove_if() just slide non-removed elements forward and report where the new range ends -- they don't (and can't) delete them because they can work on any arbitrary iterator range, not just a container.