|
|
Le 28/02/2014 20:16, Orchid Win7 v1 nous fit lire :
> I'm using an iterator to keep track of where I am in a collection.
> ("Pattern" is actually a trivial alias to std::vector.) But as soon as
> you value-copy a container, all the iterators suddenly stop being valid.
> Ergo, I have to somehow avoid copying the vector at any cost.
If you have a vector, you can replace your iterator with an index. And
such index would remain valid even after a copy. (and access element via
the [] or at() ). Index starts at 0, and stop just before size().
About invalidation of iterator when value-copy is perform, it is not
always true.
A site for technical minded: http://en.cppreference.com/w/
A site with different approach: http://www.cplusplus.com/reference/
The second gives more details about invalidation of iterator by operations.
Post a reply to this message
|
|