0

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.
einpoklum
  • 118,144
  • 57
  • 340
  • 684

1 Answers1

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.

  • Wait, isn't that contradictory? I mean, vstring is the old implementation, and `-D_GLIBCXX_USE_CXX11_ABI=0` will give me the old implementation as `std::string`. Or am I wrong? – einpoklum Jun 03 '16 at 21:58
  • @einpoklum No, copy-on-write is the old string implementation, "non-reference-counted" is the new one (aka `vstring`. What I'm saying is there's no reason to use `vstring` in C++11/the new ABI). – uh oh somebody needs a pupper Jun 03 '16 at 22:01