我很好奇 C++ ISO 文档中对 move 对象的描述在哪里。我只看到了有关右值引用、 move 构造函数、 move 赋值运算符及其语法的信息。我找不到“move ”被描述为在对象之间 move 资源的官方原因。
最佳答案
来自http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1377.htm :
Move semantics is mostly about performance optimization: the ability to move an expensive object from one address in memory to another, while pilfering resources of the source in order to construct the target with minimum expense.
Move semantics already exists in the current language and library to a certain extent:
- copy constructor elision in some contexts
- auto_ptr "copy"
- list::splice
- swap on containers
All of these operations involve transferring resources from one object (location) to another (at least conceptually). What is lacking is uniform syntax and semantics to enable generic code to move arbitrary objects (just as generic code today can copy arbitrary objects). There are several places in the standard library that would greatly benefit from the ability to move objects instead of copy them (to be discussed in depth below).
关于c++ - C++ 标准中的 move 概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49682380/