Discussion of operator overloading with permzbi.
Version of Sunday 15 September 2024.
cpp.reference.com lists 39 non-alphabetic operators in C++ that can be overloaded. Below is a table of them, and how they are, or not, used with the permzbi class.
binary operators | overloading in permzbi | general examples | ||
---|---|---|---|---|
+= -= / /= % %= | none | a+=b a-=b a/b a/=b a%b a%=b | ||
*= | outer product | a*=b | ||
== != < <= >= > | comparison | a==b a!=b a<b a<=b a>b a>=b | ||
<=> | none | a<=>b | ||
&= ^ ^= | none | a&=b a^b a^=b | ||
| |= | function application | a|b a|=b | ||
<< | direct sum, stream insertion |
a<<b | ||
<<= | direct sum | a<<=b | ||
>> | skew sum, stream extraction |
a>>b | ||
>>= | skew sum | a>>=b | ||
&& || | none | a&&b a||b | ||
= | default assignment | a=b | ||
, -> ->* | none | a,b a->b a->*b | ||
unary operators | overloading in permzbi | general examples | ||
++ -- ! ~ | none | ++a a++ --a a-- !a ~a | ||
operators both binary and unary |
overloading in permzbi | general examples | ||
binary | unary | binary | unary | |
+ - | none | a+b a-b | +a -a | |
* | outer product | none | a*b | *a |
& | none | a&b | &a | |
n-ary operators | overloading in permzbi | general examples | ||
() | function application | a(b,c) | ||
[] | none | a[b,c] | ||
operator[] is strictly binary before C++23. |
Also provided is a literal operator named operator""_pz which creates a permzbi from a string literal.
Not overloaded in permzbi are operators whose names are alphabetical, such as new delete[] co_await.
Never overloadable in C++ are the following four operators: a::b a.b a.*b a?b:c.
The author's opinion is that the names direct sum and skew sum are unintuitive and indescriptive. To make things clearer, permzbi takes advantage of the symmetry of the symbols operator>> and operator<<.
Some programmers may believe that the use of a symbol such as operator<< for these functions, which are a variety of catenation, is too far removed from their established uses for input-output and bit shifting. However, their use for input-output is itself entirely unrelated to their original purpose of bit shifting, so such a jump in meaning is precented.
Along the same lines, operator|, originally used for bitwise inclusive OR, is now also used in C++ for the unrelated purpose of pipelining filters. Here in permzbi the symbol has been further extended to the application of functions, because P|Q|R|S is felt to be easier to read than the equivalent P(Q(R(S))).
There is considerable contrast between the two notations' appearance and interpretation, but they are in fact equivalent because this manner of function application, specific to permutations, is associative. Both notations are furnished in permzbi, because neither is clearly superior to the other.
The warning found elsewhere must be repeated here: Although this report uses P(Q) to mean P as resequenced according to Q, some authors do the opposite, meaning that Q is to be resequenced according to P. This operation is certainly not commutative.
Some of the classes other than permzbi use a few of these operators in an unsurprising manner, and are not reflected in the table above. Those other classes might also have operator permzbi for conversion purposes.