How to re-initialise an associative array.

Gary Willoughby dev at nomad.so
Wed Nov 6 09:14:54 PST 2013


On Wednesday, 6 November 2013 at 16:49:44 UTC, Daniel Davidson 
wrote:
> 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

I'm not taking the chance and currently using:

x = (int[string]).init;


More information about the Digitalmars-d-learn mailing list