更新时间:2022-12-08 11:40:13
Type &&
),则使用移动构造函数而不是复制构造函数.std::move()
是一个强制转换,它产生一个对对象的右值引用,以允许从它移动.Type &&
).std::move()
is a cast that produces an rvalue-reference to an object, to enable moving from it.这是一种避免复制的新 C++ 方法.例如,使用移动构造函数,std::vector
可以将其指向数据的内部指针复制到新对象,使移动的对象处于移动状态,因此不会复制所有数据.这将是 C++ 有效的.
It's a new C++ way to avoid copies. For example, using a move constructor, a std::vector
could just copy its internal pointer to data to the new object, leaving the moved object in an moved from state, therefore not copying all the data. This would be C++-valid.
尝试使用谷歌搜索移动语义、右值、完美转发.
Try googling for move semantics, rvalue, perfect forwarding.