What's C's biggest mistake?

Kevin Bealer kevinbealer at gmail.com
Sat Jan 2 03:58:10 PST 2010


bearophile Wrote:

> Walter Bright:
> > 3. The glaring fact that std::vector<char> and std::string are different 
> > suggests something is still wrong.
> 
> In an array/vector you want O(1) access time to all items (ignoring RAM-cache access/transfer delays), while in a string with variable-width Unicode encoding that can be hard to do. So they look like two different data structures.
> 
> Bye,
> bearophile

Yeah, I think the charset thing was probably the main reason for the string/vector split, that and the desire to have special properties like conversion from char* that wouldn't be in vector.  Using basic_string<T> with locales is something of a historical wart, because with Unicode, getting your charset from your locale is somewhat obsolete for general purpose computers.  (Maybe very small profile systems will continue to use ascii or the code page of whatever culture buildt them.)

But I don't think C++'s string can be made to index by character unless you use wchar_t for the T in basic_string<T>.  I don't think string.size() is ever anything but a bytes or wchar_t count.

Kevin




More information about the Digitalmars-d mailing list