Crazy option :)

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