Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » are there any sorting routines?
Re: are there any sorting routines? [message #3402 is a reply to message #3401] Tue, 23 May 2006 21:36 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14265
Registered: November 2005
Ultimate Member
Sure. Guess what, it is called "Sort" Wink (Or, if you need to retain ordering of equal items, "StableSort").

For your example, you will need to create ordering predicate - in common case, that is class with ordering operator()(T, T). Anyway, here what you need is ordering by GetCount method, therefore you can use

Sort(something, MethodRelation(&Array<int>::GetCount, StdLess<int>());


BTW, this is quite similar to STL, however one important difference is that in U++, Sort is guaranteed to work as long as T has defined IterSwap (no copy in necessary), and StableSort is guaranteed to work if there is any transfer operation (means, instead of deep copy, it is enough to have just pick). (BTW, one unresolved drawback is that at the moment, StableSort is unable to sort polymorphic arrays, anyway, that is quite corner case. And you can always use GetSortOrder.).

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: !USEMALLOC
Next Topic: Compile error "thread-local storage not supported ..."
Goto Forum:
  


Current Time: Mon Jul 07 17:26:12 CEST 2025

Total time taken to generate the page: 0.03709 seconds