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/cc9730454d9a113cd94a0c364996edc1 to your computer and use it in GitHub Desktop.
Save kazmura11/cc9730454d9a113cd94a0c364996edc1 to your computer and use it in GitHub Desktop.
vectorからmapへ
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <iostream>
auto main()->int
{
std::ios::sync_with_stdio(false);
// vector -> map
std::vector<int> v = {1,2,3,4,5};
std::unordered_map<int, int> m;
std::transform(v.begin(), v.end(),
inserter(m, m.begin()), [](const int& i) { return std::make_pair(i, i); });
// 順序はぐちゃぐちゃです
for (const auto& i : m) {
std::cout << "{" << i.first << ":" << i.second << "},"; // => {5:5},{4:4},{3,3},{2,2},{1,1},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment