to invalidate a range

Steven Schveighoffer schveiguy at yahoo.com
Fri Aug 12 13:29:14 PDT 2011


On Fri, 12 Aug 2011 15:54:53 -0400, Ellery Newcomer  
<ellery-newcomer at utulsa.edu> wrote:

> in std.container, the stable* container functions advocate that they do  
> not invalidate the ranges of their containers. What does it mean to  
> invalidate a range?

Say for example, you are iterating a red black tree, and your current  
"front" points at a certain node.  Then that node is removed from the  
tree.  That range is now invalid, because the node it points to is not  
valid.

What happens when you use an invalidated range?  Well, we could implement  
something that throws an exception, but that's an efficiency problem.  I  
contemplated doing this for debug mode in dcollections, I probably still  
will.

Another example of an invalidated range, let's say you have a hash map.   
The range has a start and a finish, with the finish being iterated after  
the start.  If you add a node, it could cause a rehash, which could  
potentially put the finish *before* the start!

However, the same hash implementation could potentially define a stable  
add, which is guaranteed not to rehash the map, even when it exceeds the  
rehash threshold :)

-Steve


More information about the Digitalmars-d-learn mailing list