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?
are there any sorting routines? [message #3401] Tue, 23 May 2006 19:41 Go to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
...or:

consider Array<Array<int>> something;

so to sort it by number of elements in subarray...
(or some recursive prototype Very Happy )

something like that.

in upp one never knows Smile

regards

[Updated on: Tue, 23 May 2006 19:42]

Report message to a moderator

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 next message
mirek is currently offline  mirek
Messages: 13975
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
Re: are there any sorting routines? [message #9293 is a reply to message #3401] Wed, 25 April 2007 22:34 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
Do you have an example of a custom class implementation that is capable of calling sort on? I need to see this in an example to get it correctly.

Much appreciated.
Re: are there any sorting routines? [message #9294 is a reply to message #9293] Wed, 25 April 2007 22:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
reference/Common or Ntl tutorial

In fact, all you need is some ordering predicate or operator< defined.

Mirek
Re: are there any sorting routines? [message #9319 is a reply to message #9294] Thu, 26 April 2007 20:16 Go to previous message
captainc is currently offline  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

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


Current Time: Mon Apr 29 05:49:23 CEST 2024

Total time taken to generate the page: 0.03195 seconds