generic_stringtemplate is derived from vararray, and is slightly specialized to provide a traditional “string” class, in the sence of character strings.
string), wide 16-bit strings (type
wstring), and extra-wide 32-bit strings (type
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.
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.