String classes

Started by
1 comment, last by Promit 12 years, 3 months ago
Do you use any string classes other than ::std::string and if so, why? Tia.
Advertisement
In my homegrown projects I commonly use two of my own in addition to std::(w)string:

ref_string: The buffer is immutable and reference-counted. Copying is no-throw, so it can be safely used as a member variable in objects thrown as exceptions.

string_literal: lightweight wrapper around string literal with overloaded comparison operators. Used inside my test library to internally wrap __FILE__, __DATE__, __TIME__, the names of tests, etc.

In the past I've also used any number of string classes that came with other frameworks e.g. QString from Qt, Glib::ustring from glibmm, etc. They are at least somewhat knowledgeable of Unicode.

Another type of string I've seen used is one that interns the buffers in order to allow comparisons to be made quicker (only the pointers need be compared).

To be honest, I find the use of std::string as anything but a container of 'char' somewhat cumbersome. Often that's all that's needed, but as soon as you start having to do string manipulation, it quickly becomes a pain.
I just stick with std::string and char* at the moment, but I'm considering adding a HashString that combines a std::string with a hash value for fast lookups etc. Compile time hashing of literals would be fabulous, but the preprocessor can't do it and I don't want to integrate it into the build.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement