Skip to content

Instantly share code, notes, and snippets.

@DieHertz
Created March 26, 2015 10:19
Show Gist options
  • Save DieHertz/a55b110a3752a7b1d54b to your computer and use it in GitHub Desktop.
Save DieHertz/a55b110a3752a7b1d54b to your computer and use it in GitHub Desktop.
#include <ext/map.hpp>
#include <vector>
#include <iostream>
int main() {
const std::vector<std::pair<std::string, std::string>> collection{
{ "first", "primero" },
{ "second", "segundo" },
{ "third", "tercero" }
};
const auto print = [] (const auto & collection) {
std::copy(std::begin(collection), std::end(collection), std::ostream_iterator<std::string>{std::cout, " "});
std::cout << std::endl;
};
/// specifying result collection template is not really necessary, type-deduction will do
const auto en = ext::map<std::vector>(collection, [] (auto & collection) {
return collection.first;
});
print(en);
const auto es = ext::map<std::vector>(collection, [] (auto & collection) {
return collection.second;
});
print(es);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment