The direct way to initialize a vector from an array seems to be:
int sizeArr; int * array = getArray(sizeArr);
std::vector<int> vec(array, array+sizeArr);
Here, I am getting the array from a function which allocates the space in memory and sets sizeArr
by reference. {start edit} Unfortunately, the function is not written by me and I need to deal with C style array then convert it to a vector somehow. (If possible efficiently). {end edit}
When I initialize vec
, obviously I am allocating space for it separately. If I have no intention of using the data using array
anymore, is it possible to somehow "move" the data pointed by array
to the vector vec
and not allocate any space for it separately?