开发者

D nested functions type inference

开发者 https://www.devze.com 2023-01-26 04:47 出处:网络
Does anyone know if subj will be implemented? At le开发者_如何学运维ast, auto storage class for them?

Does anyone know if subj will be implemented? At le开发者_如何学运维ast, auto storage class for them? Thanks!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消