Associative Array of Const Objects?

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 28 02:03:26 PDT 2015


bitwise:

> class Test{}
>
> void main()
> {
> 	const(Test)[string] tests;
> 	tests["test"] = new Test();
> }
>
> This code used to work, but after upgrading to dmd 2.067, it no 
> longer does.
> --Error: cannot modify const expression tests["test"]
>
> How do I insert an item into an associative array of const 
> objects?

You meant to say "associative array with const objects as 
values". I think the short answer is that you can't. This is a 
breaking change, I think, it broke some of my code too. But 
perhaps something like Rebindable could be used.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list