Why I (Still) Won't Use D
Sean Kelly
sean at invisibleduck.org
Fri Mar 28 10:14:45 PDT 2008
== Quote from Janice Caron (caron800 at googlemail.com)'s article
> On 28/03/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
> > Yet I'm always left wondering what is the difference between vector and
> > string?
> In Microsoft Visual Studio's implementation, std::string implements
> copy-on-write, wheras std::vector doesn't.
I'm sorry, but unless I missed a memo, this hasn't been the case for probably
ten years. It's been shown fairly conclusively that STL-conformant COW strings
are incompatible with multithreaded programs, and Dinkumware has long since
switched them for a non-COW design. Did they change them back with VS 8.x?
Personally, I think the difference between vector and string is largely in the
operations they support. Here are the gaps, from a quick glance at the standard:
vector:
back
front
pop_back
string:
append
c_str
compare
copy
data
find
find_first_not_of
find_first_of
find_last_not_of
find_last_of
length
npos
operator+=
operator=
replace
rfind
substr
The important thing to note about the routines added to string (such as find) is
that they have overloads which accept value_type* as an argument, for easy
integration with C-style strings. c_str and data are much the same, and one
can assert that strings may always be ordered while vectors may not (ie. compare).
Overall though, I find the D approach to make more sense. Strings are really just
a sequence of characters, so why bother with two separate containers? However,
I wouldn't be surprised if a redesign today did something along these lines as
well, and relied on <algorithm> plus perhaps some helper functions to handle
the various operations currently embedded for convenience in the classes
themselves.
Sean
More information about the Digitalmars-d
mailing list