I believe that I was able to do this in an earlier version of the language, and indeed, the code that I wrote a few months ago, which compiled perfectly, now does not compile. Example:
immutable(X)[int] myhash; myhash[5] = some_immutable_X;
Now, however, dmd complains about
Error: cannot modify immutable expression myhash[5]
I experimented with some other possible syntax without success (for example, (immutable X) [int]). There seems to be no more way to declare that the hash itself is volatile, but the content is not? This seems like a fairly common use case: a data structure for storing links to things that should not be changed. Can anyone figure this out?
source share