[Issue 10876] foreach and remove over associative array causes invalid data to appear

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 23 14:16:28 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10876



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-08-23 14:16:26 PDT ---
(In reply to comment #2)
> N.B. you can only use .keys, not .byKey, because the latter also amounts to
> walking the data structure while it is being modified, which will cause
> problems. Using .keys is OK because it creates an array of keys (a snapshot of
> the set of keys at that point in time) before starting to modify the data
> structure.

Yeah, as I learned in Issue 10821.

Perhaps one could do an "!is null" check against the key if iterating via
.byKey and removing at the same time? Well anyway, the safest bet is to use
.keys.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list