Besides the fact that the standard defines it to be contiguous, why is std::vector contiguous?
If it runs out of space, it needs to reallocate a new block and copy t
If std::vector
didn't guarantee contiguousness, a new container would be invented which did.
The contiguity guarantee makes it easier to inter-operate with existing code that expects a contiguous array, and also gives very good performance because it is cache-friendly. (Inserting/deleting in the middle is in practice very fast for moderate sizes because of this.)
Copying the array on expansion is surprisingly cheap - if you append to a vector a million elements one at a time, each element will have been copied on average around once.