This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Is this a bug or lack of understanding?
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Is this a bug or lack of understanding?
- From: Chris Picton <Chris dot Picton at usko dot com>
- Date: Tue, 18 Apr 2000 14:40:21 +0200
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