'final' function implementations in interface definition

Steven Schveighoffer schveiguy at yahoo.com
Mon Jun 8 06:57:51 PDT 2009


HOSOKAWA Kenchi Wrote:

> Steve Schveighoffer Wrote:
> 
> > On Sun, 07 Jun 2009 19:52:05 -0400, HOSOKAWA Kenchi wrote:
> > 
> > > Steve Schveighoffer Wrote:
> > > 
> > > 
> > >> f_twice can be a template:
> > >> 
> > >> void f_twice()(int i) { f(i); f(i); }
> > >> 
> > >> It's pretty much exactly what you want.  It should even work without
> > >> explicit instantiation.
> > >> 
> > >> -Steve
> > > 
> > > I have tried to replace final function in the interface with your code.
> > > finally I got following message. Error: function I.f_twice!().f_twice
> > > template member function not allowed in interface I
> > 
> > I could have sworn I'd seen this or written something like this in 
> > tango's log package...
> > 
> > It probably would be a good solution to this problem...
> > 
> > -Steve
> 
> 
> perhaps it is depends on the language version.
> At least both DMD 2.030 and 1.045 reject your suggestion.

I think possibly I compiled without instantiating the template, and that's why it worked...

> 
> If the function is macro- or inline-type, there is no need to instantiate it into the interface definition.
> Your suggestion might be legal for the language design, I think.

Templates do not go into the vtable, and are essentially final.  So it would be a legal solution.  It would also be nice to be able to have the ability to do templates in an interface.

Your suggestion for final functions may also be a possible solution, but I see one caveat: If the function overrides a base-interface's non-final function, then the function has to go into the base-interface's vtable, which is probably not correct.

-Steve
-Steve



More information about the Digitalmars-d mailing list