Container insertion and removal

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Mar 8 10:10:24 PST 2010


Joel C. Salomon wrote:
> On 3/6/2010 5:18 PM, Andrei Alexandrescu wrote:
>> Good question. In STL, invalidation roughly means undefined behavior if
>> you use it. With GC in tow, the concept could be significantly milder.
>> For example, reallocating an array would leave the old contents of the
>> array sort of around, just obsoleted and also depleted of meaningful
>> content if the data type has a destructor.
> 
> So it’s still a bug to use an invalidated iterator/range, and probably
> still has unusual (if no longer undefined) effects if you do follow it,
> but it (probably) won’t cause memory corruption.  Is that correct?

I'd think so. In SafeD, clearly there's no memory corruption so throwing 
or iterating over removed elements would be valid choices. In non-safe 
mode, the user should expect undefined behavior.

Andrei



More information about the Digitalmars-d mailing list