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,868 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: template parameter not used in parti   
   25 Feb 13 19:27:54   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 25.02.2013 21:44, schrieb Walter Mascarenhas:   
   > The code below does not compile in g++ 4.7.2: it says   
   > that the template parameter S is not used in Foo's   
   > specialization below. Is g++ correct on this? If so,   
   > how would I specialize the struct Foo for   
   > T = std::vector::iterator in a general way?   
   >   
   > #include    
   > template    
   > struct Foo   
   > {   
   > };   
   >   
   > template    
   > struct Foo< typename std::vector::iterator >   
   > {   
   > };   
      
   Yes, the code is ill-formed, no diagnostic required. Reason is that the   
   partial specialization can never be deduced. This is similar to the   
   situation of the following function template:   
      
   #include    
      
   template   
   void foo(typename std::vector::iterator) {}   
      
   int main() {   
     foo(std::vector().begin());   
   }   
      
   Here we have a similar non-deduced context as in the case of your   
   partial specialization.   
      
   Think a second time of what you are trying to realize here: The type   
   std::vector::iterator has not necessarily an exact inverse relation   
   to the template parameter S of std::vector. So it is not really clear   
   to me what you are trying to achieve. E.g. if std::vector::iterator   
   would be S*, how should the compiler know that if you provide int* that   
   the partial specialization should be taken? Type 'int*' may be an   
   associated type for several types. There is nothing special about it   
   being (just by chance) identical to std::vector::iterator.   
      
   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