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)   
|