是 C++ (03)SFINAE方面编译器独立吗?
我有一个头文件,其功能在很大程度上依赖于SFINAE的成功。在当前的 g++ 4.6
中,它按预期工作。我是否应该假设,我的代码对于所有编译器(C++03 编译器)都会以相同的方式无缝运行?
我发现这是一个问题,因为如果有什么不同,它不会导致编译器错误,并且会默默地改变代码流。
I have a header file, whose functionality relies heavily on the success of SFINAE. In present g++ 4.6
it works as expected. Should I assume that, my code will behave seamlessly in the same way for all compilers (C++03 compilers) ?
I find this as an issue, because if something differs it won't result in compiler error and silently would change the code flow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于这取决于 SFINAE 的成功,因此您应该使用
static_assert
(或BOOST_STATIC_ASSERT
)来确保 SFINAE 成功通过。我不知道您的代码是否适用于所有编译器,但如果特定编译器无法为特定 SFINAE 生成预期输出,则静态断言将使编译失败。
Since it depends on the success of the SFINAE, you should use
static_assert
(orBOOST_STATIC_ASSERT
) to make sure the SFINAE passed successfully.I do not know if your code would work on all compilers, but the static assert would fail the compilation if a specific compiler fails to produce expected output for specific SFINAE.
是的,您可以依赖 SFINAE 来存在并正常运行。
如果你的编译器在这方面失败了,那么它最终是不符合规范的,无论如何,所有的赌注都会落空。
Yes, you may rely on SFINAE to exist and function properly.
If you have a compiler that fails at it, then it's terminally non-conformant and all bets are off anyway.