Math::GMP only has a + overload, not a += overload. The + overload constructs a new object. Perl uses that overload, and then overwrites the stored value. This means every += op creates a new object.
Math::GMPz (without the = overload) does have a += overload. This modifies the object. If there is more than one reference to the object, they all get modified. If you implement the = overload, perl notices that there are multiple references and uses the = overload to clone the object, before modifying it with the += overload. This means that += will only create a new object if there are multiple references to the object.
In reply to Re: How does Math::GMP overload the assignment operator ?
by Haarg
in thread How does Math::GMP overload the assignment operator ?
by syphilis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |