If I had something trivial such as (and to clarify, I am not suggesting this is a good implementation, simply an example to demonstrate partial template specialization failure on member functions):
template <typename T, typename U>
class BankAccount
{
T money;
U interestRate;
public:
BankAccount(T money, U interestRate) :
money(money), interestRate(interestRate)
{}
void showMeTheMoney();
};
I would not be able to specialize each function by doing:
// invalid code
template <typename U>
void BankAccount <int, U>::showMeTheMoney()
{
printf("$%d.00 interest: %f\n", money, interestRate);
}
template <typename U>
void BankAccount <long, U>::showMeTheMoney()
{
printf("$%l.00 interest: %f\n", money, interestRate);
}
template <typename U>
void BankAccount <float, U>::showMeTheMoney()
{
printf("$%.2f interest: %f\n", money, interestRate);
}
template <typename U>
void BankAccount <double, U>::showMeTheMoney()
{
printf("$%.2f interest: %f\n", money, interestRate);
}
int main(int argc, char *argv[])
{
BankAccount<double, float> b(500, 0.03);
b.showMeTheMoney();
BankAccount<std::uint64_t, float> c(1234, 0.01);
c.showMeTheMoney();
}
etc. Unfortunately C++ standards do not allow this:
14.5.5.3.1. The template parameter list of a member of a class template partial specialization shall match the template parameter list of the class template partial specialization. The template argument list of a member of a class template partial specialization shall match the template argument list of the class template partial specialization.
So instead the only solutions (that I know of) are to use type traits or reproduce the entire class with boilerplate code. Is there a rationale behind this decision, or is this something that simply does not exist in C++ because there isn't enough demand, or some other reason?