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   |
 |
mirek
Messages: 14265 Registered: November 2005
|
Ultimate Member |
|
|
Sure. Guess what, it is called "Sort" (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
|
|
|
Goto Forum:
Current Time: Mon Jul 07 17:26:12 CEST 2025
Total time taken to generate the page: 0.03709 seconds
|