'final' function implementations in interface definition

Steve Schveighoffer schveiguy at yahoo.com
Sun Jun 7 16:42:02 PDT 2009


On Sun, 07 Jun 2009 17:58:30 -0400, HOSOKAWA Kenchi wrote:

> Hello,
> 
> 
> Interface member functions do not have implementations. This
> specification prevents to implement macro-like small functions which
> won't be overridden. It seems that interfaces are possible to have
> function implementations if the function is ensured not to be
> overridden. Hence following list will possibly avoid problems in
> multiple inheritance.
> 
> 
> interface I
> {
> 	void f(int);
> 	final void f_twice(int i) { f(i); f(i); }
> }
> 

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



More information about the Digitalmars-d mailing list