Created
March 26, 2015 10:19
-
-
Save DieHertz/a55b110a3752a7b1d54b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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