`restricted` member variables

Dom Disc dominikus at scherkl.de
Mon Jun 20 13:59:39 UTC 2022


On Monday, 20 June 2022 at 11:04:16 UTC, Mike Parker wrote:
> I'm seeing it more granularly than class-level and down to the 
> function level.
>
> After some spitballing, here's something I like:
>
> ```d
> class E
> {
>    restricted int _y;
>    restricted(_y) void y(int newY) { _y = newY; }
> }
> ```
>
> A restricted member variable `_y` can only be accessed in 
> functions explicitly marked `restricted(_y)`. No other member 
> function can access that variable, and therefore neither can 
> anything in the broader module.

This is EXACTLY what I suggested (but I called it @hidden int _y 
and the function UDA @sees(_y)).
I didn't even received a single response :-(


More information about the Digitalmars-d mailing list