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,271 of 33,346   
   Andy Lutomirski to David Barrett-Lennard   
   Re: Overload resolution and templates wi   
   10 May 12 11:48:25   
   
   49a7f3d1   
   From: luto@amacapital.net   
      
   On 05/10/2012 01:14 AM, 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'm having trouble finding the relevant part of the standard, but   
   there's no way this could work -- the type "typename X::type" is, in   
   general, an arbitrary function of T, and finding a T that matches is at   
   least NP hard.   
      
   To make enable_if work, use it in a context that doesn't require   
   deduction.  For example:   
      
   template   
   typename enable_if::type G(T);   
      
   --Andy   
      
      
   --   
         [ 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