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 14 of 14 Topic 9541 of 9831
Post > Topic >>

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

by Carl Barron <cbarron413@[EMAIL PROTECTED] > Apr 26, 2008 at 04:32 PM

In article
<6742faed-a22c-422f-8891-581674443cb3@[EMAIL PROTECTED]
>,
lallous <lallous@[EMAIL PROTECTED]
> wrote:

> To summarize, what would you do if these conditions apply:
> 1. the remove_if is so complex and requires a certain context to
> decide, thus we cannot have a functor with lots of parameters just to
> provide it with the required context.
> 2. items are not to be erased on the spot, we should wait for a
> certain operation to end, then delete them, because those items might
> be needed and referenced and read while process is not done yet.
> 
   This a most general idea if functors cant be used with <algorithm>
it further does not require ListType to be copiable and assignable
as does <algorithm>.

     void modify_list(ListType &list)
     {
       ListType marked_for_delete;
       /*
          marked_for_delete contains the items to delete
          iterators pointing to these values are valid in that
dereferencing the iterator still points to data and references
are still valid as the data node itself is not moved in memory
only internal ptrs change so incrementing iterators pointing
to elements of marked_for_delete will point to different
values, that is   *++before  is not equal to *++after in general,
    */

       for(ListType::iterator it = list.begin();it != list.end();++it)
       {
          // determine if we delete this item
          if(we_will_delete)
          {
             marked.for_delete.splice(marked_for_delete.end(),list,it);
          }
       }

       // other operations requiring all  the data;
       //  let marked_for_delete to go out of scope and it will
       //  destruct the deleted items.
    }

-- 
      [ 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 21:57:50 CDT 2008.