std::list::sort() problem

Started by
2 comments, last by DaJudge 20 years, 6 months ago
hi all. in my current project I use the following code to sort a set of log entries that are stored as pointers in a std::list...

MessageBox(0, stringf("before(%d).", entries.size()).c_str(), APP_NAME, MB_OK);
greater<LogFileEntry*> entry_greater;
entries.sort(entry_greater);
MessageBox(0, stringf("after (%d).", entries.size()).c_str(), APP_NAME, MB_OK);
    
where the functor greater is a template specialization:

struct std::greater<LogFileEntry*>
{
	bool operator()(const LogFileEntry*& e0, const LogFileEntry*& e1)const
	{
		return e0->datetime > e1->datetime;
	};
};
    
Unfortunately the one line that does the sorting reduces the number of list elements from over 100k to around 13k in my testing dataset. Now the question is: WHY? Maybe some of you can tell me... Thanks, Alex [edited by - dajudge on September 22, 2003 1:56:38 PM]
Alexander Stockinger
Programmer
Advertisement
okay. i modified the program to work on copies of the entries instead of pointers. still the same problem...

this just drives me mad...
Alexander Stockinger
Programmer
Now THIS is really evil.

	list<int> intlist;	for(unsigned int i=0; i<300000; i++)		intlist.push_back(rand());	printf("%d\r\n", intlist.size());	intlist.sort();	printf("%d\r\n", intlist.size()); 


does the following output:

3000005088Press any key to continue 


Is this stl implementation broken? It''s MSVC++ 6.0
Alexander Stockinger
Programmer
okay...

http://www.dinkumware.com/vc_fixes.html
Alexander Stockinger
Programmer

This topic is closed to new replies.

Advertisement