Static Array Idiom not working anymore.

SrMordred patric.dexheimer at gmail.com
Tue Jun 12 14:35:33 UTC 2018


this idiom for creating static array used to work, but they are 
failing now.
What changed and whats the alternative?

(from 
https://p0nce.github.io/d-idioms/#@nogc-Array-Literals:-Breaking-the-Limits)

T[n] s(T, size_t n)(auto ref T[n] array) pure nothrow @nogc @safe
{
     return array;
}

void main() @nogc
{
     int[] myDynamicArray = [1, 2, 3].s; // Slice that static 
array which is on stack
}

//output:
Deprecation: slice of static array temporary returned by s([1, 2, 
3]) assigned to longer lived variable myDynamicArray


More information about the Digitalmars-d-learn mailing list