opCmp with structs

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 6 14:54:08 PST 2015


I'm sure I'm doing a silly mistake somewhere, but why this 
doesn't work?
import std.stdio;
import std.algorithm;

struct ku
{
	immutable int id;
	alias id this;
	
	this(int i)
	{
		id = i;
	}
	
	int opCmp(ref const ku rhs) const {return id - rhs.id; }
}

void main()
{
	ku[] tt = [ku(2), ku(1)];
	sort(tt);
}


More information about the Digitalmars-d-learn mailing list