On Sunday, 23 June 2024 at 21:50:37 UTC, Vladimir Marchevsky wrote:
On Sunday, 23 June 2024 at 13:29:21 UTC, Mike Parker wrote:
DIP1046, "ref For Variable Declarations", has been accepted:

https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1046.md

which reduces the complexity of the code, as long-winded global names get a shorthand

Does ref add anything compared to using an alias?..

`ref` will bind to lvalue expressions, e.g (from the DIP):

```d
ref int dark(ref int x, int i, int* q)
{
    ref m = *q;    // m refers to whatever q points to
    ...
}
```

`*q` is an expression, not a symbol. `ref` can bind to e.g. a struct field runtime value, or an lvalue returned from a function.

`alias` only allows giving new names for existing compile-time symbols.

Reply via email to