Re: std::string bad design????
jaibuduvin@gmail.com (Le Chaud Lapin) wrote (abridged):
You should try the iterators-state-in-the-container model. Everyone I
have met who has experience the pleasure of not having to create an
iterator to go with a container has raved about it, from students to
colleagues. It's addictive, and especially attractive when you are
iterating over a container that is 3-levels deep inside nested
containers.
The drawback is that if two pieces of code iterate over the same container
at the same time, they interfere with each other. The shared iterator
state is a channel for side-effects.
Sometimes - perhaps most of the time - you can guarantee that will never
happen, but for a general purpose library like the C++ standard it's not
acceptable in my view. You need to provide external iterators as well (or
at least a way to save and restore iteration state), and once you have
them you might as well use them always. Side-effects are evil.
In my view the real problem with STL iterators is that you need two of
them to define a range. That's convenient for some algorithms, such as
sorting, but for most simple loops it's better to have a single object,
with an at_end() function to tell you when to stop incrementing it.
IMO, the most blatant wart, aside from letting iterators be external
to containers, is the notion that all containers are linear, in
the "movement" of the iterator is 1 dimensional. But trees are
containers, very useful containers, and we do not have a tree<>
template in STL. I suspect that the reason we don't is because
it would illuminate the fact algorithms-are-universally-applicable
model is not so universal, and that containers do not all fall under
the linear model.
I suspect the reason is that no-one submitted a high-quality tree library
to the standard's committee. I very much doubt that any submission was
rejected for the reason you give. The standard already contains several
difference kinds of iterator, which is a tacit admission that different
algorithms have different requirements.
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]