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?

If you're okay with the allocation that comes with it:

foreach(k; aa.keys)
{
    if(pred(key)) aa.remove(key);
}



Reply via email to