You can fully specialize a member selectively:
template<int N>
struct Vector {
int calculate() { return N; }
};
// put into the .cpp file, or make inline!
template<>
int Vector<3>::calculate() { return -1; }
You do a full specialization. Meaning you cannot partial specialize it:
template<int N, int P>
struct Vector {
int calculate() { return N; }
};
// WROOONG!
template<int N>
int Vector<N, 3>::calculate() { return -1; }
If you need that, you can use enable_if:
template<int N, int P>
struct Vector {
int calculate() { return calculate<P>(); }
private:
// enable for P1 == 3
template<int P1>
typename enable_if_c<P1 == P && P1 == 3, int>::type
calculate() { return -1; }
// disable for P1 == 3
template<int P1>
typename enable_if_c<!(P1 == P && P1 == 3), int>::type
calculate() { return N; }
};
An alternative approach is to split your stuff up (common stuff into a base class, and specialized stuff into the derived class) like Nick recommends.
I usually would take the second approach. But i prefer the first one if i don't need to partial specialize the functions.