Emil Jerabek wrote:
On Wed, Apr 02, 2003 at 08:53:37PM +0200, Frank Heckenbach wrote:
Frank D. Engel, Jr. wrote:
Actually, overloading of unary operators might be a good idea (leaving apart the rest of the joke :)
Sure, then we can do negation with '+' and square root with '-'!
(another joke, but seriously, if we allow overloading of binary operators, then why not unary ones... but I hardly think overloading the ';' operator is reasonable. There IS a limit.)
I think currently we have 4 unary operators: `+', `-', `not', `@'.
Overloading `@' (BP style address operator) would seem strange to me -- basically because the built-in meaning already accepts all types (as "reference parameters").
Wouldn't it also clash with the ISO meaning of `@' ?
I don't think so. In ISO `@' (equivalent to `^') can be used in a type-definition (no conflict here) and as a postfix operator (pointer dereference). If there was a conflict with a user-defined operator, it would also be against the BP (prefix) operator. But still I wouldn't like to let it be overloaded.
Overloading `+' and `-' could be useful (e.g., when implementing your own vector arithmetic etc.), and perhaps `not' as well.
That's what I had in mind.
However, overloading `-' for Integers would mean that `-42' gets a different meaning.
Maybe I'll implement it sometime (or perhaps someone else would like to do it?) ...
Frank