template mixin in class is virtual function?

strtr strtr at spam.com
Fri May 21 13:40:10 PDT 2010


== Quote from div0 (div0 at users.sourceforge.net)'s article
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> strtr wrote:
> > Or more to the point:
> >
> > Can (Class) template mixin functions be devirtualized by the compiler or do I (as
> > optimization) need to manually copy paste the boiler plate code?
> You can just wrap the mixin in a final block:
> import std.stdio;
> template bar(T) {
> 	void test(T t) {
> 		writefln("t: %s", t);
> 	}
> }
> class foo {
> 	final {
> 		mixin bar!(int);
> 	}
> }
> int main(){
> 	scope f = new foo;
> 	f.test(3);
> 	return 0;
> }

Is that different from making all functions within the template final?



More information about the Digitalmars-d-learn mailing list