class scope virtual template functions

Chris Wright dhasenan at gmail.com
Fri May 30 18:33:08 PDT 2008


janderson wrote:
> 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

If TemplateMaker is templated, then you can't return it, just an 
instantiation of it. This only allows you to access one template through it.

If TemplateMaker is not templated, then it requires virtual templates in 
order to work; it's expecting a BaseClass, and even if it got a 
DerivedClass, it only knows about the template on BaseClass, so that's 
what it uses.



More information about the Digitalmars-d mailing list