C++11
There should be a one-line version of the last two lines.
typedef std::pair<T1, T2> impl_node;
std::vector<impl_node> impl;
/* do stuff with impl */
std::vector<T1> retval(impl.size());
std::transform(impl.cbegin(), impl.cend(), retval.begin(),
[](const impl_node& in) { return *in.first; });
I tried writing some sort of custom iterator adapter, and the types are getting hairy. What’s the “right” solution? (And it probably generalizes to all sorts of other adapters.)
This is still two lines, but less typing (in both senses):
Actually, now that I look at it, I’d prefer three lines:
(Edited to remove move because there’s no evidence that it’s appropriate)