gmpxx implicit conversion between types

Emmanuel Thomé Emmanuel.Thome at gmail.com
Mon Mar 7 10:03:40 CET 2011


On Sat, Mar 05, 2011 at 09:20:38PM +0100, Marc Glisse wrote:
> Hello,
> 
> currently, gmpxx has implicit conversions between all types. For
> instance, if I have:
> void f(mpz_class);
> void f(mpq_class);
> mpq_class q;
> f(q+q);
> 
> this last call is ambiguous as q+q can just as well be converted to
> a mpz_class as a mpq_class. Without the second line, q+q would
> silently be converted to an integer, which I think is scary.

Yes it is scary in my opinion as well.

> One thing that would be possible is making it so that this
> conversion is only possible if explicitly asked for, like
> mpz_class(q+q), but doesn't happen implicitly in f(q+q). It wouldn't
> change the fact that any integral expression can implicitly be
> converted to a rational, which is ok.

I would consider this a sensible change, despite the fact that it would
break code relying on the implicit conversion.

E.


More information about the gmp-discuss mailing list