Auto returntype

Para email at address.tld
Sun May 19 23:10:08 UTC 2019


On Sunday, 19 May 2019 at 22:57:50 UTC, Alex wrote:
> One thing D does not have in it's type system is the ability to 
> infer the return type from the usage:
>
> O[] foo() { O[] x; return x; }
> byte[] q = foo();
>
> The idea is that O is determined to be byte. The compiler looks 
> at the assignment and realizes that we want foo to return a 
> byte array and that O then must be a byte.
>
> This avoids having to specify the type in foo
> e.g., we could have
>
> auto foo(O)() { O[] x; return x; }
> auto q = foo!byte();
Unless I have very poor reading comprehension, which I might, I 
believe this is already a feature: 
https://dlang.org/spec/function.html#auto-functions


More information about the Digitalmars-d mailing list