No, there is no supported way to "expand" the vector, so it contains additional values that were directly copied. Relying on the “capacity” for allocating non-dimensional memory that you can write is definitely not what you need to rely on.
You must make sure that your vector has the required space by resizing it before calling the function, and then resizing it to the desired value. For example.
vector.resize(MAX_SIZE); size_t items = write_array(&(vec[0]), MAX_SIZE) vector.resize(items);
Andrew Grant
source share