Create an array with immutable elements

Roman D. Boiko rb at d-coding.com
Thu Jun 14 17:10:27 PDT 2012


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.

More specifically, given

auto names = ["ab", "c", "def"] ~ getMoreNames();

retrieve

[Node("ab"), Node("abc"), Node("abcdef"), ...]

where Node is an immutable struct created dynamically, possibly 
with usage of some accumulating variable (in this case, a string 
concatenating previous values).

But an answer to the first question should be enough, this 
example is just for clarity.


More information about the Digitalmars-d-learn mailing list