$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-12-18 09:01:59
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.