It is possible to specialize some class member function outside the template definition:
template<class A>
struct B {
void f();
};
template<>
void B<int>::f() { ... }
template<>
void B<bool>::f() { ... }
and in this case I can even omit definition of function f for a general type A.
But how to put this specializations inside the class? Like this:
template<class A>
struct B {
void f();
void f<int>() { ... }
void f<bool>() { ... }
};
What syntax should I use in this case?
EDIT:
For now the solution with fewest lines of code is to add a fake template function f definition and explicitly call it from original function f:
template<class A>
struct B {
void f() { f<A>(); }
template<class B>
void f();
template<>
void f<int>() { ... }
template<>
void f<bool>() { ... }
};
You can make
B::fa template function within your struct:Edit:
According to your comment this may help you, but I’ve not tested if it works: