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 » SortedIndex and Less
Re: SortedIndex and Less [message #40827 is a reply to message #40728] Sat, 21 September 2013 19:12 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13980
Registered: November 2005
Ultimate Member
Not sure what went wrong, I have tried this:

#include <Core/Core.h>

using namespace Upp;

struct rho : Moveable<rho> {
	int x,y,z;

	rho(int x,int y,int z) : x(x), y(y), z(z) {}
	rho() {}
	
	String ToString() const { return AsString(x) + ' ' + AsString(y) + ' ' + AsString(z); }
};

bool operator < (const rho& a, const rho& b){
	return a.x == b.x ? (a.y == b.y ? a.z < b.z : a.y < b.y) : a.x < b.x;
}

CONSOLE_APP_MAIN{
	StdLogSetup(LOG_FILE);

	SortedIndex<rho> data;
	data.Add(rho(1, 2, 3));
	data.Add(rho(1, 1, 1));
	data.Add(rho(1, 2, 0));
	
	DDUMPC(data);
}


and it seems to work fine...

Note: you can use CombineCompare helper:

bool operator < (const rho& a, const rho& b){
	return CombineCompare(a.x, b.x)(a.y, b.y)(a.z, b.z) < 0;
}


Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Deserialize json object
Next Topic: Confused about ArrayCtrl
Goto Forum:
  


Current Time: Wed May 15 11:41:00 CEST 2024

Total time taken to generate the page: 0.02612 seconds