I recently learned, that since a few years the library libstdc++ contains vstring
(also known as versa_string
), which provides the same functionality as std::string
, but is apparently more conforming to the C++ standard. I have tried to use vstring
as a replacement for std::string
, but I have found no easy way to do it.
Is there an easy way to replace std::string
with vstring
, without changing the libstdc++ sources?
I am fine with replacing all uses of std::string
within my code by an alias, as indicated by the following listing. However, the problem with this approach is, that std::string
is also used internally in some places, e.g. in std::ostringstream
. That means, the statements std::ostringstream os; my::string s = os.str();
no longer works.
namespace my {
#ifdef __GLIBCXX__
using string = __gnu_cxx::__vstring;
#else
using string = std::string;
#endif
}
vstring
was added in 4.1. See https://mcmap.net/q/427724/-what-is-gcc-39-s-quot-vstring-quot. – Dwarfishstd::string
non-ref counted, but I don't see that in the release notes. You can fix the error in the one case you've listed by usingmy::string s = os.str().c_str();
instead. There might even be a way to access the underlying streambuf to avoid the intermediatestd::string
, but I'm not sure of that part. – Lodhiastd::string
in the library. You'll have to wait for GCC 4.10 – Sociology