The synthesized assignment operator is declared as one of them (if it can be synthesized and not declared as deleted) according to clause 12.8 [class.copy]:
Y& Y::operator=(Y const&)Y& Y::operator=(Y&) ()
That is, as with any other member function that is not specifically declared with ref-qualifiers , it applies to rvalues.
If you want to prevent a temporary object on the left side of the task, you need to declare it accordingly:
class Y { public : explicit Y(std::size_t num = 0); Y& operator= (Y const&) & = default; };
The standard uses the name ref-qualifier for & to = default . Relevant Offer N2439 . I do not know where there is a good description of ref-qualifiers. There is information on this issue .
Dietmar Kühl
source share