Auto convert const char[] to const char * in template function
You could use a metafunction to transform the types passed as argument to your templates. Any array of chars would be transformed into a char*
:
template< typename T > struct transform
{
typedef T type;
};
template< std::size_t N > struct transform< char[N] >
{
typedef char* type;
};
template< std::size_t N > struct transform< const char[N] >
{
typedef const char* type;
};
Then, instead of using Tn
directly you would use typename transform< Tn >::type
.
Update: If you are working in C++11, then std::decay
already does what you want.