G
Gianni Mariani
I have a couple of template methods that take any integer type however,
the first "if" statement becomes a constant expression when T is an
unsigned type.
#include <limits>
template <typename T>
static T bin_to_gray( const T & value )
{
if ( value >= 0 ) // << warning - "allways true" when T unsigned
{
return value ^ ( value >> 1 );
}
else
{
return ( ( ~value ) ^ ( ( ~value ) >> 1 ) )
+ std::numeric_limits<T>::min();
}
}
Any portable way to eliminate the warning ?
the first "if" statement becomes a constant expression when T is an
unsigned type.
#include <limits>
template <typename T>
static T bin_to_gray( const T & value )
{
if ( value >= 0 ) // << warning - "allways true" when T unsigned
{
return value ^ ( value >> 1 );
}
else
{
return ( ( ~value ) ^ ( ( ~value ) >> 1 ) )
+ std::numeric_limits<T>::min();
}
}
Any portable way to eliminate the warning ?