Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Deleting it...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 14 Topic 9541 of 9830
Post > Topic >>

Re: Deleting items from an std::list , is this code correct?

by Chris Uzdavinis <cuzdav@[EMAIL PROTECTED] > Apr 25, 2008 at 10:14 AM

On Apr 24, 5:43 pm, Ron Natalie <r...@[EMAIL PROTECTED]
> wrote:
> lallous wrote:
> > Hello Group,
>
> > Please advise. Does this work with all STL implementations
>
> Doesn't work with any implementation as far as I know.
>

I think you mis-read the code.  There are *two* lists, one of ints,
the other of interators into the first.


> >    for (int_list_iterator_list_t::const_iterator
di=it_list.begin();di!
> > =it_list.end();++di)
> >    {
> >      L.erase(*di);
> >    }
> > }
>
> An iterator to a deleted item in a list is invalid.  You can't
> apply ++di to it.  This is why sequence erases return the next
> iterator.

The element under di is never erased, only the element under *di is.

> for (int_list_iterator_list_t::const_iterator di=it_list.begin();
> di != it_list.end; )
>      {
>        it = L.erase(*di);
>      }

Fortunately it won't compile due to incompatible iterator types.  If
it would compile and run, it'd be a disaster, since it would be trying
to jump the tracks out of it_list and into L.

--
Chris

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 14 Posts in Topic:
Deleting items from an std::list , is this code correct?
lallous <lallous@[EMAI  2008-04-24 01:04:11 
Re: Deleting items from an std::list , is this code correct?
"Paul M. Dubuc"  2008-04-24 15:19:20 
Re: Deleting items from an std::list , is this code correct?
Ron Natalie <ron@[EMAI  2008-04-24 15:43:19 
Re: Deleting items from an std::list , is this code correct?
Chris Uzdavinis <cuzda  2008-04-24 15:43:20 
Re: Deleting items from an std::list , is this code correct?
Alex Shulgin <alex.shu  2008-04-25 03:42:15 
Re: Deleting items from an std::list , is this code correct?
Chris Uzdavinis <cuzda  2008-04-25 10:14:33 
Re: Deleting items from an std::list , is this code correct?
Greg Herlihy <greghe@[  2008-04-25 10:14:41 
Re: Deleting items from an std::list , is this code correct?
Tomislav Petrovic <t.p  2008-04-25 10:45:35 
Re: Deleting items from an std::list , is this code correct?
Chris Uzdavinis <cuzda  2008-04-25 15:50:25 
Re: Deleting items from an std::list , is this code correct?
Carl Barron <cbarron41  2008-04-26 03:34:23 
Re: Deleting items from an std::list , is this code correct?
lallous <lallous@[EMAI  2008-04-26 04:44:01 
Re: Deleting items from an std::list , is this code correct?
Greg Herlihy <greghe@[  2008-04-26 08:43:46 
Re: Deleting items from an std::list , is this code correct?
Carl Barron <cbarron41  2008-04-26 16:32:32 
Re: Deleting items from an std::list , is this code correct?
Carl Barron <cbarron41  2008-04-26 16:32:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 15:37:59 CDT 2008.