Phobos function to remove all occurances from dynamic array?
Lance Bachmeier
no at spam.net
Wed May 1 01:24:55 UTC 2024
On Wednesday, 1 May 2024 at 01:09:33 UTC, Liam McGillivray wrote:
> This is presumably such a common task that I'm surprised it
> isn't easy to find the answer by searching;
>
> Is there a standard library function that removes all elements
> from a dynamic array that matches an input argument?
>
> In `std.array` there's the `replace` function which is supposed
> to replace all occurrences that match an input with another. It
> seems to work as described on strings, but I get compiler
> errors when using it on other array types. I've tried using it
> to replace occurrences of a certain object in an array with
> `[]` in order to remove all occurrences, but it's not allowed.
>
> Is there a Phobos function that does what I want? It would be
> crazy if there isn't.
Does filter do what you need?
https://dlang.org/phobos/std_algorithm_iteration.html#.filter
More information about the Digitalmars-d-learn
mailing list