Re: iterator invalidation trouble
From: Alexander Stippler (stip_at_mathematik.uni-ulm.de)
Date: 12/29/03
- Next message: nb: "What kind of problems is c++ best at solving?"
- Previous message: E.F.: "Matrox and C++ ... need help"
- In reply to: Ron Natalie: "Re: iterator invalidation trouble"
- Next in thread: Ron Natalie: "Re: iterator invalidation trouble"
- Reply: Ron Natalie: "Re: iterator invalidation trouble"
- Reply: Dan W.: "Re: iterator invalidation trouble"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Dec 2003 19:31:48 +0100
Ron Natalie wrote:
>
> "Alexander Stippler" <stip@mathematik.uni-ulm.de> wrote in message
> news:3ff061a1@news.uni-ulm.de...
>> I think this problem is rather general. Are there any threads online on
>> "robust iterators for c++"? Is there a trick for my situation?
>
> You say the user shouldn't know if the container has changed, however
> since you expose all the ugliness to him, he does have to know.
>
> It's hard to understand what solution to propose without a better
> description of the problem. Why is the user responsible for
> iterating some function f() over a list when f() is not under
> their control. Possibly this is better solved by passing the
> container v (or begin and end iterators) to f() and letting it
> manage searching over the list itself.
As an example of my application, let v be an arithmetic sparse vector, where
I only want to store non zero elements. Now I have e.g.
operator-(SparseVector v, double c), which could internally have a loop
using an iterator _it_ to add c to every non-zero-element. Here is the
client code - I do not want to have to consider the possibility of deleting
elements in every function using an iterator.
If c == *_it_, this would result in *_it_ == 0 and thus the current item is
removed. This happens immediately, when assigning *_it_ its new value
(through a proxy).
That's it. How to handle this? I considered not deleting *_it_ immediately,
but then I would have to guess the right time to do it. Is there any
simpler solution than registering iterators with their container?
regards,
alex
- Next message: nb: "What kind of problems is c++ best at solving?"
- Previous message: E.F.: "Matrox and C++ ... need help"
- In reply to: Ron Natalie: "Re: iterator invalidation trouble"
- Next in thread: Ron Natalie: "Re: iterator invalidation trouble"
- Reply: Ron Natalie: "Re: iterator invalidation trouble"
- Reply: Dan W.: "Re: iterator invalidation trouble"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|