|
Archives
D Programming
digitalmars.Ddigitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger D.gnu D C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
digitalmars.D - opDispatch or equivalent at static context
(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: Jan 21 2010
Lars T. Kyllingstad wrote:Chris Nicholson-Sauls wrote: 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"` ) Jan 21 2010
Chris Nicholson-Sauls wrote:Isn't that what opDispatch does now? -Lars Jan 21 2010
|