Reputation: 6200
I want to use unsigned T in a template:
template<class T>
void signed2unsigned(const T* source, unsigned T* dest, size_t n)
{
do
{
intmax_t s=*source;
s+=min(*source);
*dest=s;
++dest;
++source;
--n;
}
while(n!=0);
}
This doesn't work, since unsigned without is expanded to unsigned int before the type T is taken into account. Is there a workaround other than just introduce U and write in documentation that U has to be an unsigned T?
Upvotes: 8
Views: 628
Reputation: 490108
std::make_unsigned<T>::type
is what you seem to be looking for.
Upvotes: 11