C++11 user-defined literals
Gabriel Dos Reis
gdr at integrable-solutions.net
Wed Mar 7 10:46:59 CET 2012
On Wed, Mar 7, 2012 at 2:27 AM, Marc Glisse <marc.glisse at inria.fr> wrote:
> 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 will probably satisfy the C API, but my suggestion is that the
C++ API should get the user-defined literal constructor -- you would
not have to worry whether you need to add the 'long long long'
constructor :-)
> 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.
Yes, I find the suffix notation more readable than the string notation.
>
> 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...
Sure.
>
> --
> Marc Glisse
More information about the gmp-discuss
mailing list