Safe to remove AA elements while iterating over it via .byKeyValue?
Imperatorn
johan_forsberg_86 at hotmail.com
Sun Sep 27 14:05:19 UTC 2020
On Sunday, 27 September 2020 at 13:02:04 UTC, Per Nordlöw wrote:
> Is it safe to remove AA-elements from an `aa` I'm iterating
> over via aa.byKeyValue?
>
> I'm currently doing this:
>
> foreach (ref kv; aa.byKeyValue)
> {
> if (pred(kv.key))
> aa.remove(kv.key); // ok?
> }
> if (aa.length == 0)
> aa = null;
>
> Is there a better way?
What you could do is find all matches (pred) and remove range of
indices
More information about the Digitalmars-d-learn
mailing list