remove from array

BCS ao at pathlink.com
Tue Feb 27 16:36:31 PST 2007


Reply to Bill,

> Using ~ works, but it's slower than using memmorve (what's in Cashew
> utils).
> 

Good point. OTOH if you want to keep the source untouched, you need to allocate 
anyway. Thinking of that, a dup is needed to keep things consistent

T[] Remove(T)(T[] arr, int i)
{
return i==arr.length-1 ? arr[0..$-1].dup : arr[0..i] ~ arr[i+1 .. $];
}





More information about the Digitalmars-d mailing list