Safe to remove AA elements while iterating over it via .byKeyValue?

Per Nordlöw per.nordlow at gmail.com
Sun Sep 27 13:02:04 UTC 2020


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?


More information about the Digitalmars-d-learn mailing list