谁创造了统一(或统一)赋值运算符这个术语?

发布于 2024-12-28 13:11:03 字数 484 浏览 3 评论 0原文

C++ wiki 书 引用

...在 C++0x 中,这样的赋值运算符被称为统一 赋值运算符,因为它不需要编写两个 不同的赋值运算符...

对于按值获取其类类型的赋值运算符:

String & operator = (String s) // the pass-by-value parameter serves as a temporary
{
   s.swap (*this); // Non-throwing swap
   return *this;
}

我尝试在谷歌上搜索该术语,但它似乎并未得到广泛使用。

它从哪里来?

A C++ wiki book refers to

... In C++0x, such an assignment operator is known as a unifying
assignment operator
because it eliminates the need to write two
different assignment operators ...

for an assignment operator that takes it's class type by value:

String & operator = (String s) // the pass-by-value parameter serves as a temporary
{
   s.swap (*this); // Non-throwing swap
   return *this;
}

I tried googling the term, but it doesn't appear to be in widespread use.

Where does it come from?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

左耳近心 2025-01-04 13:11:03

它似乎参考了正式类型系统中发生的统一。我们的想法是,如果仅通过某些合法的替换就可以将 r 值和 l 值变为相同类型(统一),则该赋值就是格式良好的。

维基百科声称这个想法首先由 John Alan Robinson 给予了有意义的关注(可能还有它的名字) 。

It appears to be in reference to the unification that takes place in formal type systems. The thought is if the r- and l-values can be brought to the same type (unified) by only certain, legal substitutions, then the assignment is well-formed.

Wikipedia claims the idea was first given meaningful attention (and possibly its name) by John Alan Robinson.

俯瞰星空 2025-01-04 13:11:03

我不确定是谁说的,但维基百科上的书是错误的。 “统一”一词在 c++0x“标准”中恰好出现了次(现在您确实应该使用短语“C++11”,它于 2011 年 8 月获得批准)。

正确的术语是复制省略。来自 C++0x(n3242,我不用花钱就能得到的最后一个),12.8 复制和移动类对象,/34 节:

当满足某些条件时,允许实现省略类对象的复制/移动构造,即使对象的复制/移动构造函数和/或析构函数有副作用。

在这种情况下,实现将省略的复制/移动操作的源和目标视为引用同一对象的两种不同方式,并且该对象的销毁发生在这两个对象发生时的较晚时间。如果没有优化,就会被破坏。

这种复制/移动操作的省略称为复制省略,在以下情况下是允许的(可以组合起来消除多个副本)...

I'm not sure who phrased it but the wiki book is wrong. The word "unifying" appears exactly zero times in the c++0x "standard" (you should really be using the phrase "C++11" nowadays, it was approved in August 2011).

The correct term is copy elision. From C++0x (n3242, the last I can get without shelling out money), section 12.8 Copying and moving class objects, /34:

When certain criteria are met, an implementation is allowed to omit the copy/move construction of a class object, even if the copy/move constructor and/or destructor for the object have side effects.

In such cases, the implementation treats the source and target of the omitted copy/move operation as simply two different ways of referring to the same object, and the destruction of that object occurs at the later of the times when the two objects would have been destroyed without the optimization.

This elision of copy/move operations, called copy elision, is permitted in the following circumstances (which may be combined to eliminate multiple copies) ...

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