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,801 of 33,346   
   Nikolay Ivchenkov to fmatthew5...@googlemail.com   
   Re: C++11 containers   
   17 Jan 13 11:55:54   
   
   b104055b   
   From: tsoae@this.is.invalid   
      
   On 15 Jan, 09:26, fmatthew5876  wrote:   
   > 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)?   
      
   IMO, single copy-initialization should be preferred to equivalent   
   direct-initialization, because the former is more informative (the   
   initializer is supposed to be implicitly convertible to the   
   destination type). Unfortunately, we can't copy-initialize an object   
   created by a new-expression, and therefore push_back cannot   
   copy-initialize elements. However, copy-initialization and   
   direct-initialization usually have the same meaning when both are   
   well-formed, so we can have the following overload set:   
      
       // covers 4/6 forwarding failure cases   
       void push_back(T &&x)   
           { emplace_back(std::move(x)); }   
      
       template    
           enable_if_{}>   
               push_back(Param &&x)   
                   { emplace_back(FORWARD(x)); }   
      
      
   --   
         [ 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