Topic: std::vector implementation
Author: =?iso-8859-1?Q?Andr=E9_P=F6nitz?= <poenitz@htwm.de>
Date: Thu, 22 Mar 2001 16:08:48 CST Raw View
Maybe I am making a fool of myself, but here it goes:
Suppose there was an implemention of (std::)vector that stores its elements
in the following order:
"physical address": 0 1 2 3 4 5 ...
"logical position": 0 2 1 3 4 5 ...
content: a c b d e f ...
^^^^^^^
(The contents of this vector might have been created by
v.push_back(a);
v.push_back(b);
v.push_back(c);
v.push_back(d);
v.push_back(e); etc)
Iterators (which obviously can't be simple pointers) shall work as usual,
i.e. incrementing begin() moves from logical position 0 to 1 to 2 ...
etc.
Now &v[0] would even give the address of an contiguous range of memory,
but we have e.g.
&v[2] != &v[0] + 2
which is not really nice if one wants to use C-style libraries without
doing much copying.
Simple questions:
Is an implementation as outlined above forbidden by the Standard?
If so, where does it say so? If not, shouldn't it be forbidden?
Andre'
--
Andr P nitz ........................................ poenitz@htwm.de
---
[ 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://www.research.att.com/~austern/csc/faq.html ]
Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Fri, 23 Mar 2001 01:41:57 GMT Raw View
Andr=E9 P=F6nitz wrote:
[Re: non-contiguous std::vector<>]
> Is an implementation as outlined above forbidden by the Standard?
See <http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-defects.html#69>
---
[ 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://www.research.att.com/~austern/csc/faq.html ]