7

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?

Martin Ba
  • 37,187
  • 33
  • 183
  • 337
  • [This question](http://stackoverflow.com/questions/7458110/c-unified-assignment-operator-move-semantics) mentions a Channel 9 video on Perfect Forwarding, I'm not going to watch it to find out, but maybe you want to. If it's from Channel 9, possibly MS is the source of the term. – Leigh Jan 23 '12 at 07:47

2 Answers2

4

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.

Martin Ba
  • 37,187
  • 33
  • 183
  • 337
phs
  • 10,687
  • 4
  • 58
  • 84
1

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) ...

Community
  • 1
  • 1
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • You can now also get [N3337](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf), the first public draft *after* C++11 was published. (No changes to this section though). – Bo Persson Jan 23 '12 at 08:25
  • Well, the statement "X is known as Y" would be true if a reasonable number of people used *Y* to refer to X, even if it wasn't a standard-defined term, or indeed even if it was inaccurate. – Jon Hanna Jan 25 '12 at 09:51
  • Those are two different things. Copy elision is one of advantages of unifying assignment (also I think it applied before C++11 as well...). – Adam Badura Feb 17 '15 at 23:00