I have to deal with char
arrays which might be unsigned (because they come from a SCSI data block). I wanted to handle them with this function:
template <typename CharT, size_t Len>
std::string strFromArray(CharT (&src) [Len])
{
return std::string((typename boost::make_signed<CharT>::type *) src, Len);
}
The error is in the std::string
constructor call, it cannot take signed char
/unsigned char
but will only take char
.
I could of course replace the cast with (char *) src
, but then I would lose all compiler errors if I pass in a non-char type.
How can I write this so that it constructs strings out of all "charry" types?