If it is OK, not to specify the argument type when calling the write()
function with a character array (or to use char const*
in these cases rather than, e.g., char[6]
), the way to implement this is to use an overload to deal with char const*
:
void write(Buffer& ob, char const* value) {
write<char const*>(ob, value);
}
This function is preferred over the template instantiations and can, thus, be used to suitably delegate the processing for string literals (or C-strings in general, actually).
If it is necessary to get the correct type passed, the only way which would work is to not specialize the actual function template but, instead, to immediately delegate a struct
with a suitable member function and to partially specialize this struct
to deal with arrays: you cannot partially specialize a function template, i.e., the following is illegal:
template <int N>
void write<char const[N]>(Buffer& ob, char const (&value)[N]); // ERROR
... but it can be simulated by partially specializing a struct
instead.