Boost logo

Boost Users :

From: Daniel Gehriger (gehriger_at_[hidden])
Date: 2007-05-24 14:13:16


Christopher Woods wrote:
>
> Daniel Gehriger wrote:
>> -------------------
>> for (Coll::iterator it = col.begin(); it != col.end(); /* noop */)
>> {
>> Coll::value_type& o = *(it++);
>> o.destroy();
>> }
>> -------------------
>
> Aren't you asking for trouble here? If the call into a member function
> of a contained object invalidates iterators of the container that holds
> it and you're in the process of iterating over that container and
> calling such a function, then how do you know that the new value for
> 'it' is still points to a valid address within the container itself?
>
> -Chris
>

I wasn't precise enough: The call to the member function only invalidates
the iterators pointing to the object. All other iterators remain valid.

- Daniel

-- 
View this message in context: http://www.nabble.com/BOOST_FOREACH-and-iterating-by-reference-tf3806531.html#a10789561
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net