Associative array references
Atila Neves
atila.neves at gmail.com
Mon Dec 2 05:30:40 PST 2013
Bug or feature? This one caught me by surprise:
void main() {
{
int[string] aa[string];
aa["foo"]["bar"] = 1;
assert(aa["foo"]["bar"] == 1); //ok
auto aa2 = aa;
aa2["boo"]["dar"] = 2;
assert(aa["foo"]["bar"] == 1); //ok
}
{
int[string] aa[string]; //not set to anything yet
auto aa2 = aa;
aa2["boo"]["dar"] = 2;
assert(aa["foo"]["bar"] == 1); //oops
}
}
It seems that assigning an AA to another makes both point at the
same data only if the first array has data to begin with. Is that
the expected behaviour?
Atila
More information about the Digitalmars-d-learn
mailing list