int main(){
unordered_set<int> S;
S.insert(1);
S.insert(10);
S.insert(100);
S.insert(64);
for(auto &x: S){
cout<<x<<" ";
}
cout<<endl;
S.erase(S.find(1),S.end());
for(auto &x: S){
cout<<x<<" ";
}
}
Output:
64 1 100 10
64
This is same for every IDE and for every time.
Isn't unordered_set uses hash?
And hash don't have an order.
Indeed it's a poor name. I believe the C++ standards committee wanted to call it
std::hash_setbut there were too many so-calledstd::hash_sets in circulation prior to standardisation in C++11. The same applies tostd::unordered_map: see thehash_mapof the Boost distribution targeting C++03 and earlier.They are indeed ordered insofar that hashing buckets are ordered, but the main point one needs to make is that you're not supposed to care about the order.
(Fortunately in C++17
boost::optionalgrew intostd::optional: hopefully lessons were learnt, and something likestd::discretionaryavoided.)