Just some addenda to the other answers here…
std::mem_fn (from #include
) can be used as a shorthand for the transform operator:
// previously we might've used this longhand
[](pair element){return element.second;}
And we can use vector::resize and std::distance to allocate space for the vector in one go, rather than repeatedly resizing it with back_inserter.
#include
#include
#include