When navigating to std::unordered_mapSTL, it does not provide any guarantees for considering a specific order of elements.
My question is about the order of elements with the same key, I tried it with different compilers, and I always get one after the other if they have the same key (example below). I searched him, but could not find him. Is it mentioned somewhere in the standards or is implementation dependent?
unordered_multimap<int, int> umap;
umap.insert({30, 9});
umap.insert({10, 1});
umap.insert({20, 5});
umap.insert({30, 8});
umap.insert({20, 4});
umap.insert({10, 2});
for (auto p : umap)
cout << p.first << " " << p.second << endl;
exits
30 8
30 9
20 4
20 5
10 1
10 2
source
share