AA with immutable values

Jonathan M Davis jmdavisProg at gmx.com
Sun Jun 24 05:08:28 PDT 2012


On Sunday, June 24, 2012 13:57:44 Roman D. Boiko wrote:
> immutable(SomeClass)[S] _map;
> _map[S.init] = null; // doesn't compile since _map[S.init] is
> immutable
> 
> My current workaround is:
> immutable(SomeClass)*[S] _map;
> _map[S.init] = [null].ptr;
> 
> But this introduces an additional level of indirection in a
> performance-critical part of my code.
> 
> Probably I could cast away immutable before storing, and cast
> back to immutable after retrieving. But I would be more happy
> without these two casts. (By the way, is it correct that this way
> would be more efficient?)
> 
> Is there any other way to put immutable values into a dictionary?

Use std.typecons.Rebindable.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list