DIP1046, "ref For Variable Declarations", has been Accepted
Mike Shah
mshah.475 at gmail.com
Mon Jun 24 13:49:53 UTC 2024
On Monday, 24 June 2024 at 11:08:32 UTC, Nick Treleaven wrote:
> 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:
>>> [...]
>>
>>> [...]
>>
>> 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.
This is welcoming news! A nice addition for folks transitioning
over from C++ who are use to having this functionality.
More information about the Digitalmars-d-announce
mailing list