Removing elements from dynamic arrays?
Ali Çehreli
acehreli at yahoo.com
Tue Apr 5 02:55:22 UTC 2022
On 4/4/22 16:15, Enjoys Math wrote:
> https://forum.dlang.org/post/eih04u$1463$1@digitaldaemon.com
2006 is a long time ago. :)
> A version of the code that takes `T which` as a parameter instead of
> `int index`.
>
> ```
> // remove an item from an array
> template drop(T)
> {
> T drop( inout T[] arr, T which )
I bet 'inout' back then was the equivalent of 'ref' today.
Today, I would use remove():
https://dlang.org/library/std/algorithm/mutation/remove.html
And where applicable, SwapStrategy.unstable should reduce the number of
elements moved.
Ali
More information about the Digitalmars-d-learn
mailing list