For example:
template<typename T>
void write(T value)
{
mystream << value;
}
template<>
void write<const char*>(const char* value)
{
write_escaped(mystream, value);
}
template<>
void write<char*>(char* value)
{
write_escaped(mystream, value);
}
template<>
void write<const std::string&>(const std::string& value)
{
write_escaped(mystream.c_str(), value);
}
This looks like I'm doing it wrong, especially the two variants for const and non-const char*. However I checked that if I only specialize for const char *
then passing a char *
variable will invoke the non-specialized version, when called like this in VC++10:
char something[25];
strcpy(something, "blah");
write(something);
What would be the proper way of doing this?