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,000 of 33,346   
   Thomas Richter to All   
   Variadic templates and passing by refere   
   10 Mar 12 23:01:44   
   
   From: thor@math.tu-berlin.de   
      
   Hi folks,   
      
   how would you realize a variadic template function where you want to   
   pass in both scalar types and references you want to modify in the   
   callee. To be specific, consider declarations as follows:   
      
     class A;   
      
     template   
     void Launch(A &t,U&... other);   
      
     template   
     void Launch(int x,U&... other);   
      
   Now I get a problem because, when I want to call "Launch" with int   
   arguments as in   
      
    class A a,b;   
    Launch(a,5,b);   
      
   it clearly doesn't work. This would require the compiler to create a   
   reference to a temporary, which is of course not possible. Replacing the   
   arguments by const references would solve the problem as it would allow   
   the compiler to pass in references to temporaries. However, this   
   prohibits of course modification of the classes passed in, which I would   
   like to do. Replacing the reference by a copy would of course also solve   
   the problem of argument passing, but then I only modify the copy, so   
   this doesn't help either.   
      
   Any other ideas?   
      
   Greetings,   
   	Thomas   
      
      
   --   
         [ 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