See this discussions for more details:
http://stackoverflow.com/questions/3052579/explicit-specialization-in-non-namespace-scope
http://stackoverflow.com/questions/18904587/class-template-specialization-in-class-scope
Use case: We want to define a private method thah behaves depending on an external parameter (N in this case):
template<typename T, int N=0>
struct MyClass {
bool operator()(T a, T b) { return my_func<(N > 0)>(a,b); }
protected:
template<bool Discriminant> static bool my_func(T a, T b);
template<> inline static bool my_func<true>(T a, T b) { return true; }
template<> inline static bool my_func<false>(T a, T b) { return false; }
};
Problem: Partial specialization is only supported at <namespace> level in C++03 (even in C++11)
Option 1) Use template specializations outside of the class that wants to use them
namespace detail {
template<typename T, bool> struct my_func;
template<typename T>
struct my_func<true> {
inline bool operator()(T a, T b) { return true; }
};
template<typename T>
struct my_func<false> {
inline bool operator()(T a, T b) { return false; }
};
template<typename T>
struct MyClass {
using my_func = detail::my_func;
};
}//namespace detail