Tips and Tricks for D
Tom S
h3r3tic at remove.mat.uni.torun.pl
Mon Jul 3 07:12:10 PDT 2006
Errm... array.dup is evil, since it causes an alloc -> GC stalls anyone ?
How about this ?
void removeNth(T)(inout T[] array, int n) {
if (n < array.length - 1) {
memmove(&array[n],
&array[n+1],
(array.length - n - 1) * T.sizeof);
}
array.length = array.length - 1;
}
then just:
foreach (n; removeThese)
{
n = array.length - n;
array.removeNth(n);
}
--
Tomasz Stachowiak /+ a.k.a. h3r3tic +/
More information about the Digitalmars-d-learn
mailing list