iterator stability for containers

Steven Schveighoffer schveiguy at gmail.com
Mon Sep 21 15:52:03 UTC 2020


On 9/21/20 11:28 AM, ikod wrote:
> Hello,
> 
> I'd like to know if there are any iterator stability rules for dlang 
> containers?
> For example iterator over emsi containers unrolled list - does it 
> provide any stability warranties?
> 
> Or any other containers?

In dcollections (which is over 10 years past bitrotting), a major focus 
of mine was to ensure stability when possible.

Therefore, I had a few nice properties:

1. cursors were never invalidated by removal or addition of items.
2. ranges could be invalidated, but for certain containers, ranges would 
be invalidated only if the items being removed were the endpoints of the 
ranges.
3. Removing items from a hash based container wouldn't rehash (to avoid 
iteration issues).
4. All containers supported removal while iterating via a special 
foreach mechanism.

Honestly, my impetus for creating dcollections was to reproduce some of 
the nice features of iterators in C++, including removal while iterating.

-Steve


More information about the Digitalmars-d mailing list