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: 14257 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
|
|
|
|
|
Re: are there any sorting routines? [message #9319 is a reply to message #9294] |
Thu, 26 April 2007 20:16  |
captainc
Messages: 278 Registered: December 2006 Location: New Jersey, USA
|
Experienced Member |
|
|
I defined operator< in my class, but I am still receiving this error:
'error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const VT'
...
while compiling class template member function 'bool Upp::StdLess<T>::operator ()(const T &, const T &) const
...
***Found a solution: I moved the definition/declaration outside the class and used a const function in the class to return the data to the operator< function.
[Updated on: Thu, 26 April 2007 20:37] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon May 12 13:13:40 CEST 2025
Total time taken to generate the page: 0.03464 seconds
|