Before C++11 I have used swap-to-back to avoid deep copy overheads, like:
vector<vector<Object> > Objects;
for(/* some range */)
{
vector<Object> v;
for(/* some other range */)
{
v.push_back(/* some object */);
}
Objects.push_back(vector<Object>());
Objects.back().swap(v);
}
How can I use std::move to move v into Objects to avoid deep copy overhead instead of swap?
I know there are a lot of workarounds here like multi arrays or just inserting directly into Objects.back(), but I need an example of usage of std::move to understand it.
Objects.push_back( std::move( v ) );
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