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 31,581 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: Template argument deduction with lam   
   23 Oct 11 14:11:57   
   
   1253bd52   
   From: daniel.kruegler@googlemail.com   
      
   Am 22.10.2011 23:20, schrieb Pedro:   
   > The snippet below fails to compile on gcc 4.6.1. When the   
   > template argument is provided then the code compiles.   
      
   The compiler behaves conforming.   
      
   > My theory is   
   > that this because f below is a lambda not a std::function instance and   
   > although a conversion exists from one to the other this conversion   
   > is not used for purposes of template matching. Is that anywhere close   
   > to what is happening here?   
      
   This comes very close, but some further remarks: For an argument of a function   
   template like   
      
   template   
   void g2(X const&);   
      
   for a successful argument deduction (without explicit template argument or   
   template default argument) you either need some specialization of X (e.g.   
   X) or a type that derives from such a specialization of X. It wouldn't   
   even help, if the actual    
   argument type would have a conversion function to some specialization of X,   
   e.g. an object of type   
      
   struct H {   
    operator X&();   
   };   
      
   would not deduce any specialization of g2. In your example the situation is   
   worse, because a lambda closure has no conversion function to std::function.   
   What std::function has, is only a function template constructor, but this is   
   not considered here.   
      
   This is also similar to the following example:   
      
   #include    
      
   template   
   void u(const std::basic_string&){}   
      
   int main() {   
    u("Hi!");   
   }   
      
   Even though std::string has an implicit conversion from const char*, this   
   conversion is not considered here, the example is ill-formed.   
      
   HTH & Greetings from Bremen,   
      
   - Daniel Krügler   
      
      
      
   --   
         [ 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