[c++0x] Ambiguity using std::to_string

View: New views
6 Messages — Rating Filter:   Alert me  

[c++0x] Ambiguity using std::to_string

by Germán Diago :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello. I've been using std::to_string and I don't know if it's a bug,
but it's usability is horrible because:

int year;

std::to_string(year);

causes an ambiguity between long long double, long long int and long
long double.

So the way to avoid this is:

to_string((long long)year);

Shouldn't this be a better match for long long int? Because this way
of using it annoys me quite a bit and
it makes it unconfortable to use:

Maybe there should be an overload for every type including int, long
int, unsigned int, double, long double and float.
Would this prevent ambiguities?

I looked at the draft c++ standard (the last one available (N2960) )
and it does not include anything apart of
long long int and long long double.

Thanks.

Re: [c++0x] Ambiguity using std::to_string

by Christopher Jefferson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 10 Nov 2009, at 08:24, Germán Diago wrote:

> Hello. I've been using std::to_string and I don't know if it's a bug,
> but it's usability is horrible because:
>
> int year;
>
> std::to_string(year);
>
> causes an ambiguity between long long double, long long int and long
> long double.
>
> So the way to avoid this is:
>
> to_string((long long)year);
>
> Shouldn't this be a better match for long long int? Because this way
> of using it annoys me quite a bit and
> it makes it unconfortable to use:
>
> Maybe there should be an overload for every type including int, long
> int, unsigned int, double, long double and float.
> Would this prevent ambiguities?

I agree with you. I think this is a case of someone trying to be too clever, and not realising that the set of overloads they specified was not enough.
>
> I looked at the draft c++ standard (the last one available (N2960) )
> and it does not include anything apart of
> long long int and long long double.
>
> Thanks.


Re: [c++0x] Ambiguity using std::to_string

by Paolo Carlini-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Christopher Jefferson wrote:
> I agree with you. I think this is a case of someone trying to be too clever, and not realising that the set of overloads they specified was not enough.
>  
I agree. Probably we should simply file a DR. Chris, care to ask the
library reflector, just in case we are missing something?

Thanks,
Paolo.

Re: [c++0x] Ambiguity using std::to_string

by Christopher Jefferson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 10 Nov 2009, at 15:43, Paolo Carlini wrote:

> Christopher Jefferson wrote:
>> I agree with you. I think this is a case of someone trying to be too clever, and not realising that the set of overloads they specified was not enough.
>>
> I agree. Probably we should simply file a DR. Chris, care to ask the
> library reflector, just in case we are missing something?

Yes, on the case, will submit DR and get a discussion going. However this is fixed, the current situation is clearly embarrassing.

Chris

Re: [c++0x] Ambiguity using std::to_string

by Germán Diago :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Yes, on the case, will submit DR and get a discussion going. However this is fixed, the current situation is clearly embarrassing.

Anyway I think someone could add in gcc the overloads as an extension.

Re: [c++0x] Ambiguity using std::to_string

by Paolo Carlini-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Germán Diago wrote:
>> Yes, on the case, will submit DR and get a discussion going. However this is fixed, the current situation is clearly embarrassing.
>>    
> Anyway I think someone could add in gcc the overloads as an extension.
>  
I added the overloads yesterday, per the proposed resolution of DR 1261
as filed by Chris.

Paolo.