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   |
 |
mirek
Messages: 14255 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
|
|
|
Goto Forum:
Current Time: Sun Apr 27 23:44:45 CEST 2025
Total time taken to generate the page: 0.00776 seconds
|