Re: Under what circumstances can the STL move a vector?

From: Richard Thompson (
Date: 02/06/05

Date: Sun, 06 Feb 2005 17:07:40 +0000

[posted after my previous reply to myself, which hasn't turned up yet]

After re-reading the first set of replies, and looking at my test code
(just posted), it seems to me that some of you have already answered
the question. When I push a new element onto the back of the heap (the
second call to 'create_heap_item') then the heap is presumably
re-allocated, because it's size has just doubled. In the process, the
vector in the first element on the heap is moved, thus invalidating
l1rbegin and l1rend.

I had assumed, somewhere at the back of my mind, that the 'control
structure' (?) for the first vector on the heap would move, but that
the 'real' vector, which is presumably stored somewhere else on the
system heap, wouldn't move. Presumably this is wrong? Are the vector
elements actually stored in struct X, and moved with struct X?

It seems to me that if you're writing library code (as I am), and you
don't know how your classes are going to be used, then you can *never*
rely on your iterators remaining valid? Doesn't this severely restrict
the use of the STL?