associative array: unexpected results after static initialization
kdevel
kdevel at vogtner.de
Thu Nov 30 23:50:13 UTC 2017
This program
```
void aa_stat(T, U) (T[U] aa)
{
import std.stdio;
writefln ("aa : %s", aa);
writefln ("aa.length : %d", aa.length);
writefln ("aa.keys : %s", aa.keys);
writefln ("aa.values : %s", aa.values);
foreach (k, v; aa)
writeln (k, ": ", v);
}
void main ()
{
string[int] aa = [
0: "null",
0: "eins"
];
aa.aa_stat;
}
```
produces this output:
aa : [0:"eins", ]
aa.length : 2
aa.keys : [0, 32767]
aa.values : ["eins", ""]
0: eins
I would have expected either a compile time or a runtime error or
this result:
aa : [0:"eins"]
aa.length : 1
aa.keys : [0]
aa.values : ["eins"]
0: eins
What's happening here?
More information about the Digitalmars-d-learn
mailing list