template< typename charT >
struct serializer
{
    /* ... */
private:
    std::basic_string< charT > base64_encode( unsigned charT * bytes, unsigned length );
};

I would like the private member function to take an unsigned whatever-char-type. If charT is char16_t, char32_t, wchar_t, I want the signature to be unsigned that. How can I do that?

有帮助吗?

解决方案

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 );
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top