class scope virtual template functions
janderson
askme at me.com
Fri May 30 08:04:46 PDT 2008
Chris Wright wrote:
> janderson wrote:
>> You could use a functor/proxy type thing. That is return a separate
>> object for each class level that has opCall overloaded. The opCall
>> could be templated. The functor object probably could be generalized
>> so that you could use it in any case you needed a virtual function (it
>> could callback its owner by template or maybe delegate).
>
> I don't understand this. You seem to be suggesting moving the template
> to a functor and having inheritors of the original class return a
> different functor. But unless that functor is virtual, you simply can't
> do that. You'd need to call a different method for each inheritor, or
> you'd need inheritance with the functors. The former is not virtual; the
> latter simply returns us to the original problem.
Something like:
class A
{
templateCallback()() {} //template
TemplateMaker Templet() { return new TemplateMaker(this,
templateCallbackFunc); }
}
class A : B
{
templateCallback2()() {} //template
TemplateMaker Templet() { return new TemplateMaker(this,
templateCallbackFunc2); }
}
Then the templateMaker would be:
class TemplateMaker(class, callback) //Functor/proxy
{
TemplateMaker(class, callback) { record of stuff ... }
void opCall(T...)(T arg) { recordedclass->recoredcallback(arg); }
}
Call it like:
this.Templet()!("foo")(arg)
//Might simplify to due to D's magic property stuff
this.Templet!("foo")(arg)
Something like that. Haven't tried it so don't know what massaging would
be needed and if it would work.
-Joel
More information about the Digitalmars-d
mailing list