std::vector 移动赋值与移动构造:为什么“其他”的状态是这样?不一致?
For move construction:
After the move, other is guaranteed to be empty(). 1
For move assignment, the oft-quoted:
other is in a valid but unspecified state afterwards. 2
Why is the state of other different in these two cases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种流行的方法可以在容器(如内部保存指向数据的指针的向量)中实现移动:
该标准希望为实现这两者留有余地。这些保证是它在允许任一实现方法时可以做出的最强有力的保证:
移动构造函数:
移动赋值:
There are 2 popular ways to implement move in containers like vector that internally hold a pointer to the data:
The standard wants to leave leeway to implementations to do either. These guarantees are the strongest guarantees it can make while allowing either methods of implementation:
move constructor:
move assignment: