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,291 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to Johannes Schaub   
   Re: Overload resolution and templates wi   
   14 May 12 11:13:12   
   
   From: daniel.kruegler@googlemail.com   
      
   On 2012-05-12 20:05, Johannes Schaub wrote:   
   > Am 10.05.2012 20:51, schrieb Daniel Krügler:   
   >> On 2012-05-10 10:14, David Barrett-Lennard wrote:   
   >>> Under VS2008, VS2010 I get this behaviour:   
   >>>   
   >>> template struct X { typedef T type; };   
   >>>   
   >>> void f(double) {}   
   >>> template void f(T) {}   
   >>>   
   >>> void g(double) {}   
   >>> template void g(typename X::type) {}   
   >>>   
   >>> void test()   
   >>> {   
   >>> f(1); // picks f(T)   
   >>> g(1); // picks g(double)   
   >>> }   
   >>>   
   >>> Is it a bug, or expected?   
   >>   
   >>> Either way, how can one use enable_if effectively?   
   >>   
   >> I don't understand you question. enable_if is always used, when   
   >> deduction has already taken place, e.g. rewrite g as (I assume that X   
   >> represents enable_if here):   
   >>   
   >   
   >> or   
   >>   
   >> template> typename enable_if::type* = 0>   
   >> void g(T) {}   
   >>   
   >   
   > A integral null pointer constant is not allowed as template argument for   
   > a pointer non-type template parameter. Did this change in a post-C++11   
   > draft?   
      
   You are right, I was a bit hasty here.   
      
   > You need to say   
   >   
   > = (void*)0   
   >   
   > You can say   
   >   
   > = nullptr   
   >   
   > You can alternatively make it an int   
   >   
   > int>::type = 0   
      
   Yes, this is what I also usually use.   
      
   > As for the benefit over the "typename = typename enable_if ..."   
   > approach, this allows overloading function templates that solely differ   
   > by the SFINAE expression. When using the type template parameter   
   > approach, that's not possible anymore, because the overloads would   
   > solely differ by their default arguments. However, default template   
   > arguments are not part of the signature of a function template, whereas   
   > the template parameter type itself is.   
      
   Correct.   
      
   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