the following accepted both gcc-4.9.2 , clang-3.8 when compiling c++98 or c++11,
#include <cstdio> template <typename t> void f(t) { printf("t\n"); } template <> void f<int>(int) { printf("int\n"); } // explicit specialization template <> void f<>(double) { printf("double\n"); } // explicit specialization -- 14.7.2(7) template <> void f(float) { printf("float\n"); } // here int main() { f(1l); // t f(10); // int f(10.0); // double f(10.0f); // float }
i see in c++11 standard §14.7.2(7) deducing trailing template arguments in explicit template specializations permitted, cannot find whether or how terser form marked here
allowed.
are these compilers conformant or extension?
c++14 standard §14.7(3) has
an explicit specialization may declared function template, class template, member of class template or member template. explicit specialization declaration introduced template<>. in explicit specialization declaration class template, member of class template or class member template, name of class explicitly specialized shall simple-template-id. in explicit specialization declaration function template or member function template, name of function or member function explicitly specialized may template-id.
and demonstrates
template<class u> void g(u) { } template<> void g(char) { } //specialize u == char // u deduced parameter type
and have §14.7.3(10)
a trailing template-argument can left unspecified in template-id naming explicit function template specialization provided can deduced function argument type. [ example:
template<class t> class array { / ... / }; template<class t> void sort(array<t>& v); // explicit specialization sort(array<int>&) // deduced template-argument of type int template<> void sort(array<int>&);
—end example ]
Comments
Post a Comment