Skip to content

Instantly share code, notes, and snippets.

@kazmura11
Created December 31, 2016 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazmura11/da5805242adee5aee33316f2c1066459 to your computer and use it in GitHub Desktop.
Save kazmura11/da5805242adee5aee33316f2c1066459 to your computer and use it in GitHub Desktop.
mapからvectorへ
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <iostream>
auto main()->int
{
std::ios::sync_with_stdio(false);
// vector -> map
std::unordered_map<std::string, int> m {{"a",1},{"b",2},{"c",3},{"d",4}};
std::vector<int> v;
std::transform(m.begin(), m.end(), back_inserter(v),
[](decltype(m)::value_type& kv) { return kv.second; });
//一応valueででソート
sort(v.begin(), v.end());
for (const auto& i : v) {
std::cout << i << ","; // => 1,2,3,4,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment