C++11 user-defined literals

Hans Aberg haberg-1 at telia.com
Wed Mar 7 16:09:00 CET 2012


On 7 Mar 2012, at 15:53, Gabriel Dos Reis wrote:

>>>>> 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 :-)
>> 
>> Well, the user-defined literal will internally use a string and thus be
>> slower (that kind of construction should rarely matter for the performance,
>> but who knows... and you can't even overload it so it calls a long long
>> version when it fits and a string version when it doesn't). And people will
>> still want interoperability with long long.
> 
> Yes, those are valid observations.  The way I see it is this: the
> user-defined literal
> version always works.  If a user wants to be specific, it would user
> the unsigned int
> constructor or the long long constructor (when it is added.)

You might try making a static version, like in this example below (first answer with bits).

Hans


http://stackoverflow.com/questions/237804/user-defined-literals-in-c11-a-much-needed-addition-or-making-c-even-more-b





More information about the gmp-discuss mailing list