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 32,336 of 33,346   
   Dave Abrahams to All   
   Re: Broken interaction between std::prio   
   27 May 12 21:59:57   
   
   From: dave@boostpro.com   
      
   on Tue May 22 2012, Zoltan Juhasz  wrote:   
      
   > On Monday, 21 May 2012 15:28:09 UTC-4, Gene Bushuyev  wrote:   
   >> To avoid default constructing an object one would need the function   
   >> returning by value, how about simply modifying pop to return a value:   
   >>   
   >> template   
   >> T priority_queue::pop()   
   >> {   
   >>     T tmp(move(container.front()));   
   >>     container.erase(container.begin());   
   >>     make_heap(container.begin(), container.end(), compare);   
   >>     return tmp;   
   >> }   
   >>   
   >> It will not break existing code that relies on copy and assumes pop()   
   >> doesn't return anything.   
   >   
   > Unfortunately this implementation does not provide strong exception   
   > safety guarantees, e.g. if an exception is thrown when you return tmp,   
   > the container has been already modified, in an irreversible way, and   
   > the returned element is lost.   
      
   That's not so terrible.  The basic guarantee is perfectly adequate for   
   many situations.   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
         [ 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