Can you specialize a template method in a template class without specializing in a template template parameter?
Please note that specialization depends on the value of the template parameter, and not on its type.
This is similar to compiling in Visual Studio 2008 SP1, but not GCC 4.2.4.
#include <iostream> using namespace std; template <typename T> class A { private: template <bool b> void testme(); template <> void testme<true>() { cout << "true" << endl; }; template <> void testme<false>() { cout << "false" << endl; }; public: void test(); }; template<typename T> struct select {}; template<> struct select<int> { static const bool value = true; }; template<> struct select<double> { static const bool value = false; }; template <class T> void A<T>::test() { testme<select<T>::value>(); } int main(int argc, const char* argv[]) { A<int> aInt; A<double> aDouble; aInt.test(); aDouble.test(); return 0; }
GCC tells me: βerror: explicit specialization in namespace without class A classβ
If it is not supported by the standard, can someone tell me why?
source share