Create an array with immutable elements
    Era Scarecrow 
    rtcvb32 at yahoo.com
       
    Thu Jun 14 17:08:32 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.
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;
}
    
    
More information about the Digitalmars-d-learn
mailing list