Boost logo

Boost :

Subject: Re: [boost] [config/multiprecision/units/general] Do we have a policy for user-defined-literals?
From: Marc Glisse (marc.glisse_at_[hidden])
Date: 2013-04-28 06:37:52

On Sun, 28 Apr 2013, John Maddock wrote:

>> I think we should just use the obvious short names,
>> and rely on users not to bring conflicting suffixes
>> into scope. If there's a conflict they can always
>> fall back on normal constructors.
> Nod. Short names are my preference too.
> Note however, that constructors may be less efficient in general - cpp_int
> users would have to fall back on a construct-from-string rather than
> constexpr initialisation (the issue is you can't write a number with enough
> digits unless it has a user-defined-suffix).

Can't you construct from string constexpr? Both gcc and clang are happy
with code like this (just an experiment to see what constexpr accepts):

struct uint128 {
   unsigned long h, l;
   constexpr uint128(unsigned long h_, unsigned long l_):h(h_),l(l_){}
   constexpr uint128 lshift(int i)const{
     return uint128{h<<4|l>>60,l<<4|i};
   static constexpr int chartoint(char c){
     return (c>='0'&&c<='9')?c-'0':(c-'a'+10);
   static constexpr uint128 from_string(uint128 tmp, const char* s){
     return (*s==0)?tmp:from_string(tmp.lshift(chartoint(*s)),s+1);

int main(){
   constexpr uint128 a=uint128::from_string(uint128{0,0},"1234567890abcdef123");

Marc Glisse

Boost list run by bdawes at, gregod at, cpdaniel at, john at