Topic: Q: Why class basic_string instead of class string?


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: 1995/07/04
Raw View
alexl@eng.sun.com (Alex Lefaive) writes:

>Why call it basic_string instead of just string?

`basic_string' is the name of the template,
but the name `string' is also defined, as

 typedef basic_string<char> string;

The reason for making `basic_string' a template rather than just having
a plain `string' class is so that the standard can also have

 typedef basic_string<wchar_t> wstring;

and so you can create string classes for your own character types.

--
Fergus Henderson
fjh@cs.mu.oz.au
http://www.cs.mu.oz.au/~fjh
"The unexamined life is not worth living" - Socrates.





Author: alexl@eng.sun.com (Alex Lefaive)
Date: 1995/06/29
Raw View
Why call it basic_string instead of just string?
I'm hoping the ANSI C++ String class is sufficient
for 95-99% of the users out there. Calling it basic_string
makes me think that it is somehow inferior, and that I'll
still need to use the string class from Rogue Wave, USL, etc.

I really haven't perused the whole document, but I think I
also saw some other classes also using the basic_ prefix. What
was the rationale for this?

-Alex

--

R. Alex Lefaive alex.lefaive@eng.sun.com





Author: peter@chinook.physics.utoronto.ca (Peter Berdeklis)
Date: 1995/06/29
Raw View
According to Dietmar Kuehl <dietmar.kuehl@uni-konstanz.de>:
> Hi,
> Alex Lefaive (alexl@eng.sun.com) wrote:
> :
> : Why call it basic_string instead of just string?
>
> You may have noted that basic_string is a template class.
> If basic_string was named "string" the following would be
> impossible:
>
>   typedef basic_string<char> string;
>
> Exactly this typedef is part of the standard: see lib.string (21.1.2).
> The same holds for all those other classes with a 'basic_' prefix:
> They are all templates and there is always a typedef provided for
> the "natural" usage of this class.


Another nice typedef which is part of the standard is:

typedef basic_string<wchar_t> wstring; // note the w

Again, this is also true for all those other classes with a 'basic_'
prefix. (eg. wostream, wistream)


The idea is that since char's and wchar_t's have so much in common
(i.e. they're both 'containers' for char data), that all classes
that deal with them should be derived from a common base class,
in proper OOD fashion.  It's one of the things I like most about
the Std Lib's.


Pete






Author: kuehl@uzwil (Dietmar Kuehl)
Date: 1995/06/29
Raw View
Hi,
Alex Lefaive (alexl@eng.sun.com) wrote:
:
: Why call it basic_string instead of just string?

You may have noted that basic_string is a template class.
If basic_string was named "string" the following would be
impossible:

  typedef basic_string<char> string;

Exactly this typedef is part of the standard: see lib.string (21.1.2).
The same holds for all those other classes with a 'basic_' prefix:
They are all templates and there is always a typedef provided for
the "natural" usage of this class.

dk
--
http://www.informatik.uni-konstanz.de/~kuehl
dietmar.kuehl@uni-konstanz.de
I am a realistic optimist - that's why I appear to be slightly pessimistic