`restricted` member variables

deadalnix deadalnix at gmail.com
Tue Jun 21 01:01:09 UTC 2022


On Tuesday, 21 June 2022 at 00:33:24 UTC, Mike Parker wrote:
> On Monday, 20 June 2022 at 15:49:20 UTC, Paul Backus wrote:
>
>>
>> I'm not convinced the extra granularity is worth adding an 
>> entire new attribute for.
>
> My main motivation was the case of having a setter with a 
> contract that serves as a cheap invariant:
>
> ```d
> class Foo {
>     int _x;
>     void x(int newX)
>     in (newX < 1000)
>     { _x = newX; }
> }
> ```
>

I'm pretty sure x can be encapsulated in some struct here.



More information about the Digitalmars-d mailing list