digitalmars.D - opDispatch or equivalent at static context
- Chris Nicholson-Sauls <ibisbasenji gmail.com> Jan 20 2010
- "Lars T. Kyllingstad" <public kyllingen.NOSPAMnet> Jan 21 2010
- Chris Nicholson-Sauls <ibisbasenji gmail.com> Jan 21 2010
- Lutger <lutger.blijdestijn gmail.com> Jan 21 2010
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> Jan 21 2010
(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:(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
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
Jan 21 2010
On 01/21/2010 09:28 AM, Chris Nicholson-Sauls wrote:Lars T. Kyllingstad wrote: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
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
static opDispatch works fine.
Jan 21 2010
Chris Nicholson-Sauls wrote:Isn't that what opDispatch does now? -Lars
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
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" } Ali
Jan 21 2010









Lutger <lutger.blijdestijn gmail.com> 