"inline" conversion of array to immutable

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 22 05:10:15 PDT 2016


On 22.04.2016 13:46, Jeff Thompson wrote:
> The function literal also works if I add
> "function int[]()":
> void main(string[] args) {
>    immutable int[] array = function int[]() {
>      int[] result = new int[10];
>      result[0] = 1;
>      return result;
>    }();
> }
>

I take it you're on 2.070 or older then. 2.071 accepts it without 
`function`, which seems a bit inconsistent when I think about it.

Anyway, just `function` should be enough. But of course you can specify 
return type and empty parameter list if you want.


More information about the Digitalmars-d-learn mailing list