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

Per Nordlöw per.nordlow at gmail.com
Mon Sep 28 10:10:10 UTC 2020


On Monday, 28 September 2020 at 10:01:23 UTC, ikod wrote:
> Is it specific to some types? What if collection supports 
> stable "foreach"?

Yes it depends on how collection members (such as insert, find, 
replace, erase, etc) are implemented.

I presume we need attributes on mutating collection members that 
describes if the operation invalidates ranges or not.

It is relatively simple to implement checks for range 
invalidation at run-time. This is basically Rust-style borrow 
checking at run-time instead of compile-time.

In C++ this is called "iterator invalidation". This attributes 
are not formally defined in code but part of the documentation.


More information about the Digitalmars-d-learn mailing list