R
Richard Herring
In message
Iterate through every copy of every iterator ever generated from that
container, to see if it references the region that's about to be
invalidated?
But physically it need not: see implementations where
vector<T>::iterator is implemented as plain T*.
Old said:unsigned char before[ sizeof( std::vector<int>::iterator ] ;
memcpy( before, &iter, sizeof( std::vector<int>::iterator ) ) ;
v.erase( iter ) ;
memcmp( before, &iter, sizeof( std::vector<int>::iterator ) ) ;
the memcmp will return a value not equal to 0.How does that work?
About how you'd expect. The container knows about the iterators
which refer to it, and marks them as invalid whenever it
invalidates them.
I agree that it's legal, but I wouldn't expect it anywhere
except the DS9000; it seems that the implementation, when
faced with vector::erase, would have to go out of its way to
go and change bits in the original 'iter' that the parameter
to vector::erase was copied from.
I'm not sure what you mean by "go out of its way".
Iterate through every copy of every iterator ever generated from that
container, to see if it references the region that's about to be
invalidated?
Every
pre-standard iterator I ever wrote did this. Logically, the
iterator knows about the container, and vice versa.
But physically it need not: see implementations where
vector<T>::iterator is implemented as plain T*.