I have two std::vector with several std::unordered_set inside. However, one of the vector will be replacing the other throughout the execution, like this:
vector1 = ...
vector2 = ...
// some operations
vector1 = vector2
vector2 = std::vector<...>
Is there a way of achieving this without having to copy the contents of the vectors?
Since C++11 you can move assign them:
vector1 = std::move(vector2); // move vector2 to vector1
vector2 = std::vector<...>; // move the temporary vector to vector2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With