remove from array
Thorsten
toki782 at usenet.cnntp.org
Tue Feb 27 15:46:47 PST 2007
> <totaly untested code>
>
> T[] Remove(T)(T[] arr, int i)
> {
> return i==arr.length-1 ? arr[0..$-1] : arr[0..i] ~ arr[i+1 .. $];
> }
Sorry, I tried that, and it is too expensive !!
Because it creates about 3 temporary instances.
I would say :
void Remove(T)(inout T[] arr, int i)
{
for(uint j = i;j < arr.length-1;++j)
arr[j] = arr[j+1];
arr.length = arr.length - 1;
}
can someone accelerate this ???
More information about the Digitalmars-d
mailing list