property syntax strawman

Chad J chadjoan at __spam.is.bad__gmail.com
Sun Aug 2 08:19:41 PDT 2009


Ary Borenszweig wrote:
> 
> What I'd like the compiler to do, if you don't define property+=, is to
> transform this:
> 
> 1. foo.property += 2;
> 
> into this:
> 
> 2. foo.property = foo.property + 2;
> 

Be careful.

It's actually better to transform it into

auto t = foo.property;
t += 2;
foo.property = t;

The reason is because typeof(t) may have opAddAssign defined, but no
definition for opAdd or opAdd_r.

Other than that, I'm totally with you.



More information about the Digitalmars-d mailing list