So, I played with the recently standardized unordered_map from STL. The code that I have, sort of like, I just create an unordered_map, populate it and print it out:
unordered_map<int,string> m1; m1[5]="lamb"; m1[2]="had"; m1[3]="a"; m1[1]="mary"; m1[4]="little"; m1[7]="fleece"; m1[6]="whose"; m1[10]="fleecey"; m1[8]="was"; m1[9]="all"; for(unordered_map<int,string>::const_iterator i = m1.begin(); i != m1.end(); ++i) cout<<i->first<<" "<<i->second<<endl;
However, the output I get is ordered:
1 mary 2 had 3 a 4 little 5 lamb 6 whose 7 fleece 8 was 9 all 10 fleecey
But I do not want to pay the price for my card to be ordered! That is why I use unordered_map ... What is happening here?
additional note: I am using gcc version 4.3.4 20090804 (release) 1 (GCC) and compiling, like this, g++ -std=c++0X maptest.cpp
unordered-map c ++ 11 map
Jimmy
source share