Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DaJudge

std::list::sort() problem

This topic is 5477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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:


300000
5088
Press any key to continue


Is this stl implementation broken? It''s MSVC++ 6.0

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!