How to re-initialise an associative array.

Gary Willoughby dev at nomad.so
Wed Nov 6 08:41:17 PST 2013


On Wednesday, 6 November 2013 at 16:34:13 UTC, Daniel Davidson 
wrote:
> On Wednesday, 6 November 2013 at 16:15:36 UTC, Gary Willoughby 
> wrote:
>> A simple request but i'm failing hard. How do i re-init an 
>> associative array? This is obviously not the way:
>>
>> 	import std.stdio;
>>
>> 	void main(string[] args)
>> 	{
>> 		int[string] x;
>>
>> 		x["hello"] = 1;
>> 		x["world"] = 2;
>>
>> 		writefln("%s", x);
>>
>> 		x = new int[string];
>>
>> 		writefln("%s", x); // Should be empty.
>> 	}
>
> x.clear();

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


More information about the Digitalmars-d-learn mailing list