Request for C++ interface doc improvement

Marc Glisse marc.glisse at inria.fr
Thu Jul 31 06:07:02 UTC 2014


On Wed, 30 Jul 2014, Jerome L Quinn wrote:

> I recently discovered the hard way that the mpz_class string constructor is
> explicit.  Thus the following is a compile error:
>
> string s = "0";
> mpz_class a = s;

Yes. An implicit conversion from string would cause too much trouble. Note 
that you can write it in 2 lines:

mpz_class a;
a = s;

> The docs didn't make this clear.

https://gmplib.org/manual/C_002b_002b-Interface-Integers.html

— Function: explicit mpz_class::mpz_class (const char *s, int base = 0)
— Function: explicit mpz_class::mpz_class (const string& s, int base = 0)

"explicit" is there...

> I'd like to suggest adding to the docs something like the following:
>
>
> Conversions from `string' or `char*' do not happen automatically.
> Construction must be explicit.  For example,
>
>    mpz_class a("245");

You can also write that as:

auto a = 245_mpz;

Where in the docs do you think some extra text would help?

-- 
Marc Glisse


More information about the gmp-bugs mailing list