gmpxx implicit conversion between types

Marc Glisse marc.glisse at inria.fr
Sat May 7 19:45:21 CEST 2011


On Sat, 7 May 2011, Gabriel Dos Reis wrote:

> On Sat, May 7, 2011 at 1:19 AM, Marc Glisse <marc.glisse at inria.fr> wrote:
>> What I eventually implemented is:
>> when the addition of an element of type A and an element of type B yields an
>> element of type B: keep the conversion A->B implicit, and make the reverse
>> conversion B->A explicit.
>>
>> In practice, this means that the following conversions are now explicit:
>> mpq_class -> mpz_class
>> mpf_class -> mpz_class
>> mpf_class -> mpq_class
>>
>> There is still time to complain and get me to change that :-)
>
> If you are also detecting the C++ compiler being used, do you think
> you could use the "explicit conversion operator" facility
> available in new C++ (assuming your compiler supported it)?

Hello,

I am not sure what you are suggesting exactly. The conversions are done 
using constructors, not conversion operators, so explicit is available 
even in C++98. And since the conversions are really from "any rational 
expression" to "exactly mpz_class", it is more convenient as constructors.

If the situation was different and it was done with conversion operators, 
I guess using the new explicit conversions would be a possibility, except 
that I am not too happy about having wildly different behavior on 
different platforms. For C++0X features, adding move constructors / 
assignment would be less of a problem.

-- 
Marc Glisse


More information about the gmp-discuss mailing list