digitalmars.D - opDispatch or equivalent at static context
- Chris Nicholson-Sauls (28/28) Jan 20 2010 (Apologies ahead of time if I've overlooked something.)
- Lars T. Kyllingstad (3/13) Jan 21 2010 Isn't that what opDispatch does now?
- Chris Nicholson-Sauls (4/20) Jan 21 2010 Not as a static member, to my knowledge. At the very least, I see no me...
- Lutger (2/23) Jan 21 2010 static opDispatch works fine.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (10/17) Jan 21 2010 The fact that the name of the non-existent function arrives as a
(Apologies ahead of time if I've overlooked something.) How possible could it be to have opDispatch or an equivalent feature (opStaticDispatch?) available for static forwarding? Use-case: I'm envisioning an ORM library, where one could do things like: Player.findFirstByName( "Bob" ) With a static forwarding template parsing the "findFirstByName" to rewrite the call: Player.find( FindFlags.First, `name == "Bob"` ) I can't help but think there could be other useful scenarios. The current (untested) work-around would be a proxy object for the API: auto finder = new Finder!Player; finder.findFirstByName( "Bob" ); // or... auto finder = new Finder; finder.findFirstPlayerByName( "Bob" ); The obvious problem with an opStaticDispatch, of course, would be preserving propagation of static lookups along the inheritance chain. I'm guessing this could be surmountable when using conditions though. class Foo : Base { static Foo opStaticDispatch ( string s, T t ) ( t param ) if ( s.length > 3 && s[ 0 .. 4 ] == "find" ) { // do stuff // if the condition failed, check for Base.opStaticDispatch's } } If there were a means for static member functions to be aware that they are being called through a sub-class, that might also be an avenue to the abilities I'm wanting. I can't think of any sane means for that, however. -- Chris Nicholson-Sauls
Jan 20 2010
Chris Nicholson-Sauls wrote:(Apologies ahead of time if I've overlooked something.) How possible could it be to have opDispatch or an equivalent feature (opStaticDispatch?) available for static forwarding? Use-case: I'm envisioning an ORM library, where one could do things like: Player.findFirstByName( "Bob" ) With a static forwarding template parsing the "findFirstByName" to rewrite the call: Player.find( FindFlags.First, `name == "Bob"` )Isn't that what opDispatch does now? -Lars
Jan 21 2010
Lars T. Kyllingstad wrote:Chris Nicholson-Sauls wrote:Not as a static member, to my knowledge. At the very least, I see no mention of static forwarding in the docs: http://www.digitalmars.com/d/2.0/operatoroverloading.html#Dispatch -- Chris Nicholson-Sauls(Apologies ahead of time if I've overlooked something.) How possible could it be to have opDispatch or an equivalent feature (opStaticDispatch?) available for static forwarding? Use-case: I'm envisioning an ORM library, where one could do things like: Player.findFirstByName( "Bob" ) With a static forwarding template parsing the "findFirstByName" to rewrite the call: Player.find( FindFlags.First, `name == "Bob"` )Isn't that what opDispatch does now? -Lars
Jan 21 2010
On 01/21/2010 09:28 AM, Chris Nicholson-Sauls wrote:Lars T. Kyllingstad wrote:static opDispatch works fine.Chris Nicholson-Sauls wrote:Not as a static member, to my knowledge. At the very least, I see no mention of static forwarding in the docs: http://www.digitalmars.com/d/2.0/operatoroverloading.html#Dispatch -- Chris Nicholson-Sauls(Apologies ahead of time if I've overlooked something.) How possible could it be to have opDispatch or an equivalent feature (opStaticDispatch?) available for static forwarding? Use-case: I'm envisioning an ORM library, where one could do things like: Player.findFirstByName( "Bob" ) With a static forwarding template parsing the "findFirstByName" to rewrite the call: Player.find( FindFlags.First, `name == "Bob"` )Isn't that what opDispatch does now? -Lars
Jan 21 2010
Chris Nicholson-Sauls wrote:The fact that the name of the non-existent function arrives as a template parameter indicates that it is static dispatch. Which made me realize that it can be overloaded: void opDispatch(string name : "special_member_function_name", T)(T parameter) { // special implementation for "special_member_function_name" } AliIsn't that what opDispatch does now? -LarsNot as a static member, to my knowledge. At the very least, I see no mention of static forwarding in the docs: http://www.digitalmars.com/d/2.0/operatoroverloading.html#Dispatch
Jan 21 2010