how to manage the list of immutable objects

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 14 04:44:37 PDT 2015


On 7/14/15 7:12 AM, aki wrote:
> On Tuesday, 14 July 2015 at 10:46:42 UTC, Andrea Fontana wrote:
>> Trying on http://dpaste.dzfl.pl/ I don't see that error.
>> Maybe you mean "const" and not "immutable" ?

Wow, that needs updating. Latest version is 2.065 from February 2014, 
and the git version is from March 2013!

>
> I used:
> DMD32 D Compiler v2.067.1 on Windows8
> I believe there are no typo because it is copy-pasted.
> I noticed I can use cast.
> cast()(map[name]) = cast()this;
> Are there any better solution?

Cast is not a good idea. What you need is a rebindable class reference 
to an immutable class. For that, the official recommendation is to use 
std.typecons.Rebindable. Perhaps it works for you:

static Rebindable!(immutable(Foo))[string] map

-Steve


More information about the Digitalmars-d-learn mailing list