First Draft: ref For Variable Declarations

Walter Bright newshound2 at digitalmars.com
Sat Apr 13 18:34:01 UTC 2024


On 4/13/2024 11:22 AM, Dukc wrote:
> This compiles and does nothing:
> 
> ```D
> @safe void main()
> {
>      foreach(ref el; 0 .. 5) el = 42;
> }
> ```

https://issues.dlang.org/show_bug.cgi?id=24499


> No problem - but the dip should explicitly say it's for local variables then, 
> not for variables in general.

The DIP does say:

"There doesn't appear to be a downside of using ref for such declarations, so by 
extension ordinary local variables should also benefit from being declared as ref."

Though it could be made more explicit.



More information about the dip.development mailing list