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,975 of 33,346   
   Dave Abrahams to All   
   Re: Where are iterators for rvalue conta   
   02 Mar 12 13:01:02   
   
   178b9c1e   
   From: dave@boostpro.com   
      
   on Fri Mar 02 2012, Gene Bushuyev  wrote:   
      
   > I was looking at the C++11 standard docs and didn't see iterators for   
   > rvalue containers. For example, std::vector has only these begin()   
   > member functions:   
   >   
   > iterator begin();   
   > const_iterator begin() const;   
   >   
   > Where is "iterator begin() &&;" ?   
   >   
   > Say, I want to construct my container by moving from a vector,   
   >   
   > MyContainer::MyContainer(vector&& v)   
   > {   
   >    reserve(v.size());   
   >    uninitialized_copy(move(v).begin(), move(v).end(), data);   
   >    size = v.size();   
   > }   
   >   
   > But that would copy instead of moving, because containers have no   
   > rvalue iterators. Am I missing something or the standard missed them?   
      
   I don't think you really want implicit move iterators for container   
   rvalues.  Move iterators only work for single-read traversals.  Replace   
   with some algorithm that makes multiple passes over the input data and   
   you could have a disaster on your hands.   
      
   Just use move_iterator when you're sure it's safe.   
      
   Cheers,   
      
   --   
   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