Title
Must elements of a vector be contiguous?
Status
tc1
Section
[vector]
Submitter
Andrew Koenig

Created on 1998-07-29.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

The LWG feels that as a practical matter the answer is clearly "yes". There was considerable discussion as to the best way to express the concept of "contiguous", which is not directly defined in the standard. Discussion included:

  • An operational definition similar to the above proposed resolution is already used for valarray ([valarray.access]).
  • There is no need to explicitly consider a user-defined operator& because elements must be copyconstructible ([container.requirements] para 3) and copyconstructible ([utility.arg.requirements]) specifies requirements for operator&.
  • There is no issue of one-past-the-end because of language rules.
Date: 2010-10-21.18:28:33

Proposed resolution:

Add the following text to the end of [vector], 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().

Date: 1998-07-29.00:00:00

The issue is this: Must the elements of a vector be in contiguous memory?

(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)

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg160
2010-10-21 18:28:33adminsetmessages: + msg159
1998-07-29 00:00:00admincreate