Say I have a function:
void someFunc(int *x,int count);
which is out of my control, so I can’t write it to accept iterators.
Is it safe to call it like so (regardless of the specific STL implementation):
vector<int> v;
/* ... */
someFunc(&v[0],v.size());
Obviously, one counter example is vector<bool>. How about any other type? (assuming I haven’t specialized vector in any way).
From section 23.2.4, point 1 of the standard:
So yes, it is safe.
Note: If
vis emptyv[0]is undefined behavior so you should only do this ifvis not empty.