eraseInPlace (eg using memmove)?

Timothee Cour via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Dec 16 19:48:27 PST 2014


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 <thelastmammoth at gmail.com>
wrote:
>
> Is there a phobos way to do eraseInPlace (eg with optimization using
> memmove where appropriate) ? (akin to insertInPlace)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20141216/3690f56d/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list