Is it possible to use C++11 ABI _and_ both cxx11-style and old-style strings?

北城余情 提交于 2021-02-08 10:14:44

问题


I have some code which is being built with GCC 5.3.1 without _GLIBCXX_CXX11_ABI set. Now, suppose I want to use both old-style and new-style std::__cxx11::string's in the same bit of code . Is that possible? If so, how?

Notes:

  • I don't really have a good reason for doing this. I do have a not-so-good reason, but let's make it a theoretical question please.
  • It's ok if the C++11 strings aren't called std::string.

回答1:


Can you have both the old and new string implementation in the same code? Not exactly. The Almighty Manual states:

ABI transition adds new implementations of several components, using the abi_tag attribute and the __cxx11 inline namespace to distinguish the new entities from the old ones.

  • Use of the new or old ABI can be selected per-translation unit with the _GLIBCXX_USE_CXX11_ABI macro.

  • New non-reference-counted string implementation.

Now you could theoretically compile with -D_GLIBCXX_USE_CXX11_ABI=0 and use ext/vstring.h, which was GCC's conforming string implementation before the breaking ABI change. I wouldn't be surprised if things blew up, though.



来源:https://stackoverflow.com/questions/37623580/is-it-possible-to-use-c11-abi-and-both-cxx11-style-and-old-style-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!