clear array

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Oct 15 17:49:44 PDT 2012


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

-- 
My program has no bugs! Only undocumented features...


More information about the Digitalmars-d-learn mailing list