move是将对象的所有权从一个对象转移到另外一个对象,只有转移,没有内存拷贝。
通过一个例子可以看的很清楚
// 定义一个vector
vector<int> arry;
// 添加数据到vector中
for (auto i = 0; i < 10; ++i)
{
arry.push_back(i);
}
// 定义另一个vector
vector<int> v;
// move操作
v = move(arry);
// move操作完了之后,arry中没有任何数据,而v则拥有了arry原来的数据
for (auto x = v.begin(); x != v.end();++x)
{
cout << *x << endl; // 输出0,1,2,3,4,5,6,7,8,9
}
for (auto x = arry.begin(); x != arry.end(); ++x)
{
cout << *x << endl; // 不输出
}