bearophile wrote:
Andrei Alexandrescu:
The real reason is different (multibyte support in std::string is at
best nonexistent). std::vector was defined by Stepanov alone. But by the
time std::string was standardized, many factions of the committee had a
feature on their list. std::string is the result of that patchwork.
Thanks you for the info, I didn't know that. In practice I was mostly talking
about D2, that interests me more than C++.
In D2 strings can be your bidirectional Ranges, while fixed-sized/dynamic arrays can be
random access Ranges (string can be random access Ranges according to just the underlying
bytes. This may require two different syntaxes to access strings, the normal str[] and
something else like str.byte[] for the bytes, and usually only the second one can
guarantee a O(1) access time unless it's a 32-bit wide unicode chars. The access with []
may use something simple, like a "skip list" to speed up access from O(n) to
O(ln n)).
Look for byCodeUnit in here:
http://dsource.org/projects/phobos/browser/trunk/phobos/std/string.d
and improve it.
And to avoid silly bugs D2 associative arrays can allow constant/immutable keys
only (especially when used in safe modules), as in Python. Because if you put a
key in a set/AA and later you modify it, its hash value and position doesn't
get updated.
That's a long discussion, sigh.
Andrei