How to re-initialise an associative array.

Daniel Davidson nospam at spam.com
Wed Nov 6 08:49:43 PST 2013


On Wednesday, 6 November 2013 at 16:41:19 UTC, Gary Willoughby 
wrote:
>
> I looked at that but apparently it leaves the array in an 
> unsafe state.
>
> Source: 
> http://forum.dlang.org/thread/iu3ll6$2d48$1@digitalmars.com

Is that still the case? The following seems to work just fine. 
Maybe Kenji has been working his magic :-)  ?

import std.stdio;

void main() {
   string[string] foo = ["a" : "a", "b" : "B"];
   writeln(foo);
   foo.clear();
   writeln(foo);
   writeln(foo.length);
   foo["x"] = "this is a test";
   writeln(foo);
   writeln(foo.length);
}
-----------------------------------------
["a":"a", "b":"B"]
[]
0
["x":"this is a test"]
1


More information about the Digitalmars-d-learn mailing list