Created
December 31, 2016 20:46
-
-
Save kazmura11/cc9730454d9a113cd94a0c364996edc1 to your computer and use it in GitHub Desktop.
vectorからmapへ
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 <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