Re: STL slist/map containers concurrent/thread-safe access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Kalaky,

#1.  Please do not cross post to GCC-help and GCC lists.

#2.  GCC@xxxxxxxxxxx is not an appropriate forum for your question.

#3.  GCC-Help@xxxxxxxxxxx is not an appropriate forum for your question.

#4.  Your question is a general C++ question, not a GCC question.

> Given that removing/inserting elements from a map/slist/whatever does
> not invalidate iterators to list elements, it is safe to use the
> element that the iterator "points" to ?

The rules for iterator invalidation are tightly dependent on the container
involved.  I recommend reading the ISO 14882 standard very carefully about
what STL containers guarantee about their iterators.  (I always have to look
them up myself -- I tend to pessimistically over-assume that my iterators
are invalidated more often then they really are in actuality.)

I'm pretty sure that removing an element from a container will cause any
iterator pointing to that element to become invalidated, for all containers.

How do you have an iterator to an element in a container, when that element
hasn't been inserted into the container yet?

*AFTER* an element is inserted into a container, and then you acquire an
iterator to that element, I presume that iterator properly refers to that
element.

I recommend you use a "Safe STL" for your development.  It will help you
discover problematic STL usage in your code.

Here are some "safe STL" implementations:
http://www.horstmann.com/safestl.html
http://www.stlport.org/
http://gcc.gnu.org/onlinedocs/libstdc++/debug.html

Good luck!
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux