我可以在 g++ 中使用可变参数模板(但不能使用其他 c++0x 功能)吗?
我们的想法是,由于可变参数模板是编译时功能,因此 ABI 影响或运行时行为变化很小。这可能吗?
我特别希望 boost::mpl::vector 和 boost::mpl::string 的编译时间更快。
重新表述问题...
是否可以通过将 c++03 和 c++11 代码分离到库中来混合它们?也就是说,我们使用了很多与 gcc 4.3 兼容的第三方 c++ 库,但我们也正在转向 gcc 4.7,并打算在可能/有意义的情况下使用 c++11 功能。或者说c++11和c++03不可能混合使用吗?
The thinking is that since variadic templates are a compile time feature, there will be little ABI impact or runtime behaviour change. Is this possible?
I specifically want the benefit of faster compile times for boost::mpl::vector and boost::mpl::string.
Rephrasing the question...
Is it possible to mix c++03 and c++11 code by separating them into libraries? I.e. we use quite a few 3rd party c++ libraries which are compatible with gcc 4.3 but we are moving on too gcc 4.7 and intend to use c++11 features where possible/makes sense. Or is it impossible to mix c++11 and c++03?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用在兼容模式下运行的相同工具来编译和链接所有内容。你不能挑选这样的功能。
例如,ABI 的影响体现在标准 I/O 类的虚拟功能表的增加。混用东西是不安全的。
You should compile and link everything using the same tools running in compatible modes. You can't cherry-pick features like this.
The ABI impact comes in, for example, increased virtual function tables for standard I/O classes. It is not safe to mix things around.
我无法给出合格的答案,但据我了解,很多人会担心这种向后兼容性是否会被破坏。据我了解,新的 C++11 中没有任何内容需要重建所有内容。因此,只有您的特定编译器才需要这样做。对于 GCC,我不期望它,但不同的 libstdc++ 版本可能会产生“问题”。
我强烈的猜测是,在典型的(英特尔)Linux 上,您应该能够使用不同的新版本的 gcc(可能> 4.x)创建两个独立的库,并将它们使用/链接到最终程序中。不过,有些东西可能会出现两次。我在 4.7.0 和
中遇到了一些可解决的小问题。我不知道他们是否会与其他线程库(例如 boost)创建一个好的或坏的组合。但是,您还不想在生产代码中使用 gcc-4.7.0。在最终的 gcc 编译器发布之前,只有负责项目团队的声明才能给您确定性。I cant give a qualified answer, but from what I understood is, that lots of people would be concerned if this kind of backward-compatibility would be broken. As far as I understood there is nothing in the new C++11 that makes it necessary to rebuild everything. Thus, it could only be your specific compiler that would make that necessary. For the GCC I dont't expect it, although, the different libstdc++ versions could create "issues".
My strong guess is, that on a typical (intel-) linuxes you should be able to create two independent libs with different decently new versions of the gcc (maybe >4.x) and use/link them into a final program. You may have some things in there twice, though. I had some minor solvable issues with threads in 4.7.0 and
<thread>
. I don't know if they would create a good or bad mix with other thread-libs (eg. boost). However, you don't want to use gcc-4.7.0 for your production code, yet. And before a final gcc compiler is out, only a statement from the responsible projects team can give you certainty.