You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Evaluation of compound assignment expressions depends on the types of the operators.
904
904
905
905
r[expr.compound-assign.primitive-order]
906
-
If both types are primitives, then the modifying operand will be evaluated first followed by the assigned operand.
906
+
If both types are primitives and the expression is non-generic (i.e., directly uses concrete types), then the modifying operand will be evaluated first followed by the assigned operand.
907
907
It will then set the value of the assigned operand's place to the value of performing the operation of the operator with the values of the assigned operand and modifying operand.
908
908
909
909
> [!NOTE]
910
910
> This is different than other expressions in that the right operand is evaluated before the left one.
911
911
912
+
> [!NOTE]
913
+
> This right-before-left evaluation only occurs in non-generic code involving primitive types.
914
+
> In all other cases---including generic contexts or non-primitive types---the expression is desugared into a trait method call, and operands are evaluated left to right.
915
+
912
916
r[expr.compound-assign.trait]
913
917
Otherwise, this expression is syntactic sugar for calling the function of the overloading compound assignment trait of the operator (see the table earlier in this chapter).
914
918
A mutable borrow of the assigned operand is automatically taken.
0 commit comments