First Draft: ref For Variable Declarations
Dennis
dkorpel at gmail.com
Wed Apr 17 16:51:41 UTC 2024
On Wednesday, 17 April 2024 at 14:29:17 UTC, Dukc wrote:
> If that was the case this DIP would be completely useless, as
> you could already do everything it enabled with `alias`.
I currently sometimes use pointers to alias members.
```D
// Inside struct LightOptimizer
void moveLightGlobal()
{
auto light = &this.scene.light;
light.pos += vec3(...);
}
void onMouseclick(ref GameState gs)
{
auto ui = &gs.ui;
ui.startDrag();
...
}
```
I'd prefer using `ref` since that's safer and enables opIndex
overloads, so this DIP seems like a nice addition to me. I tried
replacing those cases with alias but it errors:
```
Error: accessing non-static variable `scene` requires an instance
of `LightOptimizer`
```
More information about the dip.development
mailing list