Should AliasThis allow implicit conversion to the subtype AliasThis aliases to?

Dylan Knutson tcdknutson at gmail.com
Sat May 18 00:43:56 PDT 2013


I found out about AliasThis on the IRC, and it's pretty neat. 
I've got a suggestion for it however: Assigning a value to a 
class/struct which has aliased a member to this would forward the 
assignment to that member.

For instance:

----
struct IntPair {
	private int _pair;
	int left()  { return _pair[0]; }
	int right() { return _pair[1]; }
}

IntPair a = [1, 2]; // _pair = [1, 2]
IntPair b;
b.left(); //0
b = [3, 4];
b.left(); //3
----

Thoughts? I think it'd be very useful for defining types that 
look and act like built in primitives, but can have arbitrary 
methods and operator overloads attached to them.

Thanks to <jA_cOp> for bringing up AliasThis in IRC :-)


More information about the Digitalmars-d mailing list