As with pretty much every other thing involving the perl parser, the answer is a resounding yes
It seems that there are often limitations regarding the liberties that can be taken regarding overloading.
I have overloading subs (XSubs) that will overload '++' as:
void overload_inc($V * object, SV * second, SV * switch) {
/* code that adds 1 to the value held by object */
}
That always works perfectly well.
I've then considered that I should be able to do the same thing with the overloading of the '+=' operator:
void overload_plus_eq(SV * object, SV * addon, SV * switch) {
/*code that adds the value of addon to the value held by object */
}
That attempt (in overload_plus_eq), to modify the object in place always fails when called by the '+=' operator - and I have never been able to write that XSub such that it is successfully called via overloading of '+=', unless it returns a new object that overwrites the existing one.
(Which, BTW, I think is what happens with the overloading of '+=' when only '+' is overloaded.)
I've assumed the incapacity of '+=' overloading to "modify in place" is related to '+=' NOT being seen as a "mutator" by overload.pm.
But maybe it's just that I haven't found the right way of doing it.
I've often wished that overloading of "log2" and "log10" was available ... but not to the extent that I'm going to commandeer a couple of these 'bitwise' operators for that purpose ;-)
(I doubt that could readily be achievable, anyway.)
I've noticed that overload.pm recognizes these additional bitwise operators as being valid, even though"
feature 'bitwise'" has not been loaded:
D:\>perl -Mwarnings -Moverload -e "use overload 'fu' => sub {return 1}
+;"
overload arg 'fu' is invalid at -e line 1.
D:\>perl -Mwarnings -Moverload -e "use overload '&.' => sub {return 1}
+;"
D:\>perl -Mwarnings -Moverload -e "use overload '&.=' => sub {return 1
+};"
D:\>
Seems a bit odd .... but perhaps of little or no importance.
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.