foreach AA key char[] type change

Steven Schveighoffer schveiguy at yahoo.com
Sat Jun 5 18:05:54 PDT 2010


On Sat, 05 Jun 2010 20:42:43 -0400, bearophile <bearophileHUGS at lycos.com>  
wrote:

> Do you know why this D2 program prints  const(char)[]  instead of   
> char[] ?
>
> import std.stdio: writeln;
> void main() {
>     int[char[]] data = [cast(char[])"foo" : 1];
>     foreach (key, val; data)
>         writeln(typeid(typeof(key)));
> }

Probably because you aren't allowed to change keys for AAs.  Passing the  
key as a char[] type would allow that.

Although I wasn't aware the compiler did that...

-Steve


More information about the Digitalmars-d-learn mailing list