#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <iterator>
#include <functional>
using namespace std;
int get_first(const std::pair<int, int> p) { return std::get<0>(p); }
int main() {
std::vector<int> items;
std::vector<std::pair<int, int>> pairs;
pairs.push_back(std::make_pair(1, 3));
pairs.push_back(std::make_pair(5, 7));
// With custom function.
std::transform(pairs.begin(), pairs.end(), std::back_inserter(items),
get_first);
// With std::get<0>, but this is super nasty. :(
std::transform(pairs.begin(), pairs.end(), std::back_inserter(items),
(const int& (*)(const std::pair<int, int>&))std::get<0>);
// With lambda; it's not much better.
std::transform(pairs.begin(), pairs.end(), std::back_inserter(items),
[](const std::pair<int, int>& p) { return std::get<0>(p); });
std::copy(items.begin(), items.end(),
std::ostream_iterator<int>(std::cout, " "));
cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBnZXRfZmlyc3QoY29uc3Qgc3RkOjpwYWlyPGludCwgaW50PiBwKSB7IHJldHVybiBzdGQ6OmdldDwwPihwKTsgfQoKaW50IG1haW4oKSB7CiAgc3RkOjp2ZWN0b3I8aW50PiBpdGVtczsKICBzdGQ6OnZlY3RvcjxzdGQ6OnBhaXI8aW50LCBpbnQ+PiBwYWlyczsKCiAgcGFpcnMucHVzaF9iYWNrKHN0ZDo6bWFrZV9wYWlyKDEsIDMpKTsKICBwYWlycy5wdXNoX2JhY2soc3RkOjptYWtlX3BhaXIoNSwgNykpOwoKICAvLyBXaXRoIGN1c3RvbSBmdW5jdGlvbi4KICBzdGQ6OnRyYW5zZm9ybShwYWlycy5iZWdpbigpLCBwYWlycy5lbmQoKSwgc3RkOjpiYWNrX2luc2VydGVyKGl0ZW1zKSwKICA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