string / wstring / xwstring

The generic_string template is derived from vararray, and is slightly specialized to provide a traditional “string” class, in the sence of character strings.


This template provides for a common implementation of 8-bit strings (type string), wide 16-bit strings (type wstring), and extra-wide 32-bit strings (type xwstring).

Most of the functionality of the strings are actually those of the vararray, which as a flexible variable-sized array having lazy-copy semantics, is most of what we consider a “string” class already. This class meerly adds the concatenation and comparison operators.

This chapter is not yet written.

Why Use This Class

Why use this generic_string class instead of one of the other string classes?

The reasons are basically the same as for the vararray class: it is robust, thread-enabled, and reference counted.

If you want to pass string data between threads and make use of reference counting to prevent excessive copying or allow shared ownership, this is the class of choice.

Remember that each part of the code can use whichever string library it wants, based on the features it needs. Use the ustring class for passing parameters, and a specific string class for concrete implementation.

Here is a chart that shows the features of generic_string and how it relates to other common string classes. Compare with STL basic_string. Compare with MFC CString Compare with primitive C strings.

Formatting Contents into a String