Re: using copy with list<string> and list<cstring*>
From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 08/03/04
- Next message: mario: "Re: msvc & Dinkum"
- Previous message: Jason Winnebeck: "Re: using copy with list<string> and list<cstring*>"
- In reply to: Jason Winnebeck: "Re: using copy with list<string> and list<cstring*>"
- Next in thread: Stephen Howe: "Re: using copy with list<string> and list<cstring*>"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 3 Aug 2004 13:05:27 -0400
"Jason Winnebeck" <gillius@mail.rit.nspam.edu> wrote in message
news:upwKfKXeEHA.592@TK2MSFTNGP11.phx.gbl
>> With vector, it's probably safest to keep indexes into the master
>> vector. Pointers and iterators into the vector are easily
>> invalidated by just about any modifictations. Indexes are more
>> stable and predictable.
>
> Indexes invalidate at exactly the same time that all iterators
> invalidate. Pointers invalidate at exactly the same time that
> iterators invalidate for vectors. So technically they are all
> equally bad. But in some algorithms it will work fine, where you are
> ensured that the vector cannot change.
Indexes do not get invalidated, they still refer to something, in a
predictable way. You can adjust them to bring them back into order. E.g.
if you delete an element from the vector, you can subtract 1 from all
indexes referring to the elements beyond the deleted one. But if you
store pointers or iterators, you cannot adjust them - you need to throw
them away and repopulate with new ones. In some algorithms, adjustments
of indexes is more efficient than essentially regenerating your view
from scratch every time.
Of course if the vector is read-only, all three work equally well.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
- Next message: mario: "Re: msvc & Dinkum"
- Previous message: Jason Winnebeck: "Re: using copy with list<string> and list<cstring*>"
- In reply to: Jason Winnebeck: "Re: using copy with list<string> and list<cstring*>"
- Next in thread: Stephen Howe: "Re: using copy with list<string> and list<cstring*>"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|