'auto' keyword

Salih Dincer salihdb at hotmail.com
Sun Mar 12 15:31:07 UTC 2023


On Sunday, 12 March 2023 at 13:07:58 UTC, DLearner wrote:
> Is it correct that this _single_ keyword is used to indicate 
> _two_ quite different things:
>
> 1. As a shorthand to make the type of the variable being 
> declared the same as the type on the right hand side of an 
> initial assignment.

The auto keyword is really helpful for shortening it.  But in at 
least 2 cases (one of which is interfaces) it should help the 
compiler.  For example, contrary to expected, it is dynamic array:

```d
auto arr = [ 1, 2, 3 ];
```

Moreover, `auto ref` or `ref auto` is needed in functions.

SDB at 79


More information about the Digitalmars-d-learn mailing list