gmpxx implicit conversion between types

Marc Glisse marc.glisse at inria.fr
Mon Mar 7 17:23:31 CET 2011


On Mon, 7 Mar 2011, Emmanuel Thomé wrote:

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

Attached is a patch that prevents implicit conversions from mpq and mpf to 
mpz. It might be a good idea to also disable conversions to mpf, but I 
don't know, I need other opinions. Conversions to mpq sound fine to me (no 
loss of information, although an mpf may generate a huge mpq).

-- 
Marc Glisse
-------------- next part --------------
*** gmp.ff46de76bb88/gmpxx.h	2011-03-07 17:06:49.307446109 +0100
--- /data/repos/gmp/gmpxx.h	2011-03-07 17:05:22.494916282 +0100
***************
*** 1541,1552 ****
  
    // constructors and destructor
    __gmp_expr() { mpz_init(mp); }
  
    __gmp_expr(const __gmp_expr &z) { mpz_init_set(mp, z.mp); }
    template <class T, class U>
!   __gmp_expr(const __gmp_expr<T, U> &expr)
    { mpz_init(mp); __gmp_set_expr(mp, expr); }
  
    __gmp_expr(signed char c) { mpz_init_set_si(mp, c); }
    __gmp_expr(unsigned char c) { mpz_init_set_ui(mp, c); }
  
--- 1541,1555 ----
  
    // constructors and destructor
    __gmp_expr() { mpz_init(mp); }
  
    __gmp_expr(const __gmp_expr &z) { mpz_init_set(mp, z.mp); }
+   template <class T>
+   __gmp_expr(const __gmp_expr<mpz_t, T> &expr)
+   { mpz_init(mp); __gmp_set_expr(mp, expr); }
    template <class T, class U>
!   explicit __gmp_expr(const __gmp_expr<T, U> &expr)
    { mpz_init(mp); __gmp_set_expr(mp, expr); }
  
    __gmp_expr(signed char c) { mpz_init_set_si(mp, c); }
    __gmp_expr(unsigned char c) { mpz_init_set_ui(mp, c); }
  


More information about the gmp-discuss mailing list