I'm trying to understand how operator overloading works in Julia. The manual is quite brief, and gives +()
as an example function, then states all the operators are overloadable with their obvious names (a list of non-obvious names is also provided).
But what about +=?
The function +=()
doesn't even seem to exist, nor does +=!()
(since it is a modifying function). I frequently overload operators in C++ by defining +=
first and then use a simple +
based on copy and +=
.
In my case I don't even think I need +
, just the behavior of +=
... I realize I could write my own modifying function but the operator syntax would be nice. (Out of curiosity, how do *=
, /=
, $=
, etc work?)
There is no +=
function. It is simply syntactic sugar for a = a + b
.
It is also not mutating. So a += b
calculates a + b
and then changes a
to refer to the result. This means there is memory allocation for the result of a + b
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With