Is this a bug or lack of understanding?
Chris Picton
Chris.Picton@usko.com
Tue Apr 18 05:40:00 GMT 2000
Hi
I have the following program:
//----------------------------
#include <map>
#include <string>
struct s {
bool operator()(string s1, string s2) {
// return s1.size() < s2.size();
return s1 < s2;
}
};
void main()
{
map<string, int, s> m;
m["a"] = 1;
m["ab"] = 1;
m["ba"] = 1;
m["abc"] = 1;
m["acb"] = 1;
m["bac"] = 1;
m["bca"] = 1;
m["cab"] = 1;
m["cba"] = 1;
for (map<string, int>::iterator i = b.begin(); i != b.end(); i++)
cout << (*i).first << "\t" << (*i).second << endl;
}
//-------------------------------------------
If i run it as it stands, it prints out all the elements in the map
in alphabetical order of the keys
If I change the commented return line in the sort function object, to
sort by length of the key, it doesnt print all the entries in the map.
Could someone explain why, or is it a bug?
--
Chris Picton
Usko Communications Systems Developer
Chris.Picton@usko.com
More information about the Libstdc++
mailing list