Reputation: 197
Given the following definitions:
template <typename T>
class A {
public:
void f();
};
template <typename T>
void
A<T>::f()
{}
template <typename T>
class B {};
How would I partially specialize A<B<T>>::f
, i.e. f
for some B<T>
? I'm basically looking for the right magic to substitute the ???
below
template <???>
void
A<B<T>>::f()
{}
Upvotes: 3
Views: 70
Reputation: 56547
You cannot partially specialize a member function (nor in fact any function). You need to partially specialize the whole class:
template<typename T>
class A<B<T>>
{
// implement member functions for this specialization here
};
Upvotes: 1
Reputation: 206557
If you must have:
template <typename T>
void A<B<typename T>>::f() {}
then your only choice is to partially specialize A
.
template <typename T> class A<B<T>>
{
public:
void f();
};
Upvotes: 0
Reputation: 302643
You can have an explicit specialization, from [temp.expl.spec]:
An explicit specialization of any of the following:
— ...
— member function of a class template
— ...
can be declared by a declaration introduced bytemplate<>
That is:
template <>
void A<B<int>>::f() {
std::cout << "B\n";
}
But you cannot have a partial specialization of a member function of a class template. You would have to partially specialize the entire class:
template <typename T>
class A<B<T>> {
public:
void f() {
std::cout << "B\n";
}
// ... all other members you want in A<B<T>> ...
};
Upvotes: 3
Reputation: 39013
C++11 has Alias Templates, allowing you do do something like:
template<T>
using AB = A<B<T>>;
Then you can refer to AB<T>
instead of A<B<T>>
.
Unfortunately, you can't use that for specialization..
So seems to me the answer to your question is: You can't do that, but it's a shame.
Upvotes: -2