Array literals MUST be immutable.

Lars T. Kyllingstad public at kyllingen.NOSPAMnet
Wed Feb 17 01:32:02 PST 2010


Walter Bright wrote:
> Don wrote:
>> This is for me the last remaining D2 issue.
> 
> That would make it difficult to do things like:
> 
>   int*[] foo(int *p)
>   {
>     return [p, p + 1];
>   }
> 
> as all the elements of the literal would also have to be immutable. I 
> think you've made a good case, but there is also this issue.


Note his point (5).  It's trivial to add a function for creating mutable 
arrays to std.array.

   import std.array;

   int*[] foo(int* p)
   {
       return array(p, p+1);
   }

I think Don makes an excellent case. This needs to be fixed.

-Lars



More information about the Digitalmars-d mailing list