I've just stumbled across something weird. Now first off, I'm aware that when you say just "char" it is implementation specific whether you'll get a signed or an unsigned char. But what I find surprising is that regardless of whether default char is signed or unsigned, the compiler seems to treat signed char, unsigned char and char as 3 distinct types.
Code:
#include <iostream>
template < typename VarType >
struct Test
{
inline static void test()
{
std::cout << "unspecified type\n";
}
};
template <>
struct Test< signed char >
{
inline static void test()
{
std::cout << "signed char\n";
}
};
template <>
struct Test< unsigned char >
{
inline static void test()
{
std::cout << "unsigned char\n";
}
};
/*
template <>
struct Test< char >
{
inline static void test()
{
std::cout << "char\n";
}
};
*/
int main()
{
Test< char >::test();
}
This example prints "unspecified type". Only if you uncomment the specialization for char and compile / run again do you get the expected (to me at least) result: "char".
Does anyone else find that surprising?