POV-Ray : Newsgroups : povray.off-topic : Undirected ramblings on C++ : Re: Undirected ramblings on C++ Server Time
28 Jul 2024 18:24:53 EDT (-0400)
  Re: Undirected ramblings on C++  
From: Le Forgeron
Date: 28 Feb 2014 15:32:58
Message: <5310f27a$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.