C++ 中移动语义的起源是什么?

发布于 2025-01-05 07:48:56 字数 167 浏览 1 评论 0原文

我想知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢华的一滴泪 2025-01-12 07:48:56

这个概念似乎没有任何特定的祖先。 C++ 移动语义的起源,如 最初的提案,是新闻组中的讨论:

各种形式的移动语义已在 C++ 论坛中进行了讨论(大多数
尤其是 comp.lang.c++.moderated)多年来。

在我看来,它们与 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:

Move semantics in various forms has been discussed in C++ forums (most
notably comp.lang.c++.moderated) for years.

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.

通知家属抬走 2025-01-12 07:48:56

您可以阅读“添加移动语义支持的提案”到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文