On Sat, Dec 17, 2005 at 07:58:42PM +0200, Martin Vermeer wrote: > 2) BTW is it really true that pushing something to the > back of a <vector> (or other container), forcing a copy in memory to a > new location (?) will invalidate any iterators defined earlier to point > into it? This feels almost like assembly :-(
It will invalidate if the vector actually grows. One can prevent it to a certain degree with 'reserve'. I.e. if you have 10 elements i8n a vector, than reserve to 20, then obtain iterators, then push_back 10- more items you are guaranteed that the freshly obtained iterators are still vaild. If you push_back the eleventh element you aren't guaranteed anyything anymore. This is about the only reason I am rather fond of using integer offsets as 'stable iterator replacement' in case of vectors that may grow. Andre'