What is GCC's "vstring"?

Solution 1:

GCC's vstring is a versatile string class, which was introduced in GCC 4.1's libstdc++ implementation.

It is compatible with std::basic_string, with these additional details:

  • Two base classes are provided:
    • the default one avoids reference counting and is optimized for short strings;
    • the alternate one, still uses it (reference counting, that is) while improving in a few low level areas (e.g., alignment). See vstring_fwd.h for some useful typedefs.
  • Various algorithms have been rewritten (e.g., replace), the code streamlined and simple optimizations added.
  • Option 3 of DR 431 is implemented for both available bases, thus improving the support for stateful allocators.

DR431 is Library Working Group Defect Report 431, with option 3 looking like implementing better allocator support for the class to allow better swapping and other allocator-related operations.

The basic details are from GCC 4.1's release notes, under the Runtime Library section.

edit:

It looks as though the original purpose of this extension was to provide a basis for a C++11 std::string implementation. Paolo Carlini, a GCC/libstdc++ contributor, comments in this GCC Bug Report that <ext/vstring.h> contains a non-reference counted experimental version of the next std::string. Comment dated April 12, 2012:

What we tried to explain is that this sort of issue is well known and, more or less, affects any reference counted implementation... That is not the case when reference counting is not used and indeed it will not be used (per the new C++11 Standard) in a new implementation of std::string which we are currently showcasing as <ext/vstring.h>...