Title
Insufficent overloads for to_string / to_wstring
Status
c++11
Section
[string.conversions]
Submitter
Christopher Jefferson

Created on 2009-11-10.00:00:00 last changed 154 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

[string.classes], change to_string and to_wstring to:

string to_string(int val);
string to_string(unsigned val);
string to_string(long val);
string to_string(unsigned long val);
string to_string(long long val); 
string to_string(unsigned long long val); 
string to_string(float val);
string to_string(double val);
string to_string(long double val);

wstring to_wstring(int val);
wstring to_wstring(unsigned val);
wstring to_wstring(long val);
wstring to_wstring(unsigned long val);
wstring to_wstring(long long val); 
wstring to_wstring(unsigned long long val); 
wstring to_wstring(float val);
wstring to_wstring(double val);
wstring to_wstring(long double val);

In [string.conversions], paragraph 7, change to:

string to_string(int val);
string to_string(unsigned val);
string to_string(long val);
string to_string(unsigned long val);
string to_string(long long val); 
string to_string(unsigned long long val); 
string to_string(float val);
string to_string(double val);
string to_string(long double val);

7 Returns: each function returns a string object holding the character representation of the value of its argument that would be generated by calling sprintf(buf, fmt, val) with a format specifier of "%d", "%u", "%ld", "%lu", "%lld", "%llu", "%f", "%f", or "%Lf", respectively, where buf designates an internal character buffer of sufficient size.

In [string.conversions], paragraph 14, change to:

wstring to_wstring(int val);
wstring to_wstring(unsigned val);
wstring to_wstring(long val);
wstring to_wstring(unsigned long val);
wstring to_wstring(long long val); 
wstring to_wstring(unsigned long long val); 
wstring to_wstring(float val);
wstring to_wstring(double val);
wstring to_wstring(long double val);

14 Returns: Each function returns a wstring object holding the character representation of the value of its argument that would be generated by calling swprintf(buf, buffsz, fmt, val) with a format specifier of L"%d", L"%u", L"%ld", L"%lu", L"%lld", L"%llu", L"%f", L"%f", or L"%Lf", respectively, where buf designates an internal character buffer of sufficient size buffsz.

Date: 2009-11-14.00:00:00

[ 2009-11-14 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]

Date: 2009-11-10.00:00:00

Reported on the gcc mailing list.

The code "int i; to_string(i);" fails to compile, as 'int' is ambiguous between 'long long' and 'long long unsigned'. It seems unreasonable to expect users to cast numbers up to a larger type just to use to_string.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg1356
2010-10-21 18:28:33adminsetmessages: + msg1355
2009-11-10 00:00:00admincreate