home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,936 of 33,346   
   James K. Lowden to Ulrich Eckhardt   
   Re: Politics of using the standard libra   
   15 Feb 12 12:08:57   
   
   From: jklowden@speakeasy.net   
      
   On Tue, 14 Feb 2012 17:16:59 -0800 (PST)   
   Ulrich Eckhardt  wrote:   
      
   > >     List(const List& otherlist):   
   > >         _start(0),_finish(0),_numberofelements(0)   
   > >     {   
   > >         each(it,otherlist)   
   > >         {   
   > >             insertafter(finish(),otherlist(it));   
   > >         }   
   > >     }   
   >   
   > Not exception-safe. If inserting inside the ctor throws, you wont get   
   > the destructor called since the object hasn't been constructed yet.   
      
   I enjoyed the rest of your critique, and want to be sure I understand   
   this one.  IIUC:   
      
   If otherlist has 4 elements (a,b,c,d), and insertafter throws on, say,   
   'c', the exception will not invoke ~List and not free the storage for   
   elements 'a' and 'b'.   
      
   I suppose the proper solution is to try, catch, delete, and throw:   
      
   try {   
   	insertafter(finish(),otherlist(it));   
   } catch(...) {   
   	erase(_start,_finish); // and hope   
   	throw;   
   }   
      
   or use private inheritance.   
      
   --jkl   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca