C++0x 中的特殊成员函数
关于特殊成员函数的维基百科文章不包含任何对移动构造函数和移动赋值运算符的引用。
我想更新该条目,但我不确定 0x 标准的内容。
这两个函数的规则是什么?它们是由编译器自动生成的吗?如果是的话,什么时候生成?
编辑:我已经更新了维基百科页面,如果有人愿意,请通过编辑它来帮助社区(如果需要)。
The Wikipedia article about special member functions doesn't contain any reference to move constructors and move assignment operators.
I would like to update the entry but I'm not sure what the 0x standard says.
What are the rules regarding these two functions? Are they automatically generated by the compiler and if so when?
Edit: I've updated the Wikipedia page, if anyone feels like it please help the community by editing it into shape (if needed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住,C++0x 还不是很标准,这可能会发生变化。来自 FCD(PDF 链接),移动构造函数和移动赋值运算符确实可以显式默认,甚至隐式默认。*****
我只是要引用(大量删节)一堆可能有用的内容:
在显式-默认功能,§8.4.2/1-2:
关于特殊成员函数,§12/1:
关于隐式声明的函数,§12.8/8-11:
关于隐式删除的默认函数,第 12.8/12 节:
§12.8/13-18 定义了函数在隐式生成时应如何工作。
然后,§12.8/19 执行与 §12.8/8 相同的操作,但复制赋值和移动赋值运算符除外。它们非常相似,无需在此引用。
为了获得更完整的了解,您需要完整阅读这些部分,但这就是总体思路。我很高兴我们获得了隐式移动语义。
*但是就像默认的复制功能一样,它们可能并不总是具有正确的行为!三巨头应该成为五巨头。 (例如,每当我们需要深度复制某些内容时,就会实现“三巨头”。我们还需要确保执行“深度移动”,其中源数据被清空/重置。这是不 隐式完成。)
Keeping in mind C++0x isn't quite standard yet, this is subject to change. From the FCD (PDF link), move constructors and move assignment operators can indeed be explicitly defaulted, and even implicitly defaulted.*****
I'm just going to quote (heavily abridged) a bunch of stuff that might be useful to glance at:
On explicitly-defaulted functions, §8.4.2/1-2:
On special member functions, §12/1:
About implicitly declared functions, §12.8/8-11:
On implicitly deleted default functions, §12.8/12:
§12.8/13-18 defines how the functions should work when they are implicitly generated.
§12.8/19 then does the same thing as §12.8/8 did, except with the copy-assignment and move-assignment operators. They are similar enough not to warrant quoting here.
For a more complete picture, you'll want to read those sections in their entirety, but that's the general idea. I'm glad we get implicit move semantics.
*But like defaulted copy-functions, they might not always have the correct behavior! The Big Three should become The Big Five. (For example, The Big Three are implemented whenever we need to deep-copy something. We also need to make sure we do a "deep-move", where the source's data is nulled/reset. This is not done implicitly.)