I see this a lot:
std::vector<Something> vec;
do_something_with_vec(vec);
Something *arr=&vec[0];
do_something_that_needs_carray(arr);
I mean, a vector will probably use an array internally so I see why this works, I'm just wondering whether or not this is defined behavior (like, is an implementor allowed to run an implementation of std::vector with which this would break).
If there are conflicts between the standards, I'm interested in what the C++11 standard says.
Is is what is known as a state of being verb. State of being verbs do not express any specific activity or action but instead describe existence. The most common state of being verb is to be, along with its conjugations (is, am, are, was, were, being, been).
present tense third-person singular of be.
From Middle English is, from Old English is, from Proto-West Germanic *ist, from Proto-Germanic *isti (a form of Proto-Germanic *wesaną (“to be”)), from Proto-Indo-European *h₁ésti (“is”).
And is a coordinating conjunction. We use and to connect two words, phrases, clauses or prefixes together: Televisions and computers are dominating our daily life. ( noun + noun) I have to shower and change. (
Yes it is allowed, if the std::vector
is not empty. If the vector
is empty, vec[0]
will evoke Undefined Behavior.
std::vector
is required to store elements contiguously.
There is also data(
) method, but it is C++11 only.
Important:
This will not work on std::vector<bool>
(bit-efficient specialization). But it is also not a container, and IMO it should be deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With