I have a function but I want to split it into two functions, one for returning signed integers and one for unsigned integers. It looks like std::is_signed
is not strictly for integers so I thought if I could a template test for something like std::is_integral<T>::value && std::is_signed<T>::value
but that doesn't work. Right now I have the signed test as an if statement:
template<typename T>
typename std::enable_if
<
std::is_integral<T>::value,
T
>::type
foo()
{
if( std::is_signed<T>::value )
{
//signed
}
else
{
//unsigned
}
}
EDIT. I'm using Visual Studio 2010. Actually it looks like what's happening is Visual Studio will not accept two templates, one with std::is_integral<T>::value && std::is_signed<T>::value
and one with std::is_integral<T>::value && std::is_unsigned<T>::value
. It tells me function template has already been defined
. Am I doing this wrong and is there a more standard compliant way to have two functions, one that is for returning unsigned integral, and one for signed integral?