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 33,128 of 33,346   
   8604sprucemill@googlemail.com to Chris Uzdavinis   
   Re: Order of template function overloads   
   19 Jul 13 17:02:58   
   
   On Friday, July 19, 2013 12:20:07 AM UTC-7, Chris Uzdavinis wrote:   
   > On Thursday, July 18, 2013 11:55:00 AM UTC-5, 8604spr...@googlemail.com   
   wrote:   
   >   
   > >   Does the order of template function overloads matter? In the   
   > > following code, I would expect both a() and b() to produce the same   
   > > output since both overloads of f() are visible at the point of   
   > > instantiation of both a() and b(). However, with gcc (both 4.7.2 and   
   > > 4.8.1), the tuple overload is not chosen for a(). Why does this   
   > > happen?   
   >   
   > It has to do with what is visible at the point of the function   
   > definition.  It's not even a template issue, nor a c++11 issue.   
      
   Is that true? My (possibly incorrect) understanding is that templates   
   are special in that instantiation points are the only ones that   
   matter. For example, a slightly modified version of the original   
   code shows this pretty clearly:   
      
   #include    
   #include    
      
   template  struct A {   
     static void f() { std::cout << "generic\n"; } };   
      
   template  void a( const T & ) { A::f(); }   
   // Defined after definition of a()   
   template  struct A > {   
     static void f() { std::cout << "tuple\n"; } };   
      
   template  void b( const T & ) { A::f(); }   
      
   int main( int, char *[] )   
   {   
     a( std::make_tuple( 1.1, 1 ) ); // prints "tuple"   
     b( std::make_tuple( 1.1, 1 ) ); // prints "tuple"   
   }   
      
      
   --   
         [ 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