Topic: vector and random access


Author: jkanze@otelo.ibmmail.com
Date: 1998/05/06
Raw View
In article <355016D8.372C@pratique.fr>#1/1,
  Valentin Bonnard <bonnardv@pratique.fr> wrote:
>
> Bradd W. Szonye wrote:
>
> > Or perhaps they were talking about something else? But I'm pretty sure
> > that the assertion was that you couldn't treat a vector like a "random
> > access container." Could it have been strings, not vectors? Since they
> > follow the less strict "sequence requirements." I hope.
>
> Which guru ? Where ?
>
> Sure, a vector is a random access container. It's even the
> more common example of random access container. And string
> should also be one, and IMO the differences (if any) between
> random access container requirements and string requirements
> are bugs, not features.

Are you sure?  String is required to support things like replace, where
the replace string has a different length; vector is not.  Strings are
often copied, vectors are not.  (There is an expressed intent to allow
shared representation of strings, whereas this is not allowed for
vector.)  On the other hand, accessing a string through operator[] is
probably a fairly rare operation -- you are typically more interested in
substrings within the string (and you should use iterators to find them,
not []).

Globally, there are less performance constraints on string, because (I
suppose) any performance constraint on one operation would force another
operation to have poor performance; apparently the committee felt it
better to let the implementers, and ultimately market presure, decide
what was important.

--
James Kanze    +33 (0)1 39 23 84 71    mailto: kanze@gabi-soft.fr
        +49 (0)69 66 45 33 10    mailto: jkanze@otelo.ibmmail.com
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
Conseils en informatique orient   e objet --
              -- Beratung in objektorientierter Datenverarbeitung

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/05/06
Raw View
Bradd W. Szonye wrote:

> Or perhaps they were talking about something else? But I'm pretty sure
> that the assertion was that you couldn't treat a vector like a "random
> access container." Could it have been strings, not vectors? Since they
> follow the less strict "sequence requirements." I hope.

Which guru ? Where ?

Sure, a vector is a random access container. It's even the
more common example of random access container. And string
should also be one, and IMO the differences (if any) between
random access container requirements and string requirements
are bugs, not features.

--

Valentin Bonnard                mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]