struct IsNegative<T, false>
{ static bool eval(T) { return false; } };
+template<typename T, bool f = is_signed<T>::value>
+struct Negate
+{ static T eval(T v) { return -v; } };
+
+template<typename T>
+struct Negate<T, false>
+{ static T eval(T v) { return (~v)+1; } };
+
/* Helper to avoid errors about ambiguous function calls since there are no
overloads of abs for unsigned types */
template<typename T, bool f = is_signed<T>::value>
}
if(neg)
- result = -result;
+ result = Negate<T>::eval(result);
return result;
}