Equivalence of “a @= b” and “a = a @ b”

前端 未结 4 1165
梦如初夏
梦如初夏 2021-02-12 22:15

It\'s often mooted (indeed I think even the standard alludes to it), that a @= b and a = a @ b are equivalent. Here I\'m using @ to stand

4条回答
  •  清歌不尽
    2021-02-12 22:38

    The built-in operators have that equivalence, except that a @= b only evaluates a once, while a = a @ b evaluates it twice.

    However, these are not the built-in operators, but overloads provided by the standard library. They are treated as separate, unrelated functions, so the compiler cannot change one into the other. (In fact, as noted in the comments, only the assignment operators are overloaded for atomic types - you would have to explicitly load and store the value to use the non-atomic form).

提交回复
热议问题