D Properties when?

H. S. Teoh hsteoh at qfbox.info
Thu Dec 14 21:11:49 UTC 2023


On Thu, Dec 14, 2023 at 06:08:52PM +0000, Hipreme via Digitalmars-d wrote:
[...]
> Think of an object with X and Y position. I want to be able to when
> its value changes, it sets a dirty flag to true. The problem is that
> I'm unable to do `X+= 50` after that. I need to do `X = X + 50`, this
> is not news but still makes the API inconsistent and more verbose.
>
> I don't care how this is implemented, I only want this some day to not
> make it look ugly.

Just add the appropriate opOpAssign overload.  Use templates to reduce
the boilerplate to a minimum (this is why D's operator overloads are
templates taking the operator as a CT string parameter, as opposed to
forcing you to write 10 overloads to support 10 combinations of
operators).


T

-- 
IBM = I'll Buy Microsoft!


More information about the Digitalmars-d mailing list