user12660947
user12660947

Reputation: 11

Move sematics to move data from one vector to another

If I have a vector std::vector<int64_t> oldData, can I use move semantics to move the data into another vector std::vector<uint8_t> newData.

Instead of doing:

std::vector<uint8_t> newData(oldData.begin(),oldData.end()); 

Could I do

std::vector<uint8_t> newData = std::move(oldData);

Will this actually move the data instead of copying it and be more performant?

Upvotes: 0

Views: 35

Answers (1)

NadavS
NadavS

Reputation: 777

No. If you think carefully about it, it's impossible - you to transform an array of 64 bit integers to an array of 8 bit integers, so you'll have to allocate new space for the new array (8 times smaller) and then copy the least significant 8 bits of every integer in the old array.

Upvotes: 1

Related Questions