digitalmars.D.learn - Associative array references
- Atila Neves (21/21) Dec 02 2013 Bug or feature? This one caught me by surprise:
- Maxim Fomin (4/25) Dec 02 2013 I would say it is consequence of current implementation, and,
- bearophile (6/7) Dec 02 2013 Don't mix C style array definitions with D style ones :-) Always
- Atila Neves (2/7) Dec 02 2013 How would that go in this case?
- bearophile (8/9) Dec 02 2013 An example usage:
- Atila Neves (4/13) Dec 03 2013 Oh. That makes sense. Doh!
- Jesse Phillips (4/8) Dec 02 2013 You've been hit by the null associative array not being the same
- Atila Neves (2/11) Dec 03 2013 Sigh. If at least there was a way to declare them empty...
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
Dec 02 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? AtilaI 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.
Dec 02 2013
Atila Neves:int[string] aa[string];Don't mix C style array definitions with D style ones :-) Always use the D-style, unless you are porting C code (and refactor it later). Bye, bearophile
Dec 02 2013
On Monday, 2 December 2013 at 15:13:48 UTC, bearophile wrote:Atila Neves:How would that go in this case?int[string] aa[string];Don't mix C style array definitions with D style ones :-) Always use the D-style, unless you are porting C code (and refactor it later).
Dec 02 2013
Atila Neves:How would that go in this case?An example usage: void main() { int[float][string] aa; aa["foo"][1.5] = 1; } Bye, bearophile
Dec 02 2013
On Monday, 2 December 2013 at 16:52:51 UTC, bearophile wrote:Atila Neves:Oh. That makes sense. Doh! I guess I was focussing on "key to AA of..." and that's why I wrote it that way.How would that go in this case?An example usage: void main() { int[float][string] aa; aa["foo"][1.5] = 1; } Bye, bearophile
Dec 03 2013
On Monday, 2 December 2013 at 13:30:44 UTC, Atila Neves wrote: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? AtilaYou've been hit by the null associative array not being the same as an empty associative array. See discussion: http://forum.dlang.org/post/wovnuggqtscsbgnjcpua forum.dlang.org
Dec 02 2013
On Tuesday, 3 December 2013 at 03:14:46 UTC, Jesse Phillips wrote:On Monday, 2 December 2013 at 13:30:44 UTC, Atila Neves wrote:Sigh. If at least there was a way to declare them empty...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? AtilaYou've been hit by the null associative array not being the same as an empty associative array. See discussion: http://forum.dlang.org/post/wovnuggqtscsbgnjcpua forum.dlang.org
Dec 03 2013