Method overloading without Type2Type
Benjamin Thaut
code at benjamin-thaut.de
Mon Apr 25 23:32:07 PDT 2011
I'm just reading Andreis book "Modern C++ Design" and try to translate a
few examples to D 2. My most recent test looks as follows:
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)());
}
I'm wondering if there is any way in D 2 to not use Type2Type so that
the calls to echo would look like:
test.echo!(double)();
test.echo!(short)();
The solution does not have to use inheritance, any idea?
--
Kind Regards
Benjamin Thaut
More information about the Digitalmars-d-learn
mailing list