Archived

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

Map Container & Sorting :: STL

This topic is 5574 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. Is it possible to sort a map *by value* instead of by key? Moreover, is it possible to declare a map that with a custome sorting algorithm that sorts accord to value? If yes, please give a sample of the sorting function. I can create the function object, but I need to know the parameter. Thanks, Kuphryn

Share this post


Link to post
Share on other sites
The way I see it, sorting a map by value is illogical. Maps are sorted implicitly because of the way they''re done, they''re not sorted because it has to be (though we often take advantage of that).

You can provide your own operator as a template argument, but it will only be used to compare the keys.

What are you trying to do exactly?

----------------
Blaster
Computer game programmer and part time human being
Strategy First - http://www.strategyfirst.com
BlasterSoft - http://www.blastersoft.com

Share this post


Link to post
Share on other sites
No point sorting by value, because your lookups are on the key.

Maybe you want a set rather than a map.

But as Blaster said, since what you asked for doesn''t make sense, let us know what you''re trying to achieve and maybe we can help.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Share this post


Link to post
Share on other sites
Okay. Thanks.

The algorithm I am working on a probably simple for most programmers. Nonetheless, I want to come up with my own solution instead of posting it and home someone else solve it.

Hey, I always appreciate help from members.

Kuphryn

Share this post


Link to post
Share on other sites