|
Boost Users : |
From: Christopher Woods (cwoods_eol_at_[hidden])
Date: 2007-05-24 14:01:35
Daniel Gehriger wrote:
>
> I happen to work with custom containers whose iterators are invalidated when
> certain member functions are called on the contained objects. So I typically
> use a loop pattern as follows:
>
> -------------------
> 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
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