
Le lun 08/03/2004 à 18:53, Michael Stevens a écrit :
Eric,
The recent changes to the new std_min/std_max caused some unexpected problems in uBLAS. I have narrowed them down to support for boost::numeric::interval in uBLAS. This is picked up by ublas/libs/test7. This test is however not at present part of the regression run.
The new std_max (or std_min) is implemented by returning a constant reference to the return value of std::max. This should be OK as std::max similarly returns a const reference to one of its const reference parameters. For gcc this causes some problems when the type is a boost::numeric::interval. The test case is very simple.
#include <boost/numeric/interval.hpp> #include <boost/minmax.hpp>
int main() { boost::numeric::interval<float> a,b,c; c = boost::std_max(a, a); }
gcc (2.95.3 and 3.3.1) is only warning "returning reference to temporary". I am surprised this doesn't show up in more cases. Why gcc thinks it needs a temporary here is beyond me
Hi, The reason is: the return type of the function max(interval const &, interval const &) is not a constant reference, it is a temporary (since the maximum of two intervals is not one of these two intervals when they overlap). Consequently, since std_max has been defined so that it returns a reference, it can't be used when one argument is an interval and GCC is right to complain. Consequently, having std_min and std_max functions was not a good solution. Is it possible to have macros that behave like them (that way there would be no return type problem)? However, in the particular case of uBLAS, the problem lies elsewhere imho. At lines 620-621, 688-689, 753-754 of ublas/traits.hpp in the equals function, uBLAS should not be using the norm_inf function. Indeed norm_inf relies on abs(interval); and what is really needed is a norm_inf_for_equals function that would rely on norm(interval). The same problem will also appear later with complex intervals. This solution should solve the issue with uBLAS. But the more general issue of the return type of std_min and std_max is still here. Regards, Guillaume