c++ - C++ 标准中的 move 概念

标签 c++ c++11 move

我很好奇 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/

相关文章:

c++ - 如何在 C++ 中使函数内联

c++ - 如何将函数<void()> 写入管道/套接字对?

c++ - 通过 move 赋值实现 B=f(A) 语法

c++ - 使用 move 成本低但复制成本高的对象初始化容器的首选方法是什么

c# - 如何将文件从一个 SP 2010 根站点复制到其子站点 (C#)

c++ - cuda 数学函数 norm3df 是否溢出?

c++ - 调整大小以适应 QTableView 中的行和列非常慢

c++ - 在模板中有没有办法为每个计时实例只编写一个特化? (纳秒、毫秒、秒等)

c++ - void* 和 char* 的区别

c++ - 如何将 future 转移到 lambda 表达式中