Crazy option :)

1
2
3
4
5
6
7
8
template<typename T>
T sign(T x)
{
enum { CONSTRAINT = static_cast<T>(0) };
const int T_BIT = sizeof (T) * CHAR_BIT;
const int SHIFT = T_BIT - 1;
return x >> SHIFT | !!x;
}