On Saturday, 13 May 2017 at 18:32:16 UTC, Lewis wrote:
import std.random; import std.stdio;int[4] testfunc(int num) @nogc { return [0, 1, num, 3]; } int main() { int[4] arr = testfunc(uniform(0, 15)); writeln(arr); return 0; }I've read a bunch of stuff that seems to indicate that array literals are always heap-allocated, even when being used to populate a static array. However, testfunc() above compiles as @nogc. This would indicate to me that D does the smart thing and avoids a heap allocation for an array literal being used to populate a static array. Is all the old stuff I was reading just out-of-date now?
1D arrays it doesn't, 2D or higher it does.
