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,056 of 33,346   
   Dave Abrahams to All   
   Re: Explicit template arguments in perfe   
   27 Mar 12 19:46:21   
   
   From: dave@boostpro.com   
      
   on Mon Mar 26 2012, Johannes Schaub  wrote:   
      
   > I just discussed cases like "Write a perfect forwarding template that   
   > calls 'make_shared'" and was told that this is not possible because   
   > "make_shared" requires a single explicit argument.   
   >   
   > I would like to spread knowledge that it is possible to write such a   
   > perfect forwarder. Given a generic (template) target function "g" and a   
   > perfect forwarder "f", we can write   
   >   
   >    template   
   >    auto f(D &&...d) -> decltype(   
   >             g(std::forward(d)...)   
   >    ) {   
   >      return g(std::forward(d)...);   
   >    }   
   >   
   > Since "E" is the first parameter pack, it receives any explicit template   
   > arguments passed to "f". This has been tested and works on GCC and Clang.   
      
   OK... and why exactly doesn't the following work?   
      
      template   
      auto f(D &&...d) -> decltype(   
               g(std::forward(d)...)   
      ) {   
        return g(std::forward(d)...);   
      }   
      
   Seems to work for me.   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
         [ 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