c++ - Why function template cannot be partially specialized? -


i know language specification forbids partial specialization of function template.

i know rationale why forbids it? not useful?

template<typename t, typename u> void f() {}   //allowed! template<> void f<int, char>()            {}   //allowed! template<typename t> void f<char, t>()    {}   //not allowed! template<typename t> void f<t, int>()     {}   //not allowed! 

afaik that's changed in c++0x.

i guess oversight (considering can partial specialization effect more verbose code, placing function static member of class).

you might relevant dr (defect report), if there one.

edit: checking this, find others have believed that, no-one able find such support in draft standard. this thread seems indicate partial specialization of function templates not supported in c++0x.

edit 2: example of meant "placing function static member of class":

#include <iostream> using namespace std;  // template<typename t, typename u> void f() {}   //allowed! // template<> void f<int, char>()            {}   //allowed! // template<typename t> void f<char, t>()    {}   //not allowed! // template<typename t> void f<t, int>()     {}   //not allowed!  void say( char const s[] ) { std::cout << s << std::endl; }  namespace detail {     template< class t, class u >     struct f {         static void impl() { say( "1. primary template" ); }     };      template<>     struct f<int, char> {         static void impl() { say( "2. <int, char> explicit specialization" ); }     };      template< class t >     struct f< char, t > {         static void impl() { say( "3. <char, t> partial specialization" ); }     };      template< class t >     struct f< t, int > {         static void impl() { say( "4. <t, int> partial specialization" ); }     }; }  // namespace detail  template< class t, class u > void f() { detail::f<t, u>::impl(); }      int main() {     f<char const*, double>();       // 1     f<int, char>();                 // 2     f<char, double>();              // 3     f<double, int>();               // 4 } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -