Associative array references
Maxim Fomin
maxim at maxim-fomin.ru
Mon Dec 2 06:57:28 PST 2013
On Monday, 2 December 2013 at 13:30:44 UTC, Atila Neves wrote:
> 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
I would say it is consequence of current implementation, and,
taking into account ongoing efforts to rewrite AA implementation,
this special detail of null AA behavior may one day be gone.
More information about the Digitalmars-d-learn
mailing list