Here's what I'd like in phobos:
void eraseInPlace(T)(ref T a, size_t index, size_t n=1)
if(isArray!T){
enum s=typeof(a[0]).sizeof;
auto ptr=a.ptr+index;
import core.stdc.string:memmove;
memmove(ptr,ptr+n,(a.length-(index+n))*s);
a.length-=n;
}
unittest{
auto a=[0,1,2,3,4,5,6];
a.eraseInPlace(1,2);
import std.conv:text;
assert(a==[0,3,4,5,6], text(a));
}
(obviously it assumes no aliasing)
On Tue, Dec 16, 2014 at 6:59 PM, Timothee Cour thelastmamm...@gmail.com
wrote:
Is there a phobos way to do eraseInPlace (eg with optimization using
memmove where appropriate) ? (akin to insertInPlace)