|
Boost : |
From: Kresimir Fresl (fresl_at_[hidden])
Date: 2002-09-27 07:11:11
Michael Stevens wrote:
> Hmm.. Interesting. I've given this a bit of thought before and concluded
> that the .begin() is better. When used where a pointer is required, it
> will ONLY compile if the iterator is a pointer. This is a good thing; it
> almost certainly is not a good idea to use the linear memory after the
> first entry unless this is true.
> As you say all this only works if storage type has continuous storage.
> To keep things simple I would simply define these two properties
> (iterator==pointer, linear storage) as being equivilent!
I don't agree. ``iterator==pointer'' does not follow from ``storage is
linear''.
Issue 69 of ``C++ Standard Library Issues List'' is
``Must the elements of a vector be in contiguous memory?''
(http://anubis.dkuug.dk/JTC1/SC22/WG21/docs/lwg-defects.html#69).
Proposed resolution, which has status TC (``The full WG21 committee
has voted to accept the Defect Report's Proposed Resolution as a
Technical Corrigenda''), is:
``Add the following text to the end of 23.2.4, paragraph 1:
The elements of a vector are stored contiguously, meaning that if v
is a vector<T, Allocator> where T is some type other than bool, then
it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size().
Rationale: The LWG feels that as a practical matter the answer is
clearly "yes". ''
But there is also a note:
``(Please note that this is entirely separate from the question of
whether a vector iterator is required to be a pointer; the answer to
that question is clearly "no," as it would rule out debugging
implementations)''
fres
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk