Topic: vector will be contiguous (Was: variable length arrays in C++ (was: R
Author: scorp@btinternet.com (Dave Harris)
Date: 1999/07/31 Raw View
alain@sophia.cnrs.fr (Alain Miniussi) wrote:
> I am not sure that the purpose of a standard is to decide the best
> implementation for a general purpose template.
Well, in my view the STL is generally over-specified. For example, there
are a great many ways to implement a map. Even if we rule out hash-tables,
many ways remain - eg a vector with linear search, or a sorted vector with
binary search, or a binary tree, or a multi-way tree. Most of the time I
don't care which is used; I just want a map. The STL's complexity
requirements more or less mandate a red-black tree, which is a highly
specific implementation, not suited to such a general purpose name as
map<>. (If it were called red_black_tree_map<> I wouldn't mind so much.)
Similarly the STL list<> requires that size() be O(1) which means the
length must be stored rather than calculated as needed. This doubles the
memory overhead for a zero-length list and means splice cannot be O(1).
Again these are highly specific, and controversial, choices.
So the STL containers are already highly constrained and not very
"encapsulated". I don't think requiring vector to use contiguous storage
makes them worse. In fact, I find it such a pragmatically useful property
that I'll be glad to have the guarantee.
Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
brangdon@cix.co.uk | And close your eyes with holy dread,
| For he on honey dew hath fed
http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."
---
[ 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: "Dave Abrahams" <abrahams@mediaone.net>
Date: 1999/08/01 Raw View
In article <memo.19990727033220.38663C@btinternet.com> ,
scorp@btinternet.com (Dave Harris) wrote:
> Similarly the STL list<> requires that size() be O(1) which means the
> length must be stored rather than calculated as needed. This doubles the
> memory overhead for a zero-length list and means splice cannot be O(1).
> Again these are highly specific, and controversial, choices.
Actually, the exact opposite is the case.
-Dave
---
[ 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: Alain Miniussi <alain@sophia.cnrs.fr>
Date: 1999/08/02 Raw View
Dave Harris wrote:
>
> alain@sophia.cnrs.fr (Alain Miniussi) wrote:
> > I am not sure that the purpose of a standard is to decide the best
> > implementation for a general purpose template.
[...]
> So the STL containers are already highly constrained and not very
> "encapsulated". I don't think requiring vector to use contiguous storage
> makes them worse.
Thanks, these are the best arguments I have read so far !
But why this wasn't frankly admited in the standard, instead
of the pseudo highh level stuff used in the vector introduction ?
and why vector does not provide a real accessor for the buffer ?
Alain
---
[ 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 ]