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 33,305 of 33,346   
   sg to All   
   Re: transform, make_pair, and rvalues   
   14 Apr 14 12:17:04   
   
   From: sgesemann@googlemail.invalid   
      
   Am 12.04.2014 20:10, schrieb James K. Lowden:   
   > Today we encountered an rvalue question I couldn't answer.   
   >   
   > Array a;   
   > Array64 b;   
   > std::map c;   
   >   
   > transform( a.begin(), a.end(), b.begin(), inserter(c, c.begin()),   
   > 	   make_pair );   
   >   
   > The compilation error from VC11 said it couldn't convert parameter 2 of   
   > make_pair from uint64_t&& to uint64_t.   Bug or feature?   
      
   As others have pointed out, the template parameters of make_pair are   
   supposed to be deduced which involves some perfect forwarding magic   
   (possibly resulting in lvalue reference types for lvalues).   
      
   Just like overload resolution, template argument deduction is something   
   that one should not do manually in general. With a lambda expression you   
   can let the compiler worry about that:   
      
     transform( a.begin(), a.end(), b.begin(), inserter(c, c.begin()),   
         [](int x, uint64_t y){return make_pair(x,y);} );   
      
   This way, it will also be easier for the compiler to inline the   
   make_pair expression into the std::transform<> instantiation.   
      
   Cheers!   
   sg   
      
      
   --   
         [ 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