Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the C++ standard not allow function template partial specialization?

I read something that it might be confusing for the compiler to write

template <class T>
void calculator<std::complex<T>>::myMin();

but maybe just give it a hint like so? To make it clear that it is a partial specialization.

template < , class T>
void calculator<std::complex<T>>::myMin();
like image 458
Hakaishin Avatar asked Nov 17 '16 10:11

Hakaishin


People also ask

What is function template specialization?

The act of creating a new definition of a function, class, or member of a class from a template declaration and one or more template arguments is called template instantiation. The definition created from a template instantiation is called a specialization.

Can templates be used for functions?

Templates are powerful features of C++ which allows us to write generic programs. We can create a single function to work with different data types by using a template.

What is the specialty of a template function give example?

Template in C++is a feature. We write code once and use it for any data type including user defined data types. For example, sort() can be written and used to sort any data type items. A class stack can be created that can be used as a stack of any data type.

Can we have overloading the function template?

You may overload a function template either by a non-template function or by another function template. The function call f(1, 2) could match the argument types of both the template function and the non-template function.


1 Answers

From http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#229 linked by @danh in the comments above:

Notes from 10/00 meeting:

A major concern over the idea of partial specialization of function templates is that function templates can be overloaded, unlike class templates. Simply naming the function template in the specialization, as is done for class specialization, is not adequate to identify the template being specialized.

like image 127
fwyzard Avatar answered Oct 09 '22 00:10

fwyzard