简体   繁体   English

为什么std :: to_string没有短暂的重载? 为什么没有noexcept?

[英]Why no short overloads for std::to_string? Why no noexcept?

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? 有谁知道为什么在C ++ 11标准的第21.5节中声明的各种to_string函数缺少short和unsigned short的重载? How about why these functions are not declared noexcept ? 为什么这些函数没有被声明为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. 我查看了导致这些功能被采纳的提案(N1803,N1982,N2408),但没有一个有任何动机或理由。

If I'm violating protocol by putting two (rather related, IMO) questions in a single post, I apologize. 如果我通过在一个帖子中提出两个(相当相关的,IMO)问题来违反协议,我道歉。 I'm still new at SO. 我还是新人。

Exceptions: there's no noexcept constructor for std::string , so that's just not possible (ie the string memory allocation may fail). 例外: std::string没有noexcept构造函数,所以这是不可能的(即字符串内存分配可能会失败)。

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. 相比之下,较长的类型可能更昂贵,因此应该为空间意识提供int

These functions all do arithmetic on the value that's passed to them. 这些函数都对传递给它们的值进行算术运算。 Types that are smaller than int are promoted to int (or unsigned int) for arithmetic, so there's no computational benefit from having versions that take types smaller than int. 小于int的类型被提升为int(或unsigned int)以进行算术运算,因此使类型小于int的版本没有计算优势。 (These came in through my proposal, so I know the history intimately) (这些来自我的建议,所以我非常了解历史)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM