The easiest way is by usage of std::make_unsigned
, which works for any integral type:
template<typename T>
typename std::make_unsigned<T>::type convert(T const& input)
{
return static_cast<typename std::make_unsigned<T>::type>(input);
}
Using this in your class becomes fairly ugly when used directly, so we will add a type alias:
template< typename charT >
struct serializer
{
typedef typename ::std::make_unsigned<charT>::type ucharT;
/* ... */
private:
std::basic_string< ucharT > base64_encode( ucharT * bytes, unsigned length );
};