I am interested in this behavior. I found that the destination unordered_mapchanges the internal order of the unordered map without entering / deleting:
unordered_map<int, string> m1;
unordered_map<int, string> m2;
unordered_map<int, string> m3;
m1[2] = "john";
m1[4] = "sarah";
m1[1] = "mark";
m2 = m1;
m3 = m2;
for(auto it = m1.begin(); it != m1.end(); ++it) {
cout << it->second << " ";
}
cout << endl;
for(auto it = m2.begin(); it != m2.end(); ++it) {
cout << it->second << " ";
}
cout << endl;
for(auto it = m3.begin(); it != m3.end(); ++it) {
cout << it->second << " ";
}
cout << endl;
outputs:
mark sarah john
john sarah mark
mark sarah john
I know that unordered_mapno particular order is supported due to the fact that it is a hash table internally, so inserting an element can end anywhere, and re-hash will mix it all.
However, here the order changes immediately after the appointment. I expected that the order would be the same as I thought, it would just copy the underlying storage.
, , , , , unordered_map . (m3) m2, m2 m3.
?
- Apple LLVM 8.1.0 (clang-802.0.42)