in reply to Re^4: How does Math::GMP overload the assignment operator ?
in thread How does Math::GMP overload the assignment operator ?
The real solution to this is to make your objects immutable. Don't provide any methods that change the value of your object, and instead return new objects. You could then remove your += and similar overloads and = overload, and just rely on creating new objects from your + overload.
It would actually be possible to still provide the += overload as an optimization if you were providing the = overload. Since the only way to trigger mutation of the object would be via the overload, perl would protect you from ever modifying a shared object by cloning using the = overload. I'm not sure that the extra complexity here would really be worth it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: How does Math::GMP overload the assignment operator ?
by syphilis (Archbishop) on Nov 09, 2020 at 13:52 UTC | |
by Haarg (Priest) on Nov 09, 2020 at 17:42 UTC | |
by syphilis (Archbishop) on Nov 10, 2020 at 00:36 UTC | |
Re^6: How does Math::GMP overload the assignment operator ?
by karlgoethebier (Abbot) on Nov 10, 2020 at 16:55 UTC | |
by syphilis (Archbishop) on Nov 11, 2020 at 00:31 UTC | |
by karlgoethebier (Abbot) on Nov 13, 2020 at 15:15 UTC | |
by Haarg (Priest) on Nov 10, 2020 at 20:22 UTC | |
by karlgoethebier (Abbot) on Nov 13, 2020 at 15:17 UTC |