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,797 of 33,346   
   =?windows-1252?Q?Daniel_Kr=FCgler?= to All   
   Re: C++11 containers   
   15 Jan 13 13:58:54   
   
   From: daniel.kruegler@googlemail.com   
      
   On 2013-01-15 06:26, fmatthew5876 wrote:   
      
   > With C++11 and perfect forwarding we can have functions like   
   > template  vector.emplace_back(Args&&... args)   
   > which forward all of the constructor arguments.   
   >   
   > This appears to work for all cases. If you want default construction   
   > you pass no arguments, if you want copy or move you pass an lvalue   
   > or rvalue T. If you want any other constructor, you pass the   
   > arguments for it.   
   >   
   > So my question is when creating our own containers for C++11 is   
   > there any reason to still write old style insertion functions for a   
   > container like void push_back(const T& t) or void push_back(T&& t)?   
      
   Sure, there is no general problem with that approach, push_back() is -   
   like emplace_back() - an optional operation (see Table 101 — Optional   
   sequence container operations). It would mean though that you cannot   
   take advantage of std::back_insert_iterator, instead you would need to   
   fall back to one of the other existing insert iterators or you would   
   need to provide your own emplacing back_insert_iterator. Also,   
   basically all typical Library Sequence containers provide a   
   push_back() function if they can, so not providing it may confuse   
   those who use your code.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ 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