clear array

Damian damianroyday at gmail.com
Mon Oct 15 17:57:46 PDT 2012


On Tuesday, 16 October 2012 at 00:47:44 UTC, H. S. Teoh wrote:
> On Tue, Oct 16, 2012 at 02:33:03AM +0200, Damian wrote:
>> I know this is a bit of a dumb question and I have searched 
>> and not
>> found anything concrete surprisingly :/
>> 
>> Does D have a built-in way to clear arrays dynamic and static?
>> I don't want to iterate over every element and set a default 
>> value.
>> 
>> In C++ I would just use memset, I don't know if I should be 
>> using
>> this for D?
>
> What about:
>
> 	import std.algorithm;
> 	void main() {
> 		int[] arr = [1,2,3,4];
>
> 		fill(arr, 0);
> 		writeln(arr);	// should print [0,0,0,0]
> 	}
>
> ?
>
>
> T

This does not handle multi-dimensional arrays


More information about the Digitalmars-d-learn mailing list