cpp/language/operator assignment

Assignment operators modify the value of the object.

Explanation
copy assignment operator replaces the contents of the object with a copy of the contents of  ( is not modified). For class types, this is a special member function, described in.

For non-class types, copy and move assignment are indistinguishable and are referred to as direct assignment.

compound assignment operators replace the contents of the object with the result of a binary operation between the previous value of  and the value of.

Builtin direct assignment
The direct assignment expressions have the form

For the built-in operator, may have any non-const scalar type and  must be implicitly convertible to the type of.

The direct assignment operator expects a modifiable lvalue as its left operand and an rvalue expression as its right operand, and returns an lvalue identifying the left operand after modification. The result is a bit-field if the left operand is a bit-field.

For non-class types, the right operand is first to the cv-unqualified type of the left operand, and then its value is copied into the object identified by left operand.

When the left operand has reference type, the assignment operator modifies the referred-to object.

If the left and the right operands identify overlapping objects, the behavior is undefined (unless the overlap is exact and the type is the same).

In, for every type , the following function signatures participate in overload resolution:

For every enumeration or pointer to member type, optionally volatile-qualified, the following function signature participates in overload resolution:

For every pair A1 and A2, where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic type, the following function signature participates in overload resolution:

Builtin compound assignment
The compound assignment expressions have the form

The behavior of every builtin compound-assignment expression (where E1 is a modifiable lvalue expression and E2 is an rvalue expression ) is exactly the same as the behavior of the expression, except that the expression  is evaluated only once and that it behaves as a single operation with respect to indeterminately-sequenced function calls (e.g. in , the += is either not started at all or is completed as seen from inside ).

In, for every pair A1 and A2, where A1 is an arithmetic type (optionally volatile-qualified) and A2 is a promoted arithmetic type, the following function signatures participate in overload resolution:

For every pair I1 and I2, where I1 is an integral type (optionally volatile-qualified) and I2 is a promoted integral type, the following function signatures participate in overload resolution:

For every optionally cv-qualified object type, the following function signatures participate in overload resolution: