why properties don't support +=, -= ... operators?

Andrey via Digitalmars-d digitalmars-d at puremagic.com
Tue May 23 11:21:06 PDT 2017


On Tuesday, 23 May 2017 at 17:38:18 UTC, Petar Kirov [ZombineDev] 
wrote:
> The problem is that if you return by ref you loose the ability 
> to intercept the setting of the value, i.e. you're no better 
> than just making the field public.
>
> AFAIU the OP, he's asking for the following lowering:
>
> e.value += 42;
> //   ^
> //   v
> e.value(e.value() + 42);
>
> However, note that in general such lowering may not always be 
> possible or desirable. For example:
>
> e.someContainerProperty ~= new Item();
> //   ^
> //   v
> e.someContainerProperty(e.someContainerProperty() ~ new Item());

You right, it would be nice to explicitly set lowering.


More information about the Digitalmars-d mailing list