On Friday, 15 June 2012 at 00:08:33 UTC, Era Scarecrow wrote:
On Thursday, 14 June 2012 at 23:57:36 UTC, Roman D. Boiko wrote:
immutable struct Node{ string s; }
Node[] f()
{
Node[] arr = ...?
return arr;
}
How to fill an array, if its elements are immutable? I want to
assign values calculated by some function.
I recall this in TDPL, you can append to an array as it doesn't
change it's contents, only the range the array holds... So...
Node[] f()
{
immutable(Node)[] arr;
arr ~= Node("something"); //should work?
return arr;
}
That might be inefficient for large arrays. (In my case, arrays
are small.)
Would array appender work here? I guess it should.