Boost logo

Boost Users :

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


Eric Niebler wrote:
>
> Are you saying that calling o.destroy() causes "it" to be invalidated?
> This is bad practice. If that's not the case, then vanilla FOREACH
> should meet your needs. Please correct me if I've misunderstood your
> situation.
>

Yes, exactly. I wouldn't do that usually, but the collection is in fact a
database table, and I use the iterators to access the records. Each record
contains a field with the index of the next record (basically a
singly-linked list). Destroying the record therefore invalidates the
iterator pointing to the record. Pre-incrementing, however, works fine.

A solution would be to cache all indices when accessing the collection, but
I can't afford the overhead for this.

Maybe this case is too specialized for Boost and doesn't warrant the
inclusion of a BOOST_FOREACH_PRE macro in the library.

- Daniel

-- 
View this message in context: http://www.nabble.com/BOOST_FOREACH-and-iterating-by-reference-tf3806531.html#a10791982
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