Immutable array initialization in shared static this

Ali Çehreli acehreli at yahoo.com
Fri Jul 13 12:14:39 PDT 2012


On 07/13/2012 11:09 AM, Era Scarecrow wrote:

 > I would think the best solution is to create a mutable local version,
 > and then assign the immutable global one when you are done.

And there wouldn't be a copy with std.exception.assumeUnique:

import std.exception;

private immutable(int[]) constants;

shared static this()
{
     int[] local;
     local.length = 10;
     local[0] = 123;
     constants = assumeUnique(local);
}

void main()
{
     assert(constants[0] == 123);
}

Ali

-- 
D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html



More information about the Digitalmars-d-learn mailing list