C++ 中移动语义的起源是什么?
我想知道 C++ 中 移动语义 的起源是什么?特别是它是专门为这种语言发明的还是其他语言中有类似的东西?对于后一种情况,您可以提供一些参考吗?
I am wondering what is the origin of move semantics in C++? In particular was it invented specifically for this language or there was something similar in other language(s)? In the latter case could you give some references.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个概念似乎没有任何特定的祖先。 C++ 移动语义的起源,如 最初的提案,是新闻组中的讨论:
在我看来,它们与 C++ 的左值和右值概念紧密结合,如果我没记错的话,这纯粹是一个 C++ 概念。没有左值、右值及其新的 C++11 朋友的语言不需要以 C++ 实现它们的方式移动语义。
不过,更一般地说,移动内容而不是复制的概念只是一个基本概念。每当您编写链接列表并通过实际上交换指向它们的指针来“交换元素”时,您都在进行“移动”。基本上。
There doesn't appear to be any kind of specific ancestor to the concept. The origin of C++'s move semantics, as noted in the original proposal, was discussion in newsgroups:
To my mind, they are tightly coupled with C++'s notion of lvalues and rvalues which, if I'm not mistaken, is purely a C++ concept. A language that doesn't have lvalues, rvalues and their new C++11 friends doesn't need move semantics in the way that C++ implements them.
More generally, though, the concept of moving stuff around rather than copying is just a fundamental concept. Whenever you write a linked list and you "swap elements" by actually just swapping pointers to them, you're doing a "move". Basically.
您可以阅读“添加移动语义支持的提案”到 C++ 语言”,以获取有关该概念背后动机的更多信息,以及为什么需要直接语言支持而不是使用库设施来实现。
You can read "A Proposal to Add Move Semantics Support to the C++ Language" to get more information on the motivation behind the concept, as well as why this needs to have direct language support rather than being implemented using library facilities.