3 ms·
I don't think this is an operator overloading thing? It's just that `x = y + x` is equivalent to z = y + x x = z Basically, creating an object `z` jus
by staticassertion 4y ago
I don't think this is an operator overloading thing? It's just that `x = y + x` is equivalent to
z = y + x
x = z
Basically, creating an object `z` just to throw it away.
`x += y` just adds y to x directly without any intermediary.
You could write this in any language pretty easily. For example, in Rust:
let x = "abc".to_string();
let y = "123".to_string();
let x = x + &y;
as opposed to the more efficient:
let mut x = "abc".to_string();
let y = "123".to_string();
x.push_str(&y);
It's just using an operation to mutate in place vs an immutable operation.
- masklinn 4y ago> I don't think this is an operator overloading thing? It’s the confusion / idea that this is trivial change which is the overload thing.