@property - take it behind the woodshed and shoot it?
Rob T
alanb at ucora.com
Sat Jan 26 16:15:29 PST 2013
We can almost implement properties as a regular struct
struct prop
{
int _val;
ref prop opAssign( int a_val )
{
writeln("assignment = ", a_val );
_val = a_val;
return this;
}
int opCall()
{
writeln("opcall = ", _val );
return _val;
}
// other op overloads, like ++, --, etc
}
If we change a few things it may work. Instead of struct it could
be named prop
eg
prop P
{
...
}
opCall needs to be changed so there's no need to specify the ().
No dounbt other changes will be needed too to make it more
convenient to use and less error prone.
The advantage is that with a "property as a struct"
implementation, you can wrap up a lot more than just a setter and
getter around only one variable, eg internally there could be
several vars or even none at all depending on the needs.
--rt
More information about the Digitalmars-d
mailing list