user877329
user877329

Reputation: 6200

Declare an "unsigned T"

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

Answers (2)

4pie0
4pie0

Reputation: 29724

you can use std::make_unsigned<T>::type

Upvotes: 2

Jerry Coffin
Jerry Coffin

Reputation: 490108

std::make_unsigned<T>::type is what you seem to be looking for.

Upvotes: 11

Related Questions