std.collection - changing the collection while iterating

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 21 16:02:43 PDT 2015


While I work on making std.allocator better, here's some food for 
thought regarding std.collection.

Consider a traditional container with reference semantics, Java-style. 
Regarding changing the collection (e.g. adding/removing elements) while 
iterating, we have the following possibilities:

1. Leave it undefined, like the STL does. Probably this is too extreme.

2. Throw an exception if a remove is attempted while ranges exist. This 
works but it's conservative - e.g. it throws even if those ranges are 
never to be used again etc.

3. Allow the removal but throw from the ranges if there's any attempt to 
use a range following a remove.

4. Make it work such that ranges continue to be valid post removal. 
Perhaps this is on the inefficient side.


Andrei


More information about the Digitalmars-d mailing list