Associative arrays give compile error

Steven Schveighoffer schveiguy at yahoo.com
Wed Oct 6 04:33:02 PDT 2010


On Tue, 05 Oct 2010 22:02:30 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Denis Koroskin:
>
>> Compute mutable copy and then cast to immutable. Am I missing something?
>
> That's possible. But it's an exceptionally dirty thing, I am not sure it  
> works in SafeD. A well designed const system has to offer a more clean  
> solution :-) Do you agree?

Casting to immutable is the only way to create such a beast.  The best way  
to ensure as few bugs as possible is to create the object you wish to be  
immutable in a function, and cast at the end before returning.  This at  
least encapsulates the dirtiness in one function (which would probably be  
marked @trusted).

You can also use assumeUnique (which I'm guessing is there so it can be  
called in safeD?).

-Steve


More information about the Digitalmars-d-learn mailing list