Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D nested functions type inference

Does anyone know if subj will be implemented? At least, auto storage class for them? Thanks!

like image 653
Target-san Avatar asked Sep 16 '26 11:09

Target-san


1 Answers

There are various problem with auto functions in general, so it could very well be that you can't do

void main()
{
    auto bar() { return "hello world"; }

    writeln(bar());
}

because of a bug with auto rather than it being as designed. I'm not sure what the exact plans for that are, though I would think that you would supposed to be able to use auto as the return type of a nested function. There is an enhancement request on it in either case.

However, regardless of whether auto works with nested functions, you can declare a delegate in a similar manner:

void main()
{
    auto bar = () { return "hello world"; };

    writeln(bar());
}

So, the basic functionality is still there, even if the exact syntax that you were looking for doesn't currently work.

like image 144
Jonathan M Davis Avatar answered Sep 19 '26 20:09

Jonathan M Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!