C++11 user-defined literals

Marc Glisse marc.glisse at inria.fr
Wed Mar 7 09:27:42 CET 2012

On Tue, 6 Mar 2012, Gabriel Dos Reis wrote:

> On Mon, Mar 5, 2012 at 2:23 PM, Marc Glisse <marc.glisse at inria.fr> wrote:
>> Hello,
>> in C++11, we could make it so that writing 2_mpz or "-123/17"_mpq would be
>> equivalent to mpz_class(2) or mpq_class("-123/17"). Does that seem useful to
>> anyone? If it does, what suffix do you think would be best (like _mpz and
>> _mpq in my example, with the constraint that it has to start with an
>> underscore)?
> I believe it is actually very useful (assuming you have a C++11 compiler such as
> GCC-4.7.x) for reason you stated: is your integer literal does not fit
> 'unsigned long'
> (and you would actually like to use 'long long' or 'unsigned long
> long') you are kind
> of stuck with the current (limited) interface.

Do you mean that gmp should get 'long long' constructors? That is true, 
but (mostly) orthogonal to the use of the suffix notation.

Unless I am missing something, whenever people write something_mpz, it 
will be equivalent to mpz_class(something) or mpz_class("something"), 
which is quite readable and not much longer.

I am not opposed to adding it, but I don't want to add a bad 
implementation that misses all the benefits, so I need to make sure I 
understand them...

Marc Glisse

More information about the gmp-discuss mailing list