根据C ++标准,C ++标准库的实现是否可以增强标准定义的C ++标准库的方法和其他功能的noexcept规范?
According to the C++ standard, are implementations of the C++ standard library allowed to strengthen noexcept specifications of methods and other functions of the C++ standard library as defined by the standard?
例如,如果C ++标准将某些功能std::f指定为void f();,是否允许标准库实现将其作为void f() noexcept;实现?
For example, if the C++ standard specifies some function std::f as void f(); are standard library implementations allowed to implement it as void f() noexcept; instead?
推荐答案标准回答是:
§17.6.5.12.1对异常处理的限制 [res.on.异常处理]
§ 17.6.5.12.1 Restrictions on exception handling [res.on.exception.handling]
[...]
在C ++标准库中定义的
(逗号4似乎只允许对异常规范进行明确说明,并警告说缺少明确的异常规范意味着允许实现抛出任何异常).
(Comma 4 seems to just allow to be explicit about the exception specification, and to warn that the lack of an explicit exception specification means that the implementation is allowed to throw anything).
说实话,我不明白为什么允许这样做,而不允许添加constexpr(第17.6.5.6节).它们看起来像是同一枚勋章的两面-通过使用trait traits和SFINAE,您可以拥有根据所使用的标准库实现显示不同行为的代码(如果它将某些功能标记为noexcept/constexpr,或者如果不是这样的话,那首先就违背了建立标准的目的...
To be honest, I don't understand why this is allowed and adding constexpr is not (§ 17.6.5.6). They look like the two sides of the same medal -- by using type traits and SFINAE you can have code which shows different behaviours depending on which Standard Library implementation you use (if it marks some functions as noexcept/constexpr, or if it doesn't), and that defeats the purposes of having a standard in the first place...
更多推荐
是否允许C ++标准库实现增强noexcept规范?
发布评论