property syntax strawman

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Sun Aug 2 08:24:56 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;

> Walter: what are the technical reasons for not transforming 1 into 2
> already?

Because there is no guarantee that += and + are implemented consistently by
user-defined types (even though they should be). A better transformation,
suggested by several people, is:

{
    auto temp = foo.property;
    temp += 2;
    foo.property = temp;
}

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list