c++11move-semanticsmove-assignment-operator

What does it means user-declared for Implicitly-declared move assignment operator?


The statement

Implicitly-declared move assignment operator

If no user-defined move assignment operators are provided for a class type (struct, class, or union), and all of the following is true:

there are no user-declared copy constructors;
there are no user-declared move constructors;
there are no user-declared copy assignment operators;
there are no user-declared destructors;

with user-declared copy assigment operator does it means only

class_name & class_name :: operator= ( class_name && )

or any operator=() defined?

Example:

class Bar
{
public:
   Bar() = default;
   SomeClass some;
};

class Foo
{
public:
   Foo() = default;

   Foo& operator=(Bar&& bar) : some(std::move(bar.some))
   {
   }

   SomeClass some;
};

Does that match the condition for an implitely-declared move assigmnent operator?

The same goes for the implicitly-declared move constructor.


Solution

  • Note that it says "user-declared copy assignment operators" (emphasis mine). Not every assignment operator is a copy assignment operator.

    For class X, a copy assignment operator is defined as operator= which takes a parameter of type X, X&, const X&, volatile X&, or const volatile X&. So your Foo::operator=(Bar&&) is not a copy assignment operator, and thus does not affect the implicit declaration of a move (or copy) assignment operator.