properties as lvalues

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat May 13 21:05:28 PDT 2006


"cschueler" <cschueler_member at pathlink.com> wrote in message 
news:e45s4n$2sf8$1 at digitaldaemon.com...
> From the specs:
>
> Note: Properties currently cannot be the lvalue of an op=, ++, or --  
> operator.
>
> This strikes me, as I thought this was very easy to do - just have the 
> access
> function return a reference to the value. Oh wait, there are no references 
> in D
> (at least I didn't find them in the specs)? I think C++ has explicit 
> references
> for a reason, and this might be a hint why this is so.

Personally I think nice-looking reference types would be useful as well 
(great for returning references to container elements, such as the return 
value of 'in' for associative arrays), but for properties, I've got another 
idea: explicit property syntax.  Tell the compiler what is "get" and what is 
"set," and with that info, it can determine how to compile something like

a.prop += 8;

In this case, it'd make sure it has both a "get" and "set" for the property 
"prop," and then it'd just generate

a.prop(a.prop() + 8);

The problem here is that there's no guarantee that the semantics of "get" 
and "set" match up, but there's no guarantee with the current method either 
(although it'd be bad programming practice if someone did that). 





More information about the Digitalmars-d mailing list