Method overloading without Type2Type

bearophile bearophileHUGS at lycos.com
Tue Apr 26 04:23:42 PDT 2011


Benjamin Thaut:

> import std.stdio;
> 
> struct Type2Type(T){
> 	typedef T OriginalType;
> }
> 
> class foo(T,R...) : foo!(R) {
> 	public void print(){
> 		super.print();
> 		writefln(T.stringof);
> 	}
> 	
> 	alias foo!(R).echo echo;
> 	public void echo(Type2Type!(T)) {
> 		writefln(T.stringof);
> 	}
> }
> 
> class foo(T){
> 	public void print(){
> 		writefln("end " ~ T.stringof);
> 	}
> 	
> 	public void echo(Type2Type!(T)) {
> 		writefln(T.stringof);
> 	}
> }
> 
> void main(string[] args){
> 	auto test = new foo!(int,float,double,short,byte)();
> 	test.print();
> 	
> 	test.echo(Type2Type!(double)());
> 	test.echo(Type2Type!(short)());
> }

Try to compile that code with "-w" (warnings).

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list