I'm iterating through map entries, and occasionally, I delete the key I'm currently on. That is:
for addr, shutdown := range children {
if shouldShutdown(addr) {
close(shutdown)
del(children[addr])
}
}
The spec at
http://golang.org/ref/spec#For_statements states that deleting entries not already iterated over is safe, and behaves as you'd expect. However, unless I missed it, it doesn't state whether or not it is safe to delete the current entry, as I do above.
Given Go's sensible design, I'm guessing that it was a property too trivial to state, but C++ has made me paranoid about how iterators react to mutation.
So, is the above defined behavior? If so, would it be worth explicitly pointing out in the spec?
- Dave