operator overload for enum

Satoshi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 10 04:02:40 PDT 2016


Hello,
why operator overloading is not working as a static methods 
through the UFCS?

I need overload a << operator in this way:

enum PlatformID {
	None,
	Trinix,
	Unix,
	MacOS,
	Windows
}

PlatformID toPlatformID(string platform) {
	switch (platform.toLower()) {
		case "trinix":  return PlatformID.Trinix;
		case "unix":    return PlatformID.Unix;
		case "macos":   return PlatformID.MacOS;
		case "windows": return PlatformID.Windows;
		default:        return PlatformID.None;
	}
}

void opBinary(string op)(ref PlatformID plat, auto ref const 
string str) if (op == "<<") {
	plat = toPlatformID(str);
}


void thisIsTest() {
	PlatformID id;
	id << "x86_64"; // this is not working
	id.opBinary!("<<")("test"); // but this works O.K.

}


More information about the Digitalmars-d-learn mailing list