Do you have a better way to remove element from a array?

IchorDev zxinsworld at gmail.com
Sun Aug 11 21:15:39 UTC 2024


On Sunday, 11 August 2024 at 06:04:08 UTC, mw wrote:
> ```
>   array = array.remove(index);  // return a new container
> ```

I was looking through Phobos to find what might be an appropriate 
replacement for `remove`. I read `remove`’s documentation, and 
there it says it removes the element in-place, so I checked the 
implementation and that seems to be true. It moves everything 
over and then returns the array with the last element sliced off. 
So, for removing an element from the start of the array you’d be 
better off using slicing (because it just changes a pointer 
rather than doing a huge copy) but otherwise it’s pretty 
efficient.


More information about the Digitalmars-d-learn mailing list