Question about the requirements of std::vector

C

cdiggins

I have been having a debate with my colleagues. They are claiming that:


"The standard specifies that &v[0] for a vector must give a
contiguous array that can be used by a function expecting
a C-style array."

I have searched the standard but I can not substantiate their claim
(and nor can they), and I believe it to be false. Can anyone point me
to where in the standard that is specified?

Thank you very much in advance,

Christopher Diggins
http://www.cdiggins.com - Home page
http://www.cpp-cookbook.com - C++ Cookbook


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
C

Carl Barron

I have been having a debate with my colleagues. They are claiming that:


"The standard specifies that &v[0] for a vector must give a
contiguous array that can be used by a function expecting
a C-style array."

I have searched the standard but I can not substantiate their claim
(and nor can they), and I believe it to be false. Can anyone point me
to where in the standard that is specified?

Thank you very much in advance,

Christopher Diggins
http://www.cdiggins.com - Home page
http://www.cpp-cookbook.com - C++ Cookbook
it is true that the data of vector is continguous, it has been made so
by correction in the current draft of the standard [N1804=05-0064].
It was not specified in the original C++98.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
I

int2str

I have been having a debate with my colleagues. They are claiming that:

"The standard specifies that &v[0] for a vector must give a
contiguous array that can be used by a function expecting
a C-style array."

I have searched the standard but I can not substantiate their claim
(and nor can they), and I believe it to be false. Can anyone point me
to where in the standard that is specified?

23.2.4 para 1 might help:

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


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
R

red floyd

I have been having a debate with my colleagues. They are claiming that:


"The standard specifies that &v[0] for a vector must give a
contiguous array that can be used by a function expecting
a C-style array."

I have searched the standard but I can not substantiate their claim
(and nor can they), and I believe it to be false. Can anyone point me
to where in the standard that is specified?

I believe it was corrected in TC1.

23.2.4/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()."

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top