www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - clear()

reply Dr.Smith <iam notfar.com> writes:
To empty many arrays of various types, rather than:

clear(arr1);
clear(arr2);
...
clear(arrN);

is there something like:

clear(ALL);

Also, after "clear(arr)", will "arr ~= value" assign starting from element 0?
Mar 25 2011
next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Fri, 25 Mar 2011 15:10:44 -0400, Dr.Smith <iam notfar.com> wrote:

 To empty many arrays of various types, rather than:

 clear(arr1);
 clear(arr2);
 ...
 clear(arrN);

 is there something like:

 clear(ALL);
Not sure what this would do. Clear all arrays? That isn't possible.
 Also, after "clear(arr)", will "arr ~= value" assign starting from  
 element 0?
Yes. -Steve
Mar 25 2011
prev sibling parent reply Kai Meyer <kai unixlords.com> writes:
On 03/25/2011 01:10 PM, Dr.Smith wrote:
 To empty many arrays of various types, rather than:

 clear(arr1);
 clear(arr2);
 ...
 clear(arrN);

 is there something like:

 clear(ALL);
No, but perhaps you can do a: foreach(a; ALL) a.clear() But that would require you having an iterable sequence that contains all of your arrays, which may or may not be worth your time to explore.
 Also, after "clear(arr)", will "arr ~= value" assign starting from element 0?
Yes
Mar 28 2011
parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
On Mon, 28 Mar 2011 16:57:17 +0200, Kai Meyer <kai unixlords.com> wrote:

 On 03/25/2011 01:10 PM, Dr.Smith wrote:
 To empty many arrays of various types, rather than:

 clear(arr1);
 clear(arr2);
 ...
 clear(arrN);

 is there something like:

 clear(ALL);
No, but perhaps you can do a: foreach(a; ALL) a.clear()
That should probably be foreach ( a; ALL ) clear( a ); -- Simen
Mar 28 2011