numeric::interval::abs() bug

The following code does not compile with g++ nor MSVC 2003 because of ambiguity of first argument to std::max() in numeric::abs(). Is a typecast needed in interval/utility.hpp? terry #include <boost/numeric/interval.hpp> #include <iostream> typedef boost::numeric::interval<short> Interval; std::ostream& operator<<(std::ostream& os, const Interval& x) { return os << x.lower() << ".." << x.upper(); } int main() { Interval r1(-3, 7); std::cout << "r1=" << r1 << std::endl; Interval r2 = boost::numeric::abs(r1); std::cout << "r2=" << r2 << std::endl; return 0; } // main

Le vendredi 28 juillet 2006 à 14:51 -0500, Terry Golubiewski a écrit :
The following code does not compile with g++ nor MSVC 2003 because of ambiguity of first argument to std::max() in numeric::abs(). Is a typecast needed in interval/utility.hpp?
Thanks for spotting this shortcoming. You are right, the first argument to max indeed requires static_cast<T>(_). We didn't expect the library to be used with a unary minus operator that looks like "not_T operator- (T)". Unfortunately primitive types shorter than int do have this property. Best regards, Guillaume
participants (2)
-
Guillaume Melquiond
-
Terry Golubiewski