Operator overloading in Objective C
Operator overloading in Objective C
- Subject: Operator overloading in Objective C
- From: Michael Gersten <email@hidden>
- Date: Sat, 25 May 2002 22:08:04 -0700
A while ago, there was a discussion on adding operator overloading using an @ syntax -- such as root = (b @* b - 4 @* a @* c) @/ (2 @* a), in either the compiler or a preprocessor.
During that discussion, I posted a detailed look at what would be needed. I concluded that it needed two re-dispatchers in NSObject, namely
- operatorOverload: (NSString *) operator argument: (id) argument
- operatorOverload: (NSString *) operator argument: (id) argument protocol: (NSString *) protocol
Then, in the classes involved (often into a category on NSNumber), you would need
- operatorMultiply_classNSComplex: (NSComplex *) arg
or
- operatorMultiply_classXXMatrix: (XXMatrix *) arg
or even in NSObject
- operatorAddition_protocolCollection: (id <Collection> *) arg
The protocol version of the dispatcher is needed if the object is declared by a protocol, instead of by a class; if no corresponding protocol method is found, then it passes onto the class version.
The NSObject dispatchers would need to hunt through the argument's inheritence hierarchy until respondsTo: says yes, as someone might have a subclass invovled, such as
in NSString
- operatorAddition_classNSString: (NSString *) arg
(class clusters guarantee that you'll always be working with a subclass.)
or in NSMutableString
- operatorAssignAddition_classNSString: (NSString *) arg
(unlike C++, where references are needed to ensure you are sending pointers-to-objects to assignment operators, in Objective C, every object is a pointer.)
Since then, however, I haven't seen anything else. Is anyone actually interested in doing a preprocessor, or a compiler alteration, to support this?
--
I am a Mac 10-Cocoa/WOF/EOF developer, and I'm available for hire. Please contact me at michael-job @ stb.nccom.com if interested. Resume at
http://resumes.dice.com/keybounce
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.