在 C++0x 中是否有类似 static_assert 的东西会给出警告而不是错误?
我想对可能效率低下但不一定不正确的用法执行此操作。
I would like to do this for usages which may be inefficient but not necessarily incorrect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
否。
断言失败表示存在阻止程序完成的问题(执行 [运行时断言] 或编译 [静态断言])。
事实上,只要实现发出诊断(包括继续执行),就可以执行任何操作。但实际上,主流工具链的行为几乎都是相同的:它们都会出错。您当然不能将它们破解为用户定义的内容。
No.
An assertion failure indicates a problem preventing the program from being completed (be that execution [run-time assertions], or compilation [static assertions]).
In truth, an implementation is allowed to do anything as long as they emit a diagnostic (including continuing execution). But, in practice, mainstream toolchains will all behave pretty much the same: they will error out. You certainly can't hack them to something user-defined.
为此目的,C++0x 中引入了这些属性。请参阅http://docwiki.embarcadero.com/RADStudio/en/C%2B% 2B0x_attribute_deprecated 为例。
The attributes are introduced in C++0x for that purpose. See http://docwiki.embarcadero.com/RADStudio/en/C%2B%2B0x_attribute_deprecated for an example.
不符合标准,不。您可以在许多编译器中找到
#warning
,但在大多数情况下这实际上并不相同。Not as Standard, no. You can find
#warning
in many compilers, but that's really not the same in most situations.