|
Boost : |
Subject: Re: [boost] [review] Multiprecision review (June 8th - 17th, 2012)
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2012-06-28 18:14:41
Mario wrote:
>> x = max( a+b , a*b )
Christopher wrote:
>It works when the template parameter of std::max() is explicitly provided.
>The code below, for example, successfully compiles.
>boost::multiprecision::cpp_dec_float_100 c = std::max<boost::multiprecision::cpp_dec_float_100>(a + b, a * b);
>It does seem strange that the compiler needs an explicit template parameter for dis-ambiguity regarding the results of binary arithmetic.
The result of the operator function call is an expression template (I'm guessing he had expression templates enabled). You are forcing an implicit cast to temporaries of the number type by specifying the max template parameter. a+b has a different expression template type than a*b. Since max takes only one template parameter you can't specify two different types as arguments and expect it to be able to deduce.
template <class T> const T& max(const T& a, const T& b);
Presumably disabling expression templates would have worked for Mario because a+b and a*b would result in temporaries both of type cpp_dec_float_100 rather than temporaries of different expression template types.
Regards,
Luke
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk