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 » Community » Newbie corner » Sorting a ValueArray ?
Re: Sorting a ValueArray ? [message #42927 is a reply to message #42921] Mon, 14 April 2014 20:21 Go to previous message
mirek is currently offline  mirek
Messages: 14255
Registered: November 2005
Ultimate Member
mingodad wrote on Mon, 14 April 2014 15:16
After reading your answer and thinking a bit I've got this code to work:
static bool CompareGetDistances(Value &a, Value &b)
{
	return a[5] < b[5];
}
...
    ValueArray &rows = SomeValuaArrayOfValueMap();
    Vector<Value> &vv = const_cast< Vector<Value>& >(rows.Get());
    Sort(vv, CompareGetDistances);
...


Thanks for your help !


That is not quite a good idea. If there exists a copy of ValueArray, it will get sorted too...

To stay on the safe side, I would probably rather used something like

	Vector<Value> v = clone(va.Get());
	Sort(v);
	va = ValueArray(pick(v));


(but thinking about the whole issue, it looks like "Pick" method would not be a bad idea too here...)

Mirek
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Testscatter2 issue
Next Topic: Convert C# code to U++?
Goto Forum:
  


Current Time: Sun Apr 27 02:50:32 CEST 2025

Total time taken to generate the page: 0.00882 seconds