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,674 of 33,346   
   Zhihao Yuan to Frank Birbacher   
   Re: Constructing pair from single    
   22 Nov 12 11:28:04   
   
   From: lichray@googlemail.com   
      
   On Thursday, 22/11/2012 1:46:09 AM UTC-6, Frank Birbacher wrote:   
   > Does to following code reliably construct a pair that holds a given   
   > value twice? Is it true that pair::first will be constructed before   
   > pair::second? Does make_pair only forward arguments?   
      
   No.  Actually, It copies its argument first, then copies t and move t   
   into make_pair's argument list, in an indeterminate sequence.  The   
   moving /b/ can happen before the copying /a/.   
      
   > template   
   > std::pair fanout(T t)   
   > {   
   >   return std::make_pair(t, std::move(t));   
                             /a/ /b/   
      
   If you cares the initialization ordering, you can consider an   
   std::array:   
      
   template   
   std::array fanout2(T const& t)   
   {   
      return { t, t };   
   }   
      
      
   --   
         [ 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