proposal: @mixin functions to auto-mixin at call site

Dicebot public at dicebot.lv
Thu Sep 5 03:34:33 PDT 2013


On Wednesday, 4 September 2013 at 17:07:33 UTC, Timothee Cour 
wrote:
> IIRC, &foo.x with x a property should take address of return 
> value of x(),
> which will either fail to compile or do the right thing if it 
> returns a
> lvalue.

It is not possible because getters are not guaranteed to return 
lvalues. There is a quite elegant (in my opinion) proposal 
hanging around to allow annotating plain fields with @property so 
that compiler will prohibit doing any operation on them that may 
later break because of transition to actual properties, such as 
taking address.

> As for side effects, this is the reason one would go from field 
> access to
> property, eg populating some data upon 1st access to a field x. 
> Sure it can
> be misused, but I haven't seen a case in practice where it is 
> misused.

I haven't seen a case in practice when using normal method 
instead of a property was really harmful. Also modifying own 
members is legal for weakly pure method as far as I remember (it 
can modify arguments, including hidden `this`), so your case will 
actually work within my restrictions.


More information about the Digitalmars-d mailing list