Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why no short overloads for std::to_string? Why no noexcept?

Tags:

c++

c++11

Does anybody know why the various to_string functions declared in section 21.5 of the C++11 standard lack overloads for short and unsigned short? How about why these functions are not declared noexcept? This is the full set of overloads:

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);

I looked at the the proposals that led to these functions being adopted (N1803, N1982, N2408), but none of them have any motivation or rationale.

If I'm violating protocol by putting two (rather related, IMO) questions in a single post, I apologize. I'm still new at SO.

like image 283
KnowItAllWannabe Avatar asked Aug 20 '12 21:08

KnowItAllWannabe


1 Answers

Exceptions: there's no noexcept constructor for std::string, so that's just not possible (i.e. the string memory allocation may fail).

Shorts: All integral types that are default-promoted are missing; I suppose there'd just be nothing to be gained from supporting them. By contrast, the longer types may be more expensive, so int should be offered for the space conscious.

like image 94
Kerrek SB Avatar answered Nov 15 '22 18:11

Kerrek SB