I would like to detect overflow in a function, before I multiply a
variable X of integral type X_type by 2.
I could write:
if (X > std::numeric_limits<X_type>::max() / 2)
but this causes an extra dependency on X's type.
I had considered writing an helper function to work as a typeof
replacement:
template <class T>
T numeric_limits_max(T) { return std::numeric_limits<T>::max(); }
and then I could write:
if (X > numeric_limits_max(X) / 2) ...
Something similar could be done for min(), of course. I was wondering if
such functions would be useful as part of the boost facilities in
integer_traits.
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost