<div dir="ltr"><div>Here's what I'd like in phobos:</div><div><br></div><div>void eraseInPlace(T)(ref T a, size_t index, size_t n=1) </div><div>if(isArray!T){</div><div><span class="" style="white-space:pre"> </span>enum s=typeof(a[0]).sizeof;</div><div>   auto ptr=a.ptr+index;</div><div>   import core.stdc.string:memmove;</div><div>   memmove(ptr,ptr+n,(a.length-(index+n))*s);</div><div>   a.length-=n;</div><div>}</div><div><br></div><div>unittest{</div><div><span class="" style="white-space:pre">    </span>auto a=[0,1,2,3,4,5,6];</div><div><span class="" style="white-space:pre">    </span>a.eraseInPlace(1,2);</div><div><span class="" style="white-space:pre">       </span>import std.conv:text;</div><div><span class="" style="white-space:pre">      </span>assert(a==[0,3,4,5,6], text(a));</div><div>}</div><div><br></div><div>(obviously it assumes no aliasing)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 16, 2014 at 6:59 PM, Timothee Cour <span dir="ltr"><<a href="mailto:thelastmammoth@gmail.com" target="_blank">thelastmammoth@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:13px">Is there a phobos way to do eraseInPlace (eg with optimization using memmove where appropriate) ? (akin to insertInPlace)</span><br></div>
</blockquote></div></div>