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,577 of 33,346   
   Seungbeom Kim to jhartzell42@googlemail.com   
   Re: move_back() function   
   05 Oct 12 23:34:25   
   
   From: musiphil@bawi.org   
      
   On 2012-10-04 22:23, jhartzell42@googlemail.com wrote:   
   >   
   > I find myself, when using a vector or a deque, using this combination:   
   >   
   > do_something(std::move(deq.back());   
   > deq.pop_back();   
   >   
   > I wonder if there's any way to combine this concept into a move_back()   
   > function, but I can't think how it would work.   
      
   The answer depends on your desired usage pattern, but   
   maybe something like this?   
      
   template   
   void move_back(C& c, F f)   
   {   
        f(std::move(c.back()));   
        c.pop_back();   
   }   
      
   /* move_back(deq, do_something); */   
      
   > I guess one possibility   
   > is to make it take a reference to the thing:   
   >   
   > template   
   > void move_back(T1 &deq, T2 &thing) {   
   >    thing = std::move(deq.back());   
   >    deq.pop_back();   
   > }   
   >   
   > ....but this is nowhere near as general as I'd like it to be.   
      
   In which ways do you want it to be more general?   
      
   --   
   Seungbeom Kim   
      
      
         [ 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