Create Object of Unsigned Template

1
2
3
4
5
template<class T>
void function ( T item )
{
    unsigned T willThisWork; // <--
}

Visual Studio compiles it, but will it actually do what I want? I do know that T is is a signed integer, I just don't know what size of integer.
I'll answer my own question. While it does compile, it will not run. So no, this is not valid syntax.

edit: It's no longer compiling either. I'm not sure why it did before.
Last edited on
std::make_unsigned would work, if that is what you were trying to achieve

1
2
3
4
5
6
7
#include <type_traits>

template<class T>
void function ( T item )
{
    typename std::make_unsigned<T>::type willThisWork;
}

Last edited on
Yes, that is what I wanted. Thank you.
Topic archived. No new replies allowed.