How do I store an immutable value into a mutable associative array?

PlatisYialos leonidasklados at gmail.com
Tue Nov 6 09:23:40 PST 2012


Here's a test file, with the compiler messages obtained.  I also 
tried introducing an alias with similar results to the second 
attempt below.

1    module test;
2
3    void noparens() {
4      immutable char[char] aMap;
5      aMap['a'] = 'b';
6
7      /* Compiler error messages
8         ./src/test.d(5): Error: aMap['a'] isn't mutable
9         ./src/test.d(5): Error: variable test.noparens.aMap 
cannot modify immutable
10      */
11   }
12
13   void withparens() {
14     immutable(char)[char] aMap;
15     aMap['a'] = 'b';
16
17     /* Compiler error messages
18        ./src/test.d(15): Error: aMap['a'] isn't mutable
19      */
20   }




More information about the Digitalmars-d-learn mailing list