By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,948 Members | 1,215 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,948 IT Pros & Developers. It's quick & easy.

Question about the requirements of std::vector

P: n/a
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! ]

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <11**********************@g44g2000cwa.googlegroups .com>,
<cd******@videotron.ca> wrote:
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! ]

Nov 22 '05 #2

P: n/a

cd******@videotron.ca wrote:
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! ]

Nov 22 '05 #3

P: n/a
cd******@videotron.ca wrote:
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! ]

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.